Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
6.0 KiB

  1. /* $Source: /u/mark/src/pax/RCS/warn.c,v $
  2. *
  3. * $Revision: 1.2 $
  4. *
  5. * warn.c - miscellaneous user warning routines
  6. *
  7. * DESCRIPTION
  8. *
  9. * These routines provide the user with various forms of warning
  10. * and informational messages.
  11. *
  12. * AUTHOR
  13. *
  14. * Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
  15. *
  16. * Sponsored by The USENIX Association for public distribution.
  17. *
  18. * Copyright (c) 1989 Mark H. Colburn.
  19. * All rights reserved.
  20. *
  21. * Redistribution and use in source and binary forms are permitted
  22. * provided that the above copyright notice is duplicated in all such
  23. * forms and that any documentation, advertising materials, and other
  24. * materials related to such distribution and use acknowledge that the
  25. * software was developed * by Mark H. Colburn and sponsored by The
  26. * USENIX Association.
  27. *
  28. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  29. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  30. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31. *
  32. * $Log: warn.c,v $
  33. * Revision 1.2 89/02/12 10:06:15 mark
  34. * 1.2 release fixes
  35. *
  36. * Revision 1.1 88/12/23 18:02:40 mark
  37. * Initial revision
  38. *
  39. */
  40. #ifndef lint
  41. static char *ident = "$Id: warn.c,v 1.2 89/02/12 10:06:15 mark Exp $";
  42. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  43. #endif /* ! lint */
  44. /* Headers */
  45. #include "pax.h"
  46. /* Function Prototypes */
  47. #ifdef __STDC__
  48. static void prsize(FILE *, OFFSET);
  49. #else /* !__STDC__ */
  50. static void prsize();
  51. #endif /* __STDC__ */
  52. /* warnarch - print an archive-related warning message and offset
  53. *
  54. * DESCRIPTION
  55. *
  56. * Present the user with an error message and an archive offset at
  57. * which the error occured. This can be useful for diagnosing or
  58. * fixing damaged archives.
  59. *
  60. * PARAMETERS
  61. *
  62. * char *msg - A message string to be printed for the user.
  63. * OFFSET adjust - An adjustment which is added to the current
  64. * archive position to tell the user exactly where
  65. * the error occurred.
  66. */
  67. #ifdef __STDC__
  68. void warnarch(char *msg, OFFSET adjust)
  69. #else
  70. void warnarch(msg, adjust)
  71. char *msg;
  72. OFFSET adjust;
  73. #endif
  74. {
  75. #ifdef DF_TRACE_DEBUG
  76. printf("DF_TRACE_DEBUG: void warnarch() in warn.c\n");
  77. #endif
  78. fprintf(stderr, "%s: [offset ", myname);
  79. prsize(stderr, total - adjust);
  80. fprintf(stderr, "]: %s\n", msg);
  81. }
  82. #ifdef STRERROR /* Xn */
  83. /* strerror - return pointer to appropriate system error message
  84. *
  85. * DESCRIPTION
  86. *
  87. * Get an error message string which is appropriate for the setting
  88. * of the errno variable.
  89. *
  90. * RETURNS
  91. *
  92. * Returns a pointer to a string which has an appropriate error
  93. * message for the present value of errno. The error message
  94. * strings are taken from sys_errlist[] where appropriate. If an
  95. * appropriate message is not available in sys_errlist, then a
  96. * pointer to the string "Unknown error (errno <errvalue>)" is
  97. * returned instead.
  98. */
  99. #ifdef __STDC__
  100. char *strerror(int errno) /* Xn */
  101. #else
  102. char *strerror(errno) /* Xn */
  103. int errno; /* Xn */
  104. #endif
  105. {
  106. static char msg[40]; /* used for "Unknown error" messages */
  107. #ifndef DF_POSIX //DF_MSS
  108. #ifdef DF_TRACE_DEBUG
  109. printf("DF_TRACE_DEBUG: char *strerror() in warn.c\n");
  110. #endif
  111. if (errno > 0 && errno < sys_nerr) {
  112. return (sys_errlist[errno]);
  113. }
  114. #endif
  115. sprintf(msg, "Unknown error (errno %d)", errno);
  116. return (msg);
  117. }
  118. #endif /* Xn */
  119. /* prsize - print a file offset on a file stream
  120. *
  121. * DESCRIPTION
  122. *
  123. * Prints a file offset to a specific file stream. The file offset is
  124. * of the form "%dm+%dk+%d", where the number preceeding the "m" and
  125. * the "k" stand for the number of Megabytes and the number of
  126. * Kilobytes, respectivley, which have been processed so far.
  127. *
  128. * PARAMETERS
  129. *
  130. * FILE *stream - Stream which is to be used for output
  131. * OFFSET size - Current archive position to be printed on the output
  132. * stream in the form: "%dm+%dk+%d".
  133. *
  134. */
  135. #ifdef __STDC__
  136. static void prsize(FILE *stream, OFFSET size)
  137. #else
  138. static void prsize(stream, size)
  139. FILE *stream; /* stream which is used for output */
  140. OFFSET size; /* current archive position to be printed */
  141. #endif
  142. {
  143. OFFSET n;
  144. #ifdef DF_TRACE_DEBUG
  145. printf("DF_TRACE_DEBUG: static void prsize() in warn.c\n");
  146. #endif
  147. if (n = (size / (1024L * 1024L))) {
  148. fprintf(stream, "%ldm+", n);
  149. size -= n * 1024L * 1024L;
  150. }
  151. if (n = (size / 1024L)) {
  152. fprintf(stream, "%ldk+", n);
  153. size -= n * 1024L;
  154. }
  155. fprintf(stream, "%ld", size);
  156. }
  157. /* fatal - print fatal message and exit
  158. *
  159. * DESCRIPTION
  160. *
  161. * Fatal prints the program's name along with an error message, then
  162. * exits the program with a non-zero return code.
  163. *
  164. * PARAMETERS
  165. *
  166. * char *why - description of reason for termination
  167. *
  168. * RETURNS
  169. *
  170. * Returns an exit code of 1 to the parent process.
  171. */
  172. #ifdef __STDC__
  173. void fatal(char *why)
  174. #else
  175. void fatal(why)
  176. char *why; /* description of reason for termination */
  177. #endif
  178. {
  179. #ifdef DF_TRACE_DEBUG
  180. printf("DF_TRACE_DEBUG: void fatal() in warn.c\n");
  181. #endif
  182. #ifdef _POSIX_SOURCE
  183. perror(why);
  184. #endif
  185. fprintf(stderr, "%s: %s\n", myname, why);
  186. exit(1);
  187. }
  188. /* warn - print a warning message
  189. *
  190. * DESCRIPTION
  191. *
  192. * Print an error message listing the program name, the actual error
  193. * which occurred and an informational message as to why the error
  194. * occurred on the standard error device. The standard error is
  195. * flushed after the error is printed to assure that the user gets
  196. * the message in a timely fasion.
  197. *
  198. * PARAMETERS
  199. *
  200. * char *what - Pointer to string describing what failed.
  201. * char *why - Pointer to string describing why did it failed.
  202. */
  203. #ifdef __STDC__
  204. void warn(char *what, char *why)
  205. #else
  206. void warn(what, why)
  207. char *what; /* message as to what the error was */
  208. char *why; /* explanation why the error occurred */
  209. #endif
  210. {
  211. #ifdef DF_TRACE_DEBUG
  212. printf("DF_TRACE_DEBUG: void warn() in warn.c\n");
  213. #endif
  214. fprintf(stderr, "%s: %s : %s\n", myname, what, why);
  215. fflush(stderr);
  216. }