error.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * (C) Copyright 2000
  3. * Murray Jensen <Murray.Jensen@csiro.au>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <errno.h>
  27. #include "error.h"
  28. char *pname;
  29. void
  30. Warning(char *fmt, ...)
  31. {
  32. va_list args;
  33. fprintf(stderr, "%s: WARNING: ", pname);
  34. va_start(args, fmt);
  35. vfprintf(stderr, fmt, args);
  36. va_end(args);
  37. fprintf(stderr, "\n");
  38. }
  39. void
  40. Error(char *fmt, ...)
  41. {
  42. va_list args;
  43. fprintf(stderr, "%s: ERROR: ", pname);
  44. va_start(args, fmt);
  45. vfprintf(stderr, fmt, args);
  46. va_end(args);
  47. fprintf(stderr, "\n");
  48. exit(1);
  49. }
  50. void
  51. Perror(char *fmt, ...)
  52. {
  53. va_list args;
  54. int e = errno;
  55. char *p;
  56. fprintf(stderr, "%s: ERROR: ", pname);
  57. va_start(args, fmt);
  58. vfprintf(stderr, fmt, args);
  59. va_end(args);
  60. if ((p = strerror(e)) == NULL || *p == '\0')
  61. fprintf(stderr, ": Unknown Error (%d)\n", e);
  62. else
  63. fprintf(stderr, ": %s\n", p);
  64. exit(1);
  65. }