version 1.42, 2018/12/30 23:09:58 |
version 1.43, 2019/06/28 13:35:02 |
|
|
say("Moving %s to stdout.\n", from); |
say("Moving %s to stdout.\n", from); |
#endif |
#endif |
fromfd = open(from, O_RDONLY); |
fromfd = open(from, O_RDONLY); |
if (fromfd < 0) |
if (fromfd == -1) |
pfatal("internal error, can't reopen %s", from); |
pfatal("internal error, can't reopen %s", from); |
while ((i = read(fromfd, buf, sizeof buf)) > 0) |
while ((i = read(fromfd, buf, sizeof buf)) > 0) |
if (write(STDOUT_FILENO, buf, i) != i) |
if (write(STDOUT_FILENO, buf, i) != i) |
|
|
if (debug & 4) |
if (debug & 4) |
say("Moving %s to %s.\n", from, to); |
say("Moving %s to %s.\n", from, to); |
#endif |
#endif |
if (rename(from, to) < 0) { |
if (rename(from, to) == -1) { |
if (errno != EXDEV || copy_file(from, to) < 0) { |
if (errno != EXDEV || copy_file(from, to) < 0) { |
say("Can't create %s, output is in %s: %s\n", |
say("Can't create %s, output is in %s: %s\n", |
to, from, strerror(errno)); |
to, from, strerror(errno)); |
|
|
if (debug & 4) |
if (debug & 4) |
say("Moving %s to %s.\n", orig, bakname); |
say("Moving %s to %s.\n", orig, bakname); |
#endif |
#endif |
if (rename(orig, bakname) < 0) { |
if (rename(orig, bakname) == -1) { |
if (errno != EXDEV || copy_file(orig, bakname) < 0) |
if (errno != EXDEV || copy_file(orig, bakname) < 0) |
return -1; |
return -1; |
} |
} |
|
|
ssize_t i; |
ssize_t i; |
|
|
tofd = open(to, O_CREAT|O_TRUNC|O_WRONLY, 0666); |
tofd = open(to, O_CREAT|O_TRUNC|O_WRONLY, 0666); |
if (tofd < 0) |
if (tofd == -1) |
return -1; |
return -1; |
fromfd = open(from, O_RDONLY, 0); |
fromfd = open(from, O_RDONLY, 0); |
if (fromfd < 0) |
if (fromfd == -1) |
pfatal("internal error, can't reopen %s", from); |
pfatal("internal error, can't reopen %s", from); |
while ((i = read(fromfd, buf, sizeof buf)) > 0) |
while ((i = read(fromfd, buf, sizeof buf)) > 0) |
if (write(tofd, buf, i) != i) |
if (write(tofd, buf, i) != i) |
|
|
buf[nr - 1] == '\n') |
buf[nr - 1] == '\n') |
buf[nr - 1] = '\0'; |
buf[nr - 1] = '\0'; |
} |
} |
if (ttyfd < 0 || nr <= 0) { |
if (ttyfd == -1 || nr <= 0) { |
/* no tty or error reading, pretend user entered 'return' */ |
/* no tty or error reading, pretend user entered 'return' */ |
putchar('\n'); |
putchar('\n'); |
buf[0] = '\0'; |
buf[0] = '\0'; |