implement noclobber. From Ben Harris, with minor tweaks from me. Two

unimplemented comments to go. Go Ben!
This commit is contained in:
christos 2002-05-15 16:33:35 +00:00
parent a6fac9a778
commit f629aa28d9
8 changed files with 29 additions and 28 deletions

View File

@ -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 @@ STATIC const struct errname errormsg[] = {
{ 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" },

View File

@ -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 @@ expredir(n)
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;

View File

@ -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 @@ until:
break;
case NTO:
p = ">"; i = 1; goto redir;
case NCLOBBER:
p = ">|"; i = 1; goto redir;
case NAPPEND:
p = ">>"; i = 1; goto redir;
case NTOFD:

View File

@ -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 @@ NARG narg # represents a word
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

View File

@ -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 @@ parseredir: {
c = pgetc();
if (c == '>')
np->type = NAPPEND;
else if (c == '|')
np->type = NCLOBBER;
else if (c == '&')
np->type = NTOFD;
else {

View File

@ -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 @@ __RCSID("$NetBSD: redir.c,v 1.22 2000/05/22 10:18:47 elric Exp $");
#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 @@ openredirect(redir, memory)
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 @@ openredirect(redir, memory)
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:

View File

@ -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 @@ No commands will be read from the standard input.
.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

View File

@ -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 @@ shcmd(cmd, fp)
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;