summaryrefslogtreecommitdiff
path: root/ifne.c
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-04-10 14:11:21 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-04-10 14:11:21 -0400
commitddcbf562e3b6bb3a4441cc640c756127be4cf26b (patch)
treea13e693d1c005cc04c9ea4619437ee7b365d6804 /ifne.c
parent71349b5ae83878f4e59fc6517976998150856933 (diff)
downloadmoreutils-ddcbf562e3b6bb3a4441cc640c756127be4cf26b.tar.gz
sponge, ifne: Ensure that suspending/resuming doesn't result in partial writes of the data, by using fwrite() rather than write().
Diffstat (limited to 'ifne.c')
-rw-r--r--ifne.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/ifne.c b/ifne.c
index 9af19fa..817b1c5 100644
--- a/ifne.c
+++ b/ifne.c
@@ -1,4 +1,3 @@
-
/*
*
* Copyright 2008 Javier Merino <cibervicho@gmail.com>
@@ -30,6 +29,7 @@ int main(int argc, char **argv) {
int child_status;
pid_t child_pid;
char buf[BUFSIZ];
+ FILE *outf;
if (argc < 2) {
/* Noop */
@@ -68,11 +68,15 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
- /* Parent: write in fds[1] our stdin */
+ /* Parent: write stdin to fds[1] */
close(fds[0]);
-
+ outf = fdopen(fds[1], "w");
+ if (! outf) {
+ perror("fdopen");
+ exit(1);
+ }
do {
- if (write(fds[1], buf, r*sizeof(char)) == -1) {
+ if (fwrite(buf, r*sizeof(char), 1, outf) < 1) {
fprintf(stderr, "Write error to %s\n", argv[1]);
exit(EXIT_FAILURE);
}
@@ -82,8 +86,8 @@ int main(int argc, char **argv) {
perror("read");
exit(EXIT_FAILURE);
}
-
- close(fds[1]);
+ fclose(outf);
+
if (waitpid(child_pid, &child_status, 0) != child_pid) {
perror("waitpid");
return EXIT_FAILURE;