Skip to contentSkip to conversation

cld: read the cld.port file using g_file_get_contents

PATCH Applied Colin McCabe 2 participants 2 messages Nov 28, 2009 1 message not in the archive Library code

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v3 2/2 cld: read the cld.port file using g_file_get_contents

---
 lib/common.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)
lib/common.c +13 -14
index 68f60f8..f139de0 100644
@@ -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;
 }
-
Signature · 1 line
1.6.2.5
Applied
#2 lore raw
Quoted 4 lines · Colin McCabe
---
  lib/common.c |   27 +++++++++++++--------------
  1 files changed, 13 insertions(+), 14 deletions(-)

applied, thanks for the revisions