summaryrefslogtreecommitdiffstats
path: root/bin/pax/getoldopt.c
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2001-05-08 06:19:06 +0000
committerkris <kris@FreeBSD.org>2001-05-08 06:19:06 +0000
commit6f2ea93cf4d39dc17b5fff4bc84a55d6562c8cd4 (patch)
tree63ec355a438835dcc12c39eb54e9e286c4f71426 /bin/pax/getoldopt.c
parent7ecc59e45de1a67ed22b32856a18f28bb30d36e6 (diff)
downloadFreeBSD-src-6f2ea93cf4d39dc17b5fff4bc84a55d6562c8cd4.zip
FreeBSD-src-6f2ea93cf4d39dc17b5fff4bc84a55d6562c8cd4.tar.gz
Sync up with OpenBSD. Too many changes to note, but the major features
are: * Implement cpio compatibility mode when pax is invoked as cpio * Extend tar compatibility mode to cover many of the GNU tar single-letter options (bzip2 mode, aka -y/-j is not present in OpenBSD). When invoked as tar, pax is now full-featured enough for use by the ports collection to extract distfiles and create packages. * Many bug fixes to the operation of pax and the tar compatibility modes * Code fixes for things like correct string buffer termination. I tried to preserve existing FreeBSD fixes to this utility; please let me know if I have inadvertently spammed something.
Diffstat (limited to 'bin/pax/getoldopt.c')
-rw-r--r--bin/pax/getoldopt.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/bin/pax/getoldopt.c b/bin/pax/getoldopt.c
new file mode 100644
index 0000000..37c235b
--- /dev/null
+++ b/bin/pax/getoldopt.c
@@ -0,0 +1,71 @@
+/* $OpenBSD: getoldopt.c,v 1.4 2000/01/22 20:24:51 deraadt Exp $ */
+/* $NetBSD: getoldopt.c,v 1.3 1995/03/21 09:07:28 cgd Exp $ */
+
+/*
+ * Plug-compatible replacement for getopt() for parsing tar-like
+ * arguments. If the first argument begins with "-", it uses getopt;
+ * otherwise, it uses the old rules used by tar, dump, and ps.
+ *
+ * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed
+ * in the Pubic Domain for your edification and enjoyment.
+ */
+
+#ifndef lint
+static const char rcsid[] = "$FreeBSD$";
+#endif /* not lint */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+getoldopt(argc, argv, optstring)
+ int argc;
+ char **argv;
+ char *optstring;
+{
+ static char *key; /* Points to next keyletter */
+ 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 EOF;
+ key = argv[1];
+ if (*key == '-')
+ use_getopt++;
+ else
+ optind = 2;
+ }
+
+ if (use_getopt)
+ return getopt(argc, argv, optstring);
+
+ c = *key++;
+ if (c == '\0') {
+ key--;
+ return EOF;
+ }
+ 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);
+}
OpenPOWER on IntegriCloud