moreutils (0.29) UNRELEASED; urgency=low
* Add ifne, contributed by Javier Merino.
- * sponge: Ensure that suspending/resuming doesn't result in partial writes
- of the data, by using fwrite() rather than write().
+ * sponge, ifne: Ensure that suspending/resuming doesn't
+ result in partial writes of the data, by using fwrite()
+ rather than write().
-- Joey Hess <joeyh@debian.org> Thu, 20 Mar 2008 12:56:42 -0400
-
/*
*
* Copyright 2008 Javier Merino <cibervicho@gmail.com>
int child_status;
pid_t child_pid;
char buf[BUFSIZ];
+ FILE *outf;
if (argc < 2) {
/* Noop */
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);
}
perror("read");
exit(EXIT_FAILURE);
}
-
- close(fds[1]);
+ fclose(outf);
+
if (waitpid(child_pid, &child_status, 0) != child_pid) {
perror("waitpid");
return EXIT_FAILURE;