From c6369e9004be56d427f0cc0d51d7009d727e061c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 23 Sep 2012 11:33:01 +0200 Subject: 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 , 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 . (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. --- src/make-prime-list.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/make-prime-list.c') 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 #include #include +#include +#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; } -- cgit v1.2.3-54-g00ecf