Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh implement noclobber. From Ben Harris, with minor twea...
details: https://anonhg.NetBSD.org/src/rev/a52c2f7965a8
branches: trunk
changeset: 527001:a52c2f7965a8
user: christos <christos%NetBSD.org@localhost>
date: Wed May 15 16:33:35 2002 +0000
description:
implement noclobber. From Ben Harris, with minor tweaks from me. Two
unimplemented comments to go. Go Ben!
diffstat:
bin/sh/error.c | 5 +++--
bin/sh/eval.c | 5 +++--
bin/sh/jobs.c | 6 ++++--
bin/sh/nodetypes | 3 ++-
bin/sh/parser.c | 6 ++++--
bin/sh/redir.c | 24 +++++++++---------------
bin/sh/sh.1 | 3 +--
bin/sh/show.c | 5 +++--
8 files changed, 29 insertions(+), 28 deletions(-)
diffs (232 lines):
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/error.c
--- a/bin/sh/error.c Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/error.c Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: error.c,v 1.23 2000/07/03 03:26:19 matt Exp $ */
+/* $NetBSD: error.c,v 1.24 2002/05/15 16:33:35 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: error.c,v 1.23 2000/07/03 03:26:19 matt Exp $");
+__RCSID("$NetBSD: error.c,v 1.24 2002/05/15 16:33:35 christos Exp $");
#endif
#endif /* not lint */
@@ -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" },
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/eval.c
--- a/bin/sh/eval.c Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/eval.c Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.58 2002/02/14 21:51:41 christos Exp $ */
+/* $NetBSD: eval.c,v 1.59 2002/05/15 16:33:35 christos Exp $ */
/*-
* Copyright (c) 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
-__RCSID("$NetBSD: eval.c,v 1.58 2002/02/14 21:51:41 christos Exp $");
+__RCSID("$NetBSD: eval.c,v 1.59 2002/05/15 16:33:35 christos Exp $");
#endif
#endif /* not lint */
@@ -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;
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/jobs.c
--- a/bin/sh/jobs.c Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/jobs.c Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: jobs.c,v 1.45 2002/04/10 15:52:07 christos Exp $ */
+/* $NetBSD: jobs.c,v 1.46 2002/05/15 16:33:35 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: jobs.c,v 1.45 2002/04/10 15:52:07 christos Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.46 2002/05/15 16:33:35 christos Exp $");
#endif
#endif /* not lint */
@@ -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:
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/nodetypes
--- a/bin/sh/nodetypes Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/nodetypes Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: nodetypes,v 1.9 1999/02/04 16:17:39 christos Exp $
+# $NetBSD: nodetypes,v 1.10 2002/05/15 16:33:35 christos Exp $
# Copyright (c) 1991, 1993
# The Regents of the University of California. All rights reserved.
#
@@ -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
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/parser.c
--- a/bin/sh/parser.c Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/parser.c Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parser.c,v 1.52 2002/02/20 21:42:35 christos Exp $ */
+/* $NetBSD: parser.c,v 1.53 2002/05/15 16:33:35 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#else
-__RCSID("$NetBSD: parser.c,v 1.52 2002/02/20 21:42:35 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.53 2002/05/15 16:33:35 christos Exp $");
#endif
#endif /* not lint */
@@ -1177,6 +1177,8 @@
c = pgetc();
if (c == '>')
np->type = NAPPEND;
+ else if (c == '|')
+ np->type = NCLOBBER;
else if (c == '&')
np->type = NTOFD;
else {
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/redir.c
--- a/bin/sh/redir.c Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/redir.c Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.c,v 1.22 2000/05/22 10:18:47 elric Exp $ */
+/* $NetBSD: redir.c,v 1.23 2002/05/15 16:33:35 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: redir.c,v 1.22 2000/05/22 10:18:47 elric Exp $");
+__RCSID("$NetBSD: redir.c,v 1.23 2002/05/15 16:33:35 christos Exp $");
#endif
#endif /* not lint */
@@ -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"
@@ -179,6 +180,7 @@
int fd = redir->nfile.fd;
char *fname;
int f;
+ int flags = O_WRONLY|O_CREAT|O_TRUNC;
/*
* We suppress interrupts so that we won't leave open file
@@ -199,26 +201,18 @@
goto ecreate;
break;
case NTO:
+ if (Cflag)
+ flags |= O_EXCL;
+ /* FALLTHROUGH */
+ case NCLOBBER:
fname = redir->nfile.expfname;
-#ifdef O_CREAT
- if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
+ if ((f = open(fname, flags, 0666)) < 0)
goto ecreate;
-#else
- if ((f = creat(fname, 0666)) < 0)
- goto ecreate;
-#endif
break;
case NAPPEND:
fname = redir->nfile.expfname;
-#ifdef O_APPEND
if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
goto ecreate;
-#else
- if ((f = open(fname, O_WRONLY)) < 0
- && (f = creat(fname, 0666)) < 0)
- goto ecreate;
- lseek(f, (off_t)0, 2);
-#endif
break;
case NTOFD:
case NFROMFD:
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/sh.1
--- a/bin/sh/sh.1 Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/sh.1 Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: sh.1,v 1.47 2002/05/15 14:59:21 christos Exp $
+.\" $NetBSD: sh.1,v 1.48 2002/05/15 16:33:35 christos Exp $
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -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
diff -r 80d1c3d0d93f -r a52c2f7965a8 bin/sh/show.c
--- a/bin/sh/show.c Wed May 15 15:43:01 2002 +0000
+++ b/bin/sh/show.c Wed May 15 16:33:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.20 2002/02/12 06:39:11 ross Exp $ */
+/* $NetBSD: show.c,v 1.21 2002/05/15 16:33:35 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)show.c 8.3 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: show.c,v 1.20 2002/02/12 06:39:11 ross Exp $");
+__RCSID("$NetBSD: show.c,v 1.21 2002/05/15 16:33:35 christos Exp $");
#endif
#endif /* not lint */
@@ -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;
Home |
Main Index |
Thread Index |
Old Index