PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/diffutils/lib/ERROR.C

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