home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.2 / util-lin / util-linux-2.2 / bsd / err.c next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  4.1 KB  |  190 lines

  1. /*-
  2.  * Copyright (c) 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #if defined(LIBC_SCCS) && !defined(lint)
  35. static char sccsid[] = "@(#)err.c    8.1 (Berkeley) 6/4/93";
  36. #endif /* LIBC_SCCS and not lint */
  37.  
  38. #include <err.h>
  39. #include <errno.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43.  
  44. #ifdef __STDC__
  45. #include <stdarg.h>
  46. #else
  47. #include <varargs.h>
  48. #endif
  49.  
  50. extern char *__progname;        /* Program name, from crt0. */
  51. #ifdef __linux__
  52. char *__progname;
  53. #endif
  54.  
  55. __dead void
  56. #ifdef __STDC__
  57. err(int eval, const char *fmt, ...)
  58. #else
  59. err(eval, fmt, va_alist)
  60.     int eval;
  61.     const char *fmt;
  62.     va_dcl
  63. #endif
  64. {
  65.     va_list ap;
  66. #if __STDC__
  67.     va_start(ap, fmt);
  68. #else
  69.     va_start(ap);
  70. #endif
  71.     verr(eval, fmt, ap);
  72.     va_end(ap);
  73. }
  74.  
  75. __dead void
  76. verr(eval, fmt, ap)
  77.     int eval;
  78.     const char *fmt;
  79.     va_list ap;
  80. {
  81.     int sverrno;
  82.  
  83.     sverrno = errno;
  84.     (void)fprintf(stderr, "%s: ", __progname);
  85.     if (fmt != NULL) {
  86.         (void)vfprintf(stderr, fmt, ap);
  87.         (void)fprintf(stderr, ": ");
  88.     }
  89.     (void)fprintf(stderr, "%s\n", strerror(sverrno));
  90.     exit(eval);
  91. }
  92.  
  93. __dead void
  94. #if __STDC__
  95. errx(int eval, const char *fmt, ...)
  96. #else
  97. errx(eval, fmt, va_alist)
  98.     int eval;
  99.     const char *fmt;
  100.     va_dcl
  101. #endif
  102. {
  103.     va_list ap;
  104. #if __STDC__
  105.     va_start(ap, fmt);
  106. #else
  107.     va_start(ap);
  108. #endif
  109.     verrx(eval, fmt, ap);
  110.     va_end(ap);
  111. }
  112.  
  113. __dead void
  114. verrx(eval, fmt, ap)
  115.     int eval;
  116.     const char *fmt;
  117.     va_list ap;
  118. {
  119.     (void)fprintf(stderr, "%s: ", __progname);
  120.     if (fmt != NULL)
  121.         (void)vfprintf(stderr, fmt, ap);
  122.     (void)fprintf(stderr, "\n");
  123.     exit(eval);
  124. }
  125.  
  126. void
  127. #if __STDC__
  128. warn(const char *fmt, ...)
  129. #else
  130. warn(fmt, va_alist)
  131.     const char *fmt;
  132.     va_dcl
  133. #endif
  134. {
  135.     va_list ap;
  136. #if __STDC__
  137.     va_start(ap, fmt);
  138. #else
  139.     va_start(ap);
  140. #endif
  141.     vwarn(fmt, ap);
  142.     va_end(ap);
  143. }
  144.  
  145. void
  146. vwarn(fmt, ap)
  147.     const char *fmt;
  148.     va_list ap;
  149. {
  150.     int sverrno;
  151.  
  152.     sverrno = errno;
  153.     (void)fprintf(stderr, "%s: ", __progname);
  154.     if (fmt != NULL) {
  155.         (void)vfprintf(stderr, fmt, ap);
  156.         (void)fprintf(stderr, ": ");
  157.     }
  158.     (void)fprintf(stderr, "%s\n", strerror(sverrno));
  159. }
  160.  
  161. void
  162. #ifdef __STDC__
  163. warnx(const char *fmt, ...)
  164. #else
  165. warnx(fmt, va_alist)
  166.     const char *fmt;
  167.     va_dcl
  168. #endif
  169. {
  170.     va_list ap;
  171. #ifdef __STDC__
  172.     va_start(ap, fmt);
  173. #else
  174.     va_start(ap);
  175. #endif
  176.     vwarnx(fmt, ap);
  177.     va_end(ap);
  178. }
  179.  
  180. void
  181. vwarnx(fmt, ap)
  182.     const char *fmt;
  183.     va_list ap;
  184. {
  185.     (void)fprintf(stderr, "%s: ", __progname);
  186.     if (fmt != NULL)
  187.         (void)vfprintf(stderr, fmt, ap);
  188.     (void)fprintf(stderr, "\n");
  189. }
  190.