From: Colin McCabe Subject: [PATCH v3 2/2] cld: read the cld.port file using g_file_get_contents Date: Sat, 28 Nov 2009 04:34:35 -0800 Message-ID: <1259411675-23134-2-git-send-email-cmccabe@alumni.cmu.edu> References: <1259411675-23134-1-git-send-email-cmccabe@alumni.cmu.edu> Return-path: In-Reply-To: <1259411675-23134-1-git-send-email-cmccabe@alumni.cmu.edu> Sender: hail-devel-owner@vger.kernel.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Project Hail List Cc: Pete Zaitcev , Jeff Garzik , Colin McCabe Signed-off-by: Colin McCabe --- lib/common.c | 27 +++++++++++++-------------- 1 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/common.c b/lib/common.c index 68f60f8..f139de0 100644 --- a/lib/common.c +++ b/lib/common.c @@ -61,26 +61,25 @@ const char *cld_errstr(enum cle_err_codes ecode) */ int cld_readport(const char *fname) { - enum { LEN = 11 }; - char buf[LEN+1]; long port; - int fd; - int rc; + gchar *buf; + GError *err = NULL; + gsize len; - if ((fd = open(fname, O_RDONLY)) == -1) - return -errno; - rc = read(fd, buf, LEN); - close(fd); - if (rc < 0) - return -errno; - if (rc == 0) - return -EPIPE; - buf[rc] = 0; + if (!g_file_get_contents(fname, &buf, &len, &err)) { + int ret = -1000 - err->code; + g_error_free(err); + return ret; + } + if (len == 0) { + g_free(buf); + return -EPIPE; + } port = strtol(buf, NULL, 10); + g_free(buf); if (port <= 0 || port >= 65636) return -EDOM; return (int)port; } - -- 1.6.2.5