1 /* $Source: /u/mark/src/pax/RCS/warn.c,v $
5 * warn.c - miscellaneous user warning routines
9 * These routines provide the user with various forms of warning
10 * and informational messages.
14 * Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
16 * Sponsored by The USENIX Association for public distribution.
18 * Copyright (c) 1989 Mark H. Colburn.
19 * All rights reserved.
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
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.
33 * Revision 1.2 89/02/12 10:06:15 mark
36 * Revision 1.1 88/12/23 18:02:40 mark
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";
52 /* Function Prototypes */
56 static void prsize(FILE *, OFFSET);
65 /* warnarch - print an archive-related warning message and offset
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.
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
83 void warnarch(char *msg, OFFSET adjust)
87 void warnarch(msg, adjust)
93 fprintf(stderr, "%s: [offset ", myname);
94 prsize(stderr, total - adjust);
95 fprintf(stderr, "]: %s\n", msg);
99 /* strerror - return pointer to appropriate system error message
103 * Get an error message string which is appropriate for the setting
104 * of the errno variable.
108 * Returns a pointer to a string which has an appropriate error
109 * message for the present value of errno. The error message
110 * strings are taken from sys_errlist[] where appropriate. If an
111 * appropriate message is not available in sys_errlist, then a
112 * pointer to the string "Unknown error (errno <errvalue>)" is
128 return (strerror(errno));
130 static char msg[40]; /* used for "Unknown error" messages */
132 if (errno > 0 && errno < sys_nerr) {
133 return (sys_errlist[errno]);
135 sprintf(msg, "Unknown error (errno %d)", errno);
141 /* prsize - print a file offset on a file stream
145 * Prints a file offset to a specific file stream. The file offset is
146 * of the form "%dm+%dk+%d", where the number preceeding the "m" and
147 * the "k" stand for the number of Megabytes and the number of
148 * Kilobytes, respectivley, which have been processed so far.
152 * FILE *stream - Stream which is to be used for output
153 * OFFSET size - Current archive position to be printed on the output
154 * stream in the form: "%dm+%dk+%d".
160 static void prsize(FILE *stream, OFFSET size)
164 static void prsize(stream, size)
165 FILE *stream; /* stream which is used for output */
166 OFFSET size; /* current archive position to be printed */
173 if (n = (size / (1024L * 1024L))) {
174 fprintf(stream, "%ldm+", n);
175 size -= n * 1024L * 1024L;
177 if (n = (size / 1024L)) {
178 fprintf(stream, "%ldk+", n);
181 fprintf(stream, "%ld", size);
185 /* fatal - print fatal message and exit
189 * Fatal prints the program's name along with an error message, then
190 * exits the program with a non-zero return code.
194 * char *why - description of reason for termination
198 * Returns an exit code of 1 to the parent process.
203 void fatal(char *why)
208 char *why; /* description of reason for termination */
212 fprintf(stderr, "%s: %s\n", myname, why);
218 /* warn - print a warning message
222 * Print an error message listing the program name, the actual error
223 * which occurred and an informational message as to why the error
224 * occurred on the standard error device. The standard error is
225 * flushed after the error is printed to assure that the user gets
226 * the message in a timely fasion.
230 * char *what - Pointer to string describing what failed.
231 * char *why - Pointer to string describing why did it failed.
236 void warn(char *what, char *why)
241 char *what; /* message as to what the error was */
242 char *why; /* explanation why the error occurred */
246 fprintf(stderr, "%s: %s : %s\n", myname, what, why);