closeout.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* closeout.c - close standard output
  2. Copyright (C) 1998 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #if HAVE_CONFIG_H
  15. # include <config.h>
  16. #endif
  17. #if ENABLE_NLS
  18. # include <libintl.h>
  19. # define _(Text) gettext (Text)
  20. #else
  21. # define _(Text) Text
  22. #endif
  23. #if HAVE_STDLIB_H
  24. # include <stdlib.h>
  25. #endif
  26. #ifndef EXIT_FAILURE
  27. # define EXIT_FAILURE 1
  28. #endif
  29. #include <errno.h>
  30. #ifndef errno
  31. extern int errno;
  32. #endif
  33. #include <stdio.h>
  34. #include "closeout.h"
  35. #include "error.h"
  36. /* Close standard output, exiting with status STATUS on failure. */
  37. void
  38. close_stdout_status (int status)
  39. {
  40. if (ferror (stdout))
  41. error (status, 0, _("write error"));
  42. if (fclose (stdout) != 0)
  43. error (status, errno, _("write error"));
  44. }
  45. /* Close standard output, exiting with status EXIT_FAILURE on failure. */
  46. void
  47. close_stdout (void)
  48. {
  49. close_stdout_status (EXIT_FAILURE);
  50. }