summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-06-23 16:40:45 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-06-23 16:40:45 +0000
commit49ef61b214d2c1c164fa8ede893b9e0e73405f71 (patch)
treeea46e8a99b06e26a2054809b807e0271485d96d6
parent1294b4ef28fe59ca2c2b47c0bb88347578356cd1 (diff)
Don't not use getopt() in printf(1) since it causes formats beginning
with a '-' to be interpreted as flags. Noticed by Alan Barrett. There is really no reason for this to be a builtin in csh...
-rw-r--r--bin/csh/printf.c17
-rw-r--r--usr.bin/printf/printf.c19
2 files changed, 8 insertions, 28 deletions
diff --git a/bin/csh/printf.c b/bin/csh/printf.c
index 2a25b034ce7..4cfc00b8b1d 100644
--- a/bin/csh/printf.c
+++ b/bin/csh/printf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printf.c,v 1.14 2003/06/11 21:09:50 deraadt Exp $ */
+/* $OpenBSD: printf.c,v 1.15 2003/06/23 16:40:44 millert Exp $ */
/* $NetBSD: printf.c,v 1.6 1995/03/21 09:03:15 cgd Exp $ */
/*
@@ -42,7 +42,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 7/20/93";
#else
-static char rcsid[] = "$OpenBSD: printf.c,v 1.14 2003/06/11 21:09:50 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: printf.c,v 1.15 2003/06/23 16:40:44 millert Exp $";
#endif
#endif /* not lint */
@@ -94,16 +94,7 @@ main(int argc, char *argv[])
int ch, end, fieldwidth, precision;
char convch, nextch, *format, *fmt, *start;
- while ((ch = getopt(argc, argv, "")) != -1)
- switch (ch) {
- default:
- usage();
- return (1);
- }
- argc -= optind;
- argv += optind;
-
- if (argc < 1) {
+ if (argc < 2) {
usage();
return (1);
}
@@ -119,7 +110,7 @@ main(int argc, char *argv[])
skip1 = "#-+ 0";
skip2 = "*0123456789";
- escape(fmt = format = *argv); /* backslash interpretation */
+ escape(fmt = format = *++argv); /* backslash interpretation */
gargv = ++argv;
for (;;) {
end = 0;
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c
index 8829effeb77..2ce53bb8e0e 100644
--- a/usr.bin/printf/printf.c
+++ b/usr.bin/printf/printf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printf.c,v 1.10 2003/06/10 22:20:49 deraadt Exp $ */
+/* $OpenBSD: printf.c,v 1.11 2003/06/23 16:40:44 millert Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@@ -39,7 +39,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)printf.c 5.9 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$OpenBSD: printf.c,v 1.10 2003/06/10 22:20:49 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: printf.c,v 1.11 2003/06/23 16:40:44 millert Exp $";
#endif /* not lint */
#include <ctype.h>
@@ -120,23 +120,12 @@ main(int argc, char *argv[])
setlocale (LC_ALL, "");
#endif
- while ((ch = getopt(argc, argv, "")) != -1) {
- switch (ch) {
- case '?':
- default:
- usage();
- return (1);
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc < 1) {
+ if (argc < 2) {
usage();
return (1);
}
- format = *argv;
+ format = *++argv;
gargv = ++argv;
#define SKIP1 "#-+ 0"