Commit 53c40178 authored by Jiri Popelka's avatar Jiri Popelka

use scanf("%ms") instead of scanf("%as") for dynamic string

from scanf(3):
The a modifier is not available if the program is compiled with
gcc -std=c99 or gcc -D_ISOC99_SOURCE (unless _GNU_SOURCE
is also specified), in which case the a is interpreted
as a specifier for floating-point numbers (see above).

Since version 2.7, glibc also provides the m modifier for the
same purpose as the a modifier. The m modifier has the following
advantages:
* It may also be applied to %c conversion specifiers (e.g., %3mc).
* It avoids ambiguity with respect to the %a floating-point
  conversion specifier (and is unaffected by gcc -std=c99 etc.)
* It is specified in the upcoming revision of the POSIX.1 standard.
parent 699e5db8
......@@ -73,17 +73,17 @@ int DDP_rprint(int options)
return 1;
}
if (fscanf(fp, "%as %as %as %as\n", &dest, &gw, &flags, &dev))
if (fscanf(fp, "%ms %ms %ms %ms\n", &dest, &gw, &flags, &dev))
/* eat line */;
free(dest); free(gw); free(dev); free(flags);
free(dest); free(gw); free(flags); free(dev);
printf("%s\n", hdr);
while (fscanf(fp, "%as %as %as %as\n", &dest, &gw, &flags, &dev) == 4) {
while (fscanf(fp, "%ms %ms %ms %ms\n", &dest, &gw, &flags, &dev) == 4) {
int iflags = atoi(flags);
flags_decode(iflags, oflags);
printf("%-16s%-16s%-16s%-s\n", dest, gw, dev, oflags);
free(dest); free(gw); free(dev); free(flags);
free(dest); free(gw); free(flags); free(dev);
}
fclose(fp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment