PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/gnu/lib/error.c

https://github.com/vvnikitin/sdcboot
C | 105 lines | 71 code | 12 blank | 22 comment | 5 complexity | ed782a4835574b6590f26d236cdfea1f MD5 | raw file
Possible License(s): GPL-2.0, 0BSD, LGPL-2.0
  1. /* error.c -- error handler for noninteractive utilities
  2. Copyright (C) 1990, 1991 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
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. /* David MacKenzie */
  15. #include <stdio.h>
  16. #ifndef VPRINTF_MISSING
  17. #ifdef __STDC__
  18. #include <stdarg.h>
  19. #define VA_START(args, lastarg) va_start(args, lastarg)
  20. #else /* not __STDC__ */
  21. #include <varargs.h>
  22. #define VA_START(args, lastarg) va_start(args)
  23. #endif /* __STDC__ */
  24. #else /* not VPRINTF_MISSING */
  25. #ifndef DOPRNT_MISSING
  26. #define va_alist args
  27. #define va_dcl int args;
  28. #else /* DOPRNT_MISSING */
  29. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  30. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  31. #endif /* DOPRNT_MISSING */
  32. #endif /* VPRINTF_MISSING */
  33. #ifdef STDC_HEADERS
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #else /* not STDC_HEADERS */
  37. void exit ();
  38. #endif /* STDC_HEADERS */
  39. #ifdef STRERROR_MISSING
  40. static char *
  41. private_strerror (errnum)
  42. int errnum;
  43. {
  44. extern char *sys_errlist[];
  45. extern int sys_nerr;
  46. if (errnum > 0 && errnum < sys_nerr)
  47. return sys_errlist[errnum];
  48. return "Unknown system error";
  49. }
  50. #define strerror private_strerror
  51. #endif /* STRERROR_MISSING */
  52. /* Print the program name and error message MESSAGE, which is a printf-style
  53. format string with optional args.
  54. If ERRNUM is nonzero, print its corresponding system error message.
  55. Exit with status STATUS if it is nonzero. */
  56. /* VARARGS */
  57. void
  58. #if !defined (VPRINTF_MISSING) && defined (__STDC__)
  59. error (int status, int errnum, char *message, ...)
  60. #else /* VPRINTF_MISSING or not __STDC__ */
  61. error (status, errnum, message, va_alist)
  62. int status;
  63. int errnum;
  64. char *message;
  65. va_dcl
  66. #endif /* not VPRINTF_MISSING or __STDC__ */
  67. {
  68. extern char *program_name;
  69. #ifndef VPRINTF_MISSING
  70. va_list args;
  71. #endif /* VPRINTF_MISSING */
  72. fprintf (stderr, "%s: ", program_name);
  73. #ifndef VPRINTF_MISSING
  74. VA_START (args, message);
  75. vfprintf (stderr, message, args);
  76. va_end (args);
  77. #else /* VPRINTF_MISSING */
  78. #ifndef DOPRNT_MISSING
  79. _doprnt (message, &args, stderr);
  80. #else /* DOPRNT_MISSING */
  81. fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  82. #endif /* DOPRNT_MISSING */
  83. #endif /* VPRINTF_MISSING */
  84. if (errnum)
  85. fprintf (stderr, ": %s", strerror (errnum));
  86. putc ('\n', stderr);
  87. fflush (stderr);
  88. if (status)
  89. exit (status);
  90. }