* [PATCH v3 2/2] cld: read the cld.port file using g_file_get_contents
[not found] <1259411675-23134-1-git-send-email-cmccabe@alumni.cmu.edu>
@ 2009-11-28 12:34 ` Colin McCabe
2009-11-28 21:21 ` Jeff Garzik
0 siblings, 1 reply; 2+ messages in thread
From: Colin McCabe @ 2009-11-28 12:34 UTC (permalink / raw)
To: Project Hail List; +Cc: Pete Zaitcev, Jeff Garzik, Colin McCabe
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread