summaryrefslogtreecommitdiffstats
path: root/if-linux.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-11-05 13:57:54 +0000
committerRoy Marples <roy@marples.name>2008-11-05 13:57:54 +0000
commite1caa8dbade9d653dec2172b5c052f1dbeaebb22 (patch)
tree841472da5b26b69879e83089635607b5a6b39129 /if-linux.c
parent9783ceb17a8513b0ebcf5fc36d5a42cbd24f1c49 (diff)
downloaddhcpcd-e1caa8dbade9d653dec2172b5c052f1dbeaebb22.tar.xz
get_line now uses a single buffer, strips leading space and skips comments. This reduces malloc usage slightly and gives a cleaner API at the expense of a slight bss increase.
Diffstat (limited to 'if-linux.c')
-rw-r--r--if-linux.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/if-linux.c b/if-linux.c
index bbbc5493..188a9af5 100644
--- a/if-linux.c
+++ b/if-linux.c
@@ -431,18 +431,15 @@ struct interface *
discover_interfaces(int argc, char * const *argv)
{
FILE *f;
- char *buffer = NULL, *p;
- size_t len = 0, ln = 0, n;
+ char *p;
+ size_t ln = 0, n;
int i;
struct interface *ifs = NULL, *ifp, *ifl;
if ((f = fopen("/proc/net/dev", "r"))) {
- while (get_line(&buffer, &len, f)) {
+ while (p = get_line(f)) {
if (++ln < 2)
continue;
- p = buffer;
- while (isspace((unsigned int)*p))
- p++;
n = strcspn(p, ": \t");
p[n]= '\0';
ifl = NULL;
@@ -479,7 +476,6 @@ discover_interfaces(int argc, char * const *argv)
}
}
fclose(f);
- free(buffer);
}
return ifs;
}