From 99ca87dd2daf11623d11838ece4dba4e0ab94951 Mon Sep 17 00:00:00 2001 From: jilles Date: Sat, 15 Sep 2012 21:56:30 +0000 Subject: 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. --- usr.bin/printf/printf.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'usr.bin/printf') 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(); -- cgit v1.1