summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2003-06-24 16:23:31 +0000
committerchristos <christos@NetBSD.org>2003-06-24 16:23:31 +0000
commitd1a05abed1178d7fd6189931e6bcdf69b30a8fe5 (patch)
tree042e1acd19091bc1dc4381a553066bbe3f1c13b1
parent1625aa9110294234c674da4fa89df536dff0ce7e (diff)
Revert previous change, and fix the -T problem differently: When the options
of the second argument are exhausted, call the appropriate getopt() routine to process the rest of the arguments instead of finishing option processing. Fixes: tar cf - -T foo
-rw-r--r--bin/pax/getoldopt.c57
1 files changed, 46 insertions, 11 deletions
diff --git a/bin/pax/getoldopt.c b/bin/pax/getoldopt.c
index 3fd1e7a3b6a..28e846d684e 100644
--- a/bin/pax/getoldopt.c
+++ b/bin/pax/getoldopt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: getoldopt.c,v 1.17 2003/06/23 13:15:15 christos Exp $ */
+/* $NetBSD: getoldopt.c,v 1.18 2003/06/24 16:23:31 christos Exp $ */
/*
* Plug-compatible replacement for getopt() for parsing tar-like
@@ -11,7 +11,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: getoldopt.c,v 1.17 2003/06/23 13:15:15 christos Exp $");
+__RCSID("$NetBSD: getoldopt.c,v 1.18 2003/06/24 16:23:31 christos Exp $");
#endif /* not lint */
#include <getopt.h>
@@ -28,20 +28,55 @@ getoldopt(int argc, char **argv, const char *optstring,
struct option *longopts, int *idx)
{
static char *key; /* Points to next keyletter */
- static char argv1[64];
+ static char use_getopt; /* !=0 if argv[1][0] was '-' */
+ char c;
+ char *place;
+
+ optarg = NULL;
if (key == NULL) { /* First time */
if (argc < 2) return -1;
key = argv[1];
- if (*key != '-')
- (void)snprintf(argv[1] = argv1, sizeof(argv1), "-%s",
- key);
+ if (*key == '-')
+ use_getopt++;
+ else
+ optind = 2;
+ }
+
+ if (!use_getopt) {
+ c = *key++;
+ if (c == '\0') {
+ key--;
+ use_getopt = 1;
+ }
+ }
+ if (use_getopt) {
+ if (longopts != NULL) {
+ return getopt_long(argc, argv, optstring,
+ longopts, idx);
+ } else {
+ return getopt(argc, argv, optstring);
+ }
}
- if (longopts != NULL) {
- return getopt_long(argc, argv, optstring,
- longopts, idx);
- } else {
- return getopt(argc, argv, optstring);
+ place = strchr(optstring, c);
+
+ if (place == NULL || c == ':') {
+ fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
+ return('?');
+ }
+
+ place++;
+ if (*place == ':') {
+ if (optind < argc) {
+ optarg = argv[optind];
+ optind++;
+ } else {
+ fprintf(stderr, "%s: %c argument missing\n",
+ argv[0], c);
+ return('?');
+ }
}
+
+ return(c);
}