changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: awk(1): fix append operator to avoid truncating file

changeset 6854: ede4bb3c885e
parent 6853: 8ae0e1edff80
child 6855: 01468da33a6e
author: Alex Musolino <alex@musolino.id.au>
date: Wed, 31 Oct 2018 16:49:02 +1030
files: sys/src/cmd/awk/run.c
description: awk(1): fix append operator to avoid truncating file
     1.1--- a/sys/src/cmd/awk/run.c
     1.2+++ b/sys/src/cmd/awk/run.c
     1.3@@ -1710,7 +1710,7 @@ void stdinit(void)	/* in case stdin, etc
     1.4 Biobuf *openfile(int a, char *us)
     1.5 {
     1.6 	char *s = us;
     1.7-	int i, m;
     1.8+	int i, m, fd;
     1.9 	Biobuf *fp = nil;
    1.10 
    1.11 	if (*s == '\0')
    1.12@@ -1735,9 +1735,15 @@ Biobuf *openfile(int a, char *us)
    1.13 	if (a == GT) {
    1.14 		fp = Bopen(s, OWRITE);
    1.15 	} else if (a == APPEND) {
    1.16-		fp = Bopen(s, OWRITE);
    1.17-		Bseek(fp, 0LL, 2);
    1.18-		m = GT;	/* so can mix > and >> */
    1.19+		fd = open(s, OWRITE);
    1.20+		if (fd < 0)
    1.21+			fd = create(s, OWRITE, 0666);
    1.22+		if (fd >= 0) {
    1.23+			fp = Bfdopen(fd, OWRITE);
    1.24+			if (fp != nil)
    1.25+				Bseek(fp, 0LL, 2);
    1.26+			m = GT;	/* so can mix > and >> */
    1.27+		}
    1.28 	} else if (a == '|') {	/* output pipe */
    1.29 		fp = popen(s, OWRITE);
    1.30 	} else if (a == LE) {	/* input pipe */