Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Allow abbreviations of option names for the "fdflags ...
details: https://anonhg.NetBSD.org/src/rev/c4d5193d99b6
branches: trunk
changeset: 353703:c4d5193d99b6
user: kre <kre%NetBSD.org@localhost>
date: Thu May 18 13:56:58 2017 +0000
description:
Allow abbreviations of option names for the "fdflags -s" command.
While documenting that, cleanup markup of the fdflags section of the
man page.
diffstat:
bin/sh/redir.c | 38 ++++++++++++++++++--------------------
bin/sh/sh.1 | 22 ++++++++++++++++++----
2 files changed, 36 insertions(+), 24 deletions(-)
diffs (146 lines):
diff -r d528c8d33dee -r c4d5193d99b6 bin/sh/redir.c
--- a/bin/sh/redir.c Thu May 18 13:53:18 2017 +0000
+++ b/bin/sh/redir.c Thu May 18 13:56:58 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.c,v 1.55 2017/05/14 17:27:05 kre Exp $ */
+/* $NetBSD: redir.c,v 1.56 2017/05/18 13:56:58 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: redir.c,v 1.55 2017/05/14 17:27:05 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.56 2017/05/18 13:56:58 kre Exp $");
#endif
#endif /* not lint */
@@ -653,42 +653,43 @@
static const struct flgnames {
const char *name;
+ uint16_t minch;
uint32_t value;
} nv[] = {
#ifdef O_APPEND
- { "append", O_APPEND },
+ { "append", 2, O_APPEND },
#endif
#ifdef O_ASYNC
- { "async", O_ASYNC },
+ { "async", 2, O_ASYNC },
#endif
#ifdef O_SYNC
- { "sync", O_SYNC },
+ { "sync", 2, O_SYNC },
#endif
#ifdef O_NONBLOCK
- { "nonblock", O_NONBLOCK },
+ { "nonblock", 3, O_NONBLOCK },
#endif
#ifdef O_FSYNC
- { "fsync", O_FSYNC },
+ { "fsync", 2, O_FSYNC },
#endif
#ifdef O_DSYNC
- { "dsync", O_DSYNC },
+ { "dsync", 2, O_DSYNC },
#endif
#ifdef O_RSYNC
- { "rsync", O_RSYNC },
+ { "rsync", 2, O_RSYNC },
#endif
#ifdef O_ALTIO
- { "altio", O_ALT_IO },
+ { "altio", 2, O_ALT_IO },
#endif
#ifdef O_DIRECT
- { "direct", O_DIRECT },
+ { "direct", 2, O_DIRECT },
#endif
#ifdef O_NOSIGPIPE
- { "nosigpipe", O_NOSIGPIPE },
+ { "nosigpipe", 3, O_NOSIGPIPE },
#endif
#ifdef O_CLOEXEC
- { "cloexec", O_CLOEXEC },
+ { "cloexec", 2, O_CLOEXEC },
#endif
- { 0, 0 }
+ { 0, 0, 0 }
};
#define ALLFLAGS (O_APPEND|O_ASYNC|O_SYNC|O_NONBLOCK|O_DSYNC|O_RSYNC|\
O_ALT_IO|O_DIRECT|O_NOSIGPIPE|O_CLOEXEC)
@@ -752,6 +753,7 @@
{
int *v, *w;
const struct flgnames *fn;
+ size_t len;
*p = 0;
*n = 0;
@@ -769,8 +771,9 @@
error("Missing +/- indicator before flag %s", s-1);
}
+ len = strlen(s);
for (fn = nv; fn->name; fn++)
- if (strcmp(s, fn->name) == 0) {
+ if (len >= fn->minch && strncmp(s,fn->name,len) == 0) {
*v |= fn->value;
*w &=~ fn->value;
break;
@@ -846,11 +849,6 @@
if (setflags)
goto msg;
- /*
- * XXX we should only ever operate on user defined fds
- * XXX not on sh internal fds that might be open.
- * XXX but for that we need to know their range (later)
- */
for (i = 0; i <= max_user_fd; i++)
printone(i, 0, verbose, 1);
return 0;
diff -r d528c8d33dee -r c4d5193d99b6 bin/sh/sh.1
--- a/bin/sh/sh.1 Thu May 18 13:53:18 2017 +0000
+++ b/bin/sh/sh.1 Thu May 18 13:56:58 2017 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: sh.1,v 1.142 2017/05/18 13:53:18 kre Exp $
+.\" $NetBSD: sh.1,v 1.143 2017/05/18 13:56:58 kre Exp $
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -1962,14 +1962,28 @@
.Ar flags
argument as a comma separated list of file descriptor flags, each preceded
with a
-.Dq +
+.Dq \(pl
or a
-.Dq -
+.Dq \(mi
indicating to set or clear the respective flag.
Valid flags are:
-append,async,sync,nonblock,fsync,dsync,rsync,direct,nosigpipe,cloexec.
+.Cm append ,
+.Cm async ,
+.Cm sync ,
+.Cm nonblock ,
+.Cm fsync ,
+.Cm dsync ,
+.Cm rsync ,
+.Cm direct ,
+.Cm nosigpipe ,
+and
+.Cm cloexec .
+Unique abbreviations of these names, of at least 2 characters,
+may be used on input.
See
.Xr fcntl 2
+and
+.Xr open 2
for more information.
.It getopts Ar optstring var
The
Home |
Main Index |
Thread Index |
Old Index