home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / apps / posix / source / PAX / WARN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-17  |  6.3 KB  |  269 lines

  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.  
  41. #ifndef lint
  42. static char *ident = "$Id: warn.c,v 1.2 89/02/12 10:06:15 mark Exp $";
  43. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  44. #endif /* ! lint */
  45.  
  46.  
  47. /* Headers */
  48.  
  49. #include "pax.h"
  50.  
  51.  
  52. /* Function Prototypes */
  53.  
  54. #ifdef __STDC__
  55.  
  56. static void prsize(FILE *, OFFSET);
  57.  
  58. #else /* !__STDC__ */
  59.  
  60. static void prsize();
  61.  
  62. #endif /* __STDC__ */
  63.  
  64.  
  65. /* warnarch - print an archive-related warning message and offset
  66.  *
  67.  * DESCRIPTION
  68.  *
  69.  *    Present the user with an error message and an archive offset at
  70.  *    which the error occured.   This can be useful for diagnosing or
  71.  *    fixing damaged archives.
  72.  *
  73.  * PARAMETERS
  74.  *
  75.  *    char     *msg    - A message string to be printed for the user.
  76.  *    OFFSET     adjust    - An adjustment which is added to the current 
  77.  *              archive position to tell the user exactly where 
  78.  *              the error occurred.
  79.  */
  80.  
  81. #ifdef __STDC__
  82.  
  83. void warnarch(char *msg, OFFSET adjust)
  84.  
  85. #else 
  86.  
  87. void warnarch(msg, adjust)
  88. char           *msg;
  89. OFFSET          adjust;
  90.  
  91. #endif
  92. {
  93. #ifdef DF_TRACE_DEBUG
  94. printf("DF_TRACE_DEBUG: void warnarch() in warn.c\n");
  95. #endif
  96.     fprintf(stderr, "%s: [offset ", myname);
  97.     prsize(stderr, total - adjust);
  98.     fprintf(stderr, "]: %s\n", msg);
  99. }
  100.  
  101.  
  102. #ifdef STRERROR  /* Xn */
  103. /* strerror - return pointer to appropriate system error message
  104.  *
  105.  * DESCRIPTION
  106.  *
  107.  *    Get an error message string which is appropriate for the setting
  108.  *    of the errno variable.
  109.  *
  110.  * RETURNS
  111.  *
  112.  *    Returns a pointer to a string which has an appropriate error
  113.  *    message for the present value of errno.  The error message
  114.  *    strings are taken from sys_errlist[] where appropriate.  If an
  115.  *    appropriate message is not available in sys_errlist, then a
  116.  *    pointer to the string "Unknown error (errno <errvalue>)" is 
  117.  *    returned instead.
  118.  */
  119.  
  120. #ifdef __STDC__
  121.  
  122. char *strerror(int errno)  /* Xn */
  123.  
  124. #else
  125.  
  126. char *strerror(errno)  /* Xn */
  127. int             errno;  /* Xn */
  128.  
  129. #endif
  130. {
  131.     static char     msg[40];        /* used for "Unknown error" messages */
  132.  
  133. #ifdef DF_TRACE_DEBUG
  134. printf("DF_TRACE_DEBUG: char *strerror() in warn.c\n");
  135. #endif
  136.     if (errno > 0 && errno < sys_nerr) {
  137.     return (sys_errlist[errno]);
  138.     }
  139.     sprintf(msg, "Unknown error (errno %d)", errno);
  140.     return (msg);
  141. }
  142. #endif  /* Xn */
  143.  
  144.  
  145. /* prsize - print a file offset on a file stream
  146.  *
  147.  * DESCRIPTION
  148.  *
  149.  *    Prints a file offset to a specific file stream.  The file offset is
  150.  *    of the form "%dm+%dk+%d", where the number preceeding the "m" and
  151.  *    the "k" stand for the number of Megabytes and the number of
  152.  *    Kilobytes, respectivley, which have been processed so far.
  153.  *
  154.  * PARAMETERS
  155.  *
  156.  *    FILE  *stream    - Stream which is to be used for output 
  157.  *    OFFSET size    - Current archive position to be printed on the output 
  158.  *              stream in the form: "%dm+%dk+%d".
  159.  *
  160.  */
  161.  
  162. #ifdef __STDC__
  163.  
  164. static void prsize(FILE *stream, OFFSET size)
  165.  
  166. #else
  167.  
  168. static void prsize(stream, size)
  169. FILE           *stream;        /* stream which is used for output */
  170. OFFSET          size;        /* current archive position to be printed */
  171.  
  172. #endif
  173.  
  174. {
  175.     OFFSET          n;
  176.  
  177. #ifdef DF_TRACE_DEBUG
  178. printf("DF_TRACE_DEBUG: static void prsize() in warn.c\n");
  179. #endif
  180.     if ((n = (size / (1024L * 1024L))) != (OFFSET)0) {  /* Xn */
  181.     fprintf(stream, "%ldm+", n);
  182.     size -= n * 1024L * 1024L;
  183.     }
  184.     if ((n = (size / 1024L)) != (OFFSET)0) {  /* Xn */
  185.     fprintf(stream, "%ldk+", n);
  186.     size -= n * 1024L;
  187.     }
  188.     fprintf(stream, "%ld", size);
  189. }
  190.  
  191.  
  192. /* fatal - print fatal message and exit
  193.  *
  194.  * DESCRIPTION
  195.  *
  196.  *    Fatal prints the program's name along with an error message, then
  197.  *    exits the program with a non-zero return code.
  198.  *
  199.  * PARAMETERS
  200.  *
  201.  *    char     *why    - description of reason for termination 
  202.  *        
  203.  * RETURNS
  204.  *
  205.  *    Returns an exit code of 1 to the parent process.
  206.  */
  207.  
  208. #ifdef __STDC__
  209.  
  210. void fatal(char *why)
  211.  
  212. #else
  213.  
  214. void fatal(why)
  215. char           *why;        /* description of reason for termination */
  216.  
  217. #endif
  218. {
  219. #ifdef DF_TRACE_DEBUG
  220. printf("DF_TRACE_DEBUG: void fatal() in warn.c\n");
  221. #endif
  222. #ifdef _POSIX_SOURCE
  223.     perror(why);
  224. #endif
  225.     fprintf(stderr, "%s: %s\n", myname, why);
  226. #if 1 && WIN_NT
  227.     if (ppid == (pid_t) 1 && globulation == 0)
  228.     deglobulate();
  229. #endif
  230.     exit(1);
  231. }
  232.  
  233.  
  234.  
  235. /* warn - print a warning message
  236.  *
  237.  * DESCRIPTION
  238.  *
  239.  *    Print an error message listing the program name, the actual error
  240.  *    which occurred and an informational message as to why the error
  241.  *    occurred on the standard error device.  The standard error is
  242.  *    flushed after the error is printed to assure that the user gets
  243.  *    the message in a timely fasion.
  244.  *
  245.  * PARAMETERS
  246.  *
  247.  *    char *what    - Pointer to string describing what failed.
  248.  *    char *why    - Pointer to string describing why did it failed.
  249.  */
  250.  
  251. #ifdef __STDC__
  252.  
  253. void warn(char *what, char *why)
  254.  
  255. #else
  256.  
  257. void warn(what, why)
  258. char           *what;        /* message as to what the error was */
  259. char           *why;        /* explanation why the error occurred */
  260.  
  261. #endif
  262. {
  263. #ifdef DF_TRACE_DEBUG
  264. printf("DF_TRACE_DEBUG: void warn() in warn.c\n");
  265. #endif
  266.     fprintf(stderr, "%s: %s : %s\n", myname, what, why);
  267.     fflush(stderr);
  268. }
  269.