Hi, * Tommi Rantala <tt.rantala@xxxxxxxxx> [2013-06-03 07:56]: > 2013/5/24 Nico Golde <nico@xxxxxxxxx>: > > * Tommi Rantala <tt.rantala@xxxxxxxxx> [2013-05-23 20:58]: > >> 2013/5/22 Nico Golde <nico@xxxxxxxxx>: > >> > I changed the code the following way: > >> > @@ -21,7 +22,8 @@ static size_t bldevs, chrdevs, miscdevs; > >> > static void parse_proc_devices(void) > >> > { > >> > FILE *fp; > >> > - char *name, *line = NULL; > >> > + char *line = NULL; > >> > + char name[32]; > >> > >> It would be IMO preferable to not hardcode the max length. > > > > I agree, this is actually left over from quickly changing this. > > Are you aware of a proper maximum defined in the kernel headers or do we want to > > allocate this completely dynamically? > > dynamic please! Sorry I had no time to look into this for a while. Patch attached. Cheers Nico -- Nico Golde - XMPP: nion@xxxxxxxxxxxxx - GPG: 0xA0A0AAAA
From 9acc7c59c6ae2643ffba4edc17b04477f5cdaee0 Mon Sep 17 00:00:00 2001 From: Nico Golde <nion@xxxxxxxxxx> Date: Fri, 21 Jun 2013 15:18:58 +0200 Subject: [PATCH] devices.c: dont use %as scanf format string, but instead allocate and parse the device name manually for compatibility with non-glibc libcs --- devices.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/devices.c b/devices.c index 43433bc..d3916f9 100644 --- a/devices.c +++ b/devices.c @@ -21,7 +21,7 @@ static size_t bldevs, chrdevs, miscdevs; static void parse_proc_devices(void) { FILE *fp; - char *name, *line = NULL; + char *p, *name, *line = NULL; size_t n = 0; int block, major; void *new; @@ -35,7 +35,14 @@ static void parse_proc_devices(void) while (getline(&line, &n, fp) >= 0) { if (strcmp("Block devices:\n", line) == 0) block = 1; - else if (sscanf(line, "%d %as", &major, &name) == 2) { + else if (strcmp("Character devices:\n", line) == 0) + block = 0; + else if (sscanf(line, "%d %*s", &major) == 1) { + if ((p = strrchr(line, ' ')) == NULL) + continue; + p++; + name = strdup(p); + if (block) { new = realloc(block_devs, (bldevs+1)*sizeof(*block_devs)); if (!new) { -- 1.7.10.4
Attachment:
pgpFUHtJvTriQ.pgp
Description: PGP signature