diff options
author | jilles <jilles@FreeBSD.org> | 2012-09-15 21:56:30 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-09-15 21:56:30 +0000 |
commit | 99ca87dd2daf11623d11838ece4dba4e0ab94951 (patch) | |
tree | 8f1502baabb3376aec513c46c8781c9f452a7b3d /usr.bin | |
parent | 56fd9326eeef1f0702902d3716e1551e76049d94 (diff) | |
download | FreeBSD-src-99ca87dd2daf11623d11838ece4dba4e0ab94951.zip FreeBSD-src-99ca87dd2daf11623d11838ece4dba4e0ab94951.tar.gz |
sh: Prefer internal nextopt() to libc getopt().
This reduces code duplication and code size.
/usr/bin/printf is not affected.
Side effect: different error messages when certain builtins are passed
invalid options.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/printf/printf.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 89149dcda..4b09342 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -64,6 +64,7 @@ static const char rcsid[] = #define main printfcmd #include "bltin/bltin.h" #include "error.h" +#include "options.h" #endif #define PF(f, func) do { \ @@ -101,15 +102,19 @@ int main(int argc, char *argv[]) { size_t len; - int ch, chopped, end, rval; + int chopped, end, rval; char *format, *fmt, *start; - #ifndef SHELL + int ch; + (void) setlocale(LC_ALL, ""); #endif + #ifdef SHELL - optreset = 1; optind = 1; opterr = 0; /* initialize getopt */ -#endif + nextopt(""); + argc -= argptr - argv; + argv = argptr; +#else while ((ch = getopt(argc, argv, "")) != -1) switch (ch) { case '?': @@ -119,6 +124,7 @@ main(int argc, char *argv[]) } argc -= optind; argv += optind; +#endif if (argc < 1) { usage(); |