Module Name: src Committed By: kre Date: Fri Nov 23 23:41:20 UTC 2018
Modified Files: src/bin/sh: redir.c Log Message: 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 To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/bin/sh/redir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/redir.c diff -u src/bin/sh/redir.c:1.60 src/bin/sh/redir.c:1.61 --- src/bin/sh/redir.c:1.60 Mon Aug 13 22:13:02 2018 +++ src/bin/sh/redir.c Fri Nov 23 23:41:20 2018 @@ -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 @@ openredirect(union node *redir, char mem 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;