diff options
| author | Roy Marples <roy@marples.name> | 2008-11-05 13:57:54 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-11-05 13:57:54 +0000 |
| commit | e1caa8dbade9d653dec2172b5c052f1dbeaebb22 (patch) | |
| tree | 841472da5b26b69879e83089635607b5a6b39129 /duid.c | |
| parent | 9783ceb17a8513b0ebcf5fc36d5a42cbd24f1c49 (diff) | |
| download | dhcpcd-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 'duid.c')
| -rw-r--r-- | duid.c | 25 |
1 files changed, 9 insertions, 16 deletions
@@ -47,30 +47,23 @@ get_duid(unsigned char *duid, const struct interface *iface) time_t t; int x = 0; unsigned char *p = duid; - size_t len = 0, l = 0; - char *buffer = NULL, *line, *option; + size_t len = 0; + char *line; /* If we already have a DUID then use it as it's never supposed * to change once we have one even if the interfaces do */ if ((f = fopen(DUID, "r"))) { - while ((get_line(&buffer, &len, f))) { - line = buffer; - while ((option = strsep(&line, " \t"))) - if (*option != '\0') - break; - if (!option || *option == '\0' || *option == '#') - continue; - l = hwaddr_aton(NULL, option); - if (l && l <= DUID_LEN) { - hwaddr_aton(duid, option); + while ((line = get_line(f))) { + len = hwaddr_aton(NULL, line); + if (len && len <= DUID_LEN) { + hwaddr_aton(duid, line); break; } - l = 0; + len = 0; } fclose(f); - free(buffer); - if (l) - return l; + if (len) + return len; } else { if (errno != ENOENT) return 0; |
