summaryrefslogtreecommitdiff
path: root/src/make-prime-list.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-09-23 11:33:01 +0200
committerJim Meyering <meyering@redhat.com>2012-10-04 21:33:06 +0200
commitc6369e9004be56d427f0cc0d51d7009d727e061c (patch)
tree5ca3d017a780f9347299a444bc4653caa9326128 /src/make-prime-list.c
parentcf67e4cc9025ce921230b821cb7e75bce06876cd (diff)
downloadcoreutils-c6369e9004be56d427f0cc0d51d7009d727e061c.tar.xz
maint: make-prime-list: do not ignore write failure
Even though this is just a helper program that is run solely to create primes.h, it should not ignore a write failure. Normally we would simply call atexit (close_stdout), but we cannot do that from this helper program, since it must be built before the generated header, primes.h. If we were to make the linking of make-prime-list depend on libcoreutils.a, that would add all lib/*.o files to the list of dependents of $(BUILT_HEADERS). Then, since there is currently no provision to ensure that a file like lib/stdio.h (another built header) is built before the first lib/*.o file that also includes <stdio.h>, some lib/*.o files would be built before lib/stdio.h and some after. The former would provoke link failures due to undefined rpl_* functions. * src/make-prime-list.c: Include <errno.h>. (fclose): Undef, so that a definition to rpl_fclose does not cause a link failure. (main): Per the above, in this exceptional case, we check for fclose and ferror failure manually, and don't worry about the ferror-only failure case in which errno may not be relevant.
Diffstat (limited to 'src/make-prime-list.c')
-rw-r--r--src/make-prime-list.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/make-prime-list.c b/src/make-prime-list.c
index 724924b40..b18b0e5f0 100644
--- a/src/make-prime-list.c
+++ b/src/make-prime-list.c
@@ -23,6 +23,8 @@ this program. If not, see http://www.gnu.org/licenses/. */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
+#undef fclose
struct prime
{
@@ -166,5 +168,11 @@ main (int argc, char **argv)
output_primes (prime_list, nprimes);
+ if (ferror (stdout) + fclose (stdout))
+ {
+ fprintf (stderr, "write error: %s\n", strerror (errno));
+ return EXIT_FAILURE;
+ }
+
return EXIT_SUCCESS;
}