diff options
author | Roy Marples <roy@marples.name> | 2008-03-17 21:27:37 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-03-17 21:27:37 +0000 |
commit | 51c825ceee9f86deb1afc20f4406c2c8dbb3d705 (patch) | |
tree | 0dac5ab5cf9e3a54a5fabd9bf8d32ddf1f578bf3 /src/rc/rc.c | |
parent | b9eb450696eec614acc983648e2ab04f3fd44463 (diff) |
Make rc_getline private and save it's buffer so it's sort of like getline from glibc.
Diffstat (limited to 'src/rc/rc.c')
-rw-r--r-- | src/rc/rc.c | 13 |
1 files changed, 8 insertions, 5 deletions
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 <ifaddrs.h> #endif +#ifdef __linux__ +# include <asm/setup.h> /* for COMMAND_LINE_SIZE */ +#endif + #include <errno.h> #include <dirent.h> #include <ctype.h> @@ -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; |