Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Fix the <> redirection operator, which has been broke...



details:   https://anonhg.NetBSD.org/src/rev/d7c22fef7e51
branches:  trunk
changeset: 446106:d7c22fef7e51
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Nov 23 23:41:20 2018 +0000

description:
Fix the <> redirection operator, which has been broken since it was
first implemented in response to PR bin/4966  (PR Feb 1998, fix Feb 1999).

The file named should not be truncated.

No other shell truncates the file (<> was added to FreeBSD sh in Oct 2000,
and did not include O_TRUNC) and POSIX certainly does not suggest that
should happen (just that the file is to be created if it does not exist.)

Bug pointed out in off-list e-mail by Martijn Dekker

diffstat:

 bin/sh/redir.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 0871a6dfede4 -r d7c22fef7e51 bin/sh/redir.c
--- a/bin/sh/redir.c    Fri Nov 23 23:37:22 2018 +0000
+++ b/bin/sh/redir.c    Fri Nov 23 23:41:20 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: redir.c,v 1.60 2018/08/13 22:13:02 kre Exp $   */
+/*     $NetBSD: redir.c,v 1.61 2018/11/23 23:41:20 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.60 2018/08/13 22:13:02 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.61 2018/11/23 23:41:20 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -299,7 +299,7 @@
                break;
        case NFROMTO:
                fname = redir->nfile.expfname;
-               if ((f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
+               if ((f = open(fname, O_RDWR|O_CREAT, 0666)) < 0)
                        goto ecreate;
                VTRACE(DBG_REDIR, ("openredirect(<> '%s') -> %d", fname, f));
                break;



Home | Main Index | Thread Index | Old Index