awk(1): fix append operator to avoid truncating file
This commit is contained in:
parent
8e9d2434e9
commit
913be4e74a
1 changed files with 10 additions and 4 deletions
|
@ -1710,7 +1710,7 @@ void stdinit(void) /* in case stdin, etc., are not constants */
|
||||||
Biobuf *openfile(int a, char *us)
|
Biobuf *openfile(int a, char *us)
|
||||||
{
|
{
|
||||||
char *s = us;
|
char *s = us;
|
||||||
int i, m;
|
int i, m, fd;
|
||||||
Biobuf *fp = nil;
|
Biobuf *fp = nil;
|
||||||
|
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
|
@ -1735,9 +1735,15 @@ Biobuf *openfile(int a, char *us)
|
||||||
if (a == GT) {
|
if (a == GT) {
|
||||||
fp = Bopen(s, OWRITE);
|
fp = Bopen(s, OWRITE);
|
||||||
} else if (a == APPEND) {
|
} else if (a == APPEND) {
|
||||||
fp = Bopen(s, OWRITE);
|
fd = open(s, OWRITE);
|
||||||
Bseek(fp, 0LL, 2);
|
if (fd < 0)
|
||||||
m = GT; /* so can mix > and >> */
|
fd = create(s, OWRITE, 0666);
|
||||||
|
if (fd >= 0) {
|
||||||
|
fp = Bfdopen(fd, OWRITE);
|
||||||
|
if (fp != nil)
|
||||||
|
Bseek(fp, 0LL, 2);
|
||||||
|
m = GT; /* so can mix > and >> */
|
||||||
|
}
|
||||||
} else if (a == '|') { /* output pipe */
|
} else if (a == '|') { /* output pipe */
|
||||||
fp = popen(s, OWRITE);
|
fp = popen(s, OWRITE);
|
||||||
} else if (a == LE) { /* input pipe */
|
} else if (a == LE) { /* input pipe */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue