home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / rpm / lib / rpmerr.c < prev    next >
C/C++ Source or Header  |  1997-09-17  |  805b  |  54 lines

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3.  
  4. #include "rpmlib.h"
  5.  
  6. static struct err {
  7.     int code;
  8.     char string[1024];
  9. } errorRec;
  10.  
  11. static rpmErrorCallBackType errorCallback = NULL;
  12.  
  13. int rpmErrorCode(void)
  14. {
  15.     return errorRec.code;
  16. }
  17.  
  18. char *rpmErrorCodeString(void)
  19. {
  20.     return NULL;
  21. }
  22.  
  23. char *rpmErrorString(void)
  24. {
  25.     return errorRec.string;
  26. }
  27.  
  28. rpmErrorCallBackType rpmErrorSetCallback(rpmErrorCallBackType cb)
  29. {
  30.     rpmErrorCallBackType ocb;
  31.  
  32.     ocb = errorCallback;
  33.     errorCallback = cb;
  34.     
  35.     return ocb;
  36. }
  37.  
  38. void rpmError(int code, char *format, ...)
  39. {
  40.     va_list args;
  41.  
  42.     va_start(args, format);
  43.  
  44.     errorRec.code = code;
  45.     vsprintf(errorRec.string, format, args);
  46.  
  47.     if (errorCallback) {
  48.     errorCallback();
  49.     } else {
  50.     fputs(errorRec.string, stderr);
  51.     fputs("\n", stderr);
  52.     }
  53. }
  54.