home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / cctools / libstuff / errors.c < prev    next >
C/C++ Source or Header  |  1995-01-20  |  2KB  |  113 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdarg.h>
  5. #include <errno.h>
  6. #include <mach/mach.h>
  7. #include <mach/mach_error.h>
  8.  
  9. #include "stuff/errors.h"
  10.  
  11. __private_extern__ unsigned long errors = 0;    /* number of calls to error() */
  12.  
  13. /*
  14.  * Just print the message in the standard format without setting an error.
  15.  */
  16. __private_extern__
  17. void
  18. warning(
  19. const char *format,
  20. ...)
  21. {
  22.     va_list ap;
  23.  
  24.     va_start(ap, format);
  25.         fprintf(stderr, "%s: ", progname);
  26.     vfprintf(stderr, format, ap);
  27.         fprintf(stderr, "\n");
  28.     va_end(ap);
  29. }
  30.  
  31. /*
  32.  * Print the error message and return to the caller after setting the error
  33.  * indication.
  34.  */
  35. __private_extern__
  36. void
  37. error(
  38. const char *format,
  39. ...)
  40. {
  41.     va_list ap;
  42.  
  43.     va_start(ap, format);
  44.         fprintf(stderr, "%s: ", progname);
  45.     vfprintf(stderr, format, ap);
  46.         fprintf(stderr, "\n");
  47.     va_end(ap);
  48.     errors++;
  49. }
  50.  
  51. /*
  52.  * Print the error message, the architecture if not NULL and return to the
  53.  * caller after setting the error indication.
  54.  */
  55. __private_extern__
  56. void
  57. error_with_arch(
  58. const char *arch_name,
  59. const char *format,
  60. ...)
  61. {
  62.     va_list ap;
  63.  
  64.     va_start(ap, format);
  65.         fprintf(stderr, "%s: ", progname);
  66.     if(arch_name != NULL)
  67.         fprintf(stderr, "for architecture: %s ", arch_name);
  68.     vfprintf(stderr, format, ap);
  69.         fprintf(stderr, "\n");
  70.     va_end(ap);
  71.     errors++;
  72. }
  73.  
  74. /*
  75.  * Print the error message along with the system error message and return to
  76.  * the caller after setting the error indication.
  77.  */
  78. __private_extern__
  79. void
  80. system_error(
  81. const char *format,
  82. ...)
  83. {
  84.     va_list ap;
  85.  
  86.     va_start(ap, format);
  87.         fprintf(stderr, "%s: ", progname);
  88.     vfprintf(stderr, format, ap);
  89.     fprintf(stderr, " (%s)\n", strerror(errno));
  90.     va_end(ap);
  91.     errors++;
  92. }
  93.  
  94. /*
  95.  * Print the error message along with the mach error string.
  96.  */
  97. __private_extern__
  98. void
  99. my_mach_error(
  100. kern_return_t r,
  101. char *format,
  102. ...)
  103. {
  104.     va_list ap;
  105.  
  106.     va_start(ap, format);
  107.         fprintf(stderr, "%s: ", progname);
  108.     vfprintf(stderr, format, ap);
  109.     fprintf(stderr, " (%s)\n", mach_error_string(r));
  110.     va_end(ap);
  111.     errors++;
  112. }
  113.