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