Subject: sh -C patch
To: None <tech-userlevel@netbsd.org>
From: Ben Harris <bjh21@netbsd.org>
List: tech-userlevel
Date: 05/14/2002 01:04:04
Here's another proposed shell patch, this time to add support for -C
(noclobber). Anyone in a position to review this?
Index: error.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/error.c,v
retrieving revision 1.23
diff -u -r1.23 error.c
--- error.c 2000/07/03 03:26:19 1.23
+++ error.c 2002/05/13 23:55:42
@@ -226,6 +226,7 @@
{ EINTR, ALL, "interrupted" },
{ EACCES, ALL, "permission denied" },
{ EIO, ALL, "I/O error" },
+ { EEXIST, ALL, "file exists" },
{ ENOENT, E_OPEN, "no such file" },
{ ENOENT, E_CREAT,"directory nonexistent" },
{ ENOENT, E_EXEC, "not found" },
Index: eval.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/eval.c,v
retrieving revision 1.58
diff -u -r1.58 eval.c
--- eval.c 2002/02/14 21:51:41 1.58
+++ eval.c 2002/05/13 23:55:42
@@ -441,6 +441,7 @@
case NFROMTO:
case NFROM:
case NTO:
+ case NCLOBBER:
case NAPPEND:
expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
redir->nfile.expfname = fn.list->text;
Index: jobs.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/jobs.c,v
retrieving revision 1.45
diff -u -r1.45 jobs.c
--- jobs.c 2002/04/10 15:52:07 1.45
+++ jobs.c 2002/05/13 23:55:43
@@ -1100,6 +1100,8 @@
break;
case NTO:
p = ">"; i = 1; goto redir;
+ case NCLOBBER:
+ p = ">|"; i = 1; goto redir;
case NAPPEND:
p = ">>"; i = 1; goto redir;
case NTOFD:
Index: nodetypes
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/nodetypes,v
retrieving revision 1.9
diff -u -r1.9 nodetypes
--- nodetypes 1999/02/04 16:17:39 1.9
+++ nodetypes 2002/05/13 23:55:43
@@ -116,6 +116,7 @@
backquote nodelist # list of commands in back quotes
NTO nfile # fd> fname
+NCLOBBER nfile # fd>| fname
NFROM nfile # fd< fname
NFROMTO nfile # fd<> fname
NAPPEND nfile # fd>> fname
Index: parser.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/parser.c,v
retrieving revision 1.52
diff -u -r1.52 parser.c
--- parser.c 2002/02/20 21:42:35 1.52
+++ parser.c 2002/05/13 23:55:44
@@ -1177,6 +1177,8 @@
c = pgetc();
if (c == '>')
np->type = NAPPEND;
+ else if (c == '|')
+ np->type = NCLOBBER;
else if (c == '&')
np->type = NTOFD;
else {
Index: redir.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/redir.c,v
retrieving revision 1.22
diff -u -r1.22 redir.c
--- redir.c 2000/05/22 10:18:47 1.22
+++ redir.c 2002/05/13 23:55:44
@@ -61,6 +61,7 @@
#include "shell.h"
#include "nodes.h"
#include "jobs.h"
+#include "options.h"
#include "expand.h"
#include "redir.h"
#include "output.h"
@@ -199,6 +200,15 @@
goto ecreate;
break;
case NTO:
+ if (Cflag) {
+ fname = redir->nfile.expfname;
+ if ((f = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC,
+ 0666)) < 0)
+ goto ecreate;
+ break;
+ }
+ /* FALLTHROUGH */
+ case NCLOBBER:
fname = redir->nfile.expfname;
#ifdef O_CREAT
if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
Index: sh.1
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/sh.1,v
retrieving revision 1.46
diff -u -r1.46 sh.1
--- sh.1 2002/02/24 21:41:52 1.46
+++ sh.1 2002/05/13 23:55:45
@@ -177,7 +177,6 @@
.It Fl C Em noclobber
Don't overwrite existing files with
.Dq \*[Gt] .
-(UNIMPLEMENTED for 4.4alpha)
.It Fl e Em errexit
If not interactive, exit immediately if any untested command fails.
The exit status of a command is considered to be
Index: show.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/show.c,v
retrieving revision 1.20
diff -u -r1.20 show.c
--- show.c 2002/02/12 06:39:11 1.20
+++ show.c 2002/05/13 23:55:45
@@ -153,6 +153,7 @@
putchar(' ');
switch (np->nfile.type) {
case NTO: s = ">"; dftfd = 1; break;
+ case NCLOBBER: s = ">|"; dftfd = 1; break;
case NAPPEND: s = ">>"; dftfd = 1; break;
case NTOFD: s = ">&"; dftfd = 1; break;
case NFROM: s = "<"; dftfd = 0; break;
--
Ben Harris <bjh21@netbsd.org>
Portmaster, NetBSD/acorn26 <URL:http://www.netbsd.org/Ports/acorn26/>