Signed-off-by: Colin McCabe <[email protected]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to