From 51c825ceee9f86deb1afc20f4406c2c8dbb3d705 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 17 Mar 2008 21:27:37 +0000 Subject: Make rc_getline private and save it's buffer so it's sort of like getline from glibc. --- src/rc/rc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/rc') diff --git a/src/rc/rc.c b/src/rc/rc.c index 30bedcbf..eec03321 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -49,6 +49,10 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples"; # include #endif +#ifdef __linux__ +# include /* for COMMAND_LINE_SIZE */ +#endif + #include #include #include @@ -176,7 +180,7 @@ static void cleanup(void) static char *proc_getent(const char *ent) { FILE *fp; - char *proc; + char proc[COMMAND_LINE_SIZE]; char *p; char *value = NULL; int i; @@ -189,9 +193,9 @@ static char *proc_getent(const char *ent) return NULL; } - if ((proc = rc_getline(fp)) && - (p = strstr(proc, ent))) - { + memset(proc, 0, sizeof(proc)); + fgets(proc, sizeof(proc), fp); + if (*proc && (p = strstr(proc, ent))) { i = p - proc; if (i == '\0' || proc[i - 1] == ' ') { p += strlen(ent); @@ -201,7 +205,6 @@ static char *proc_getent(const char *ent) } } else errno = ENOENT; - free(proc); fclose(fp); return value; -- cgit v1.2.3