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.1 (2.11BSD GTE) 2/3/95";
  36: #endif /* LIBC_SCCS and not lint */
  37: 
  38: #include <stdio.h>
  39: 
  40: #ifdef __STDC__
  41: #include <stdarg.h>
  42: #else
  43: #include <varargs.h>
  44: #endif
  45: 
  46: extern  int errno;
  47: extern  char *__progname;       /* Program name, from crt0. */
  48: static  void    putprog(), putcolsp();
  49: 
  50: void
  51: #ifdef __STDC__
  52: err(int eval, const char *fmt, ...)
  53: #else
  54: err(eval, fmt, va_alist)
  55:     int eval;
  56:     char *fmt;
  57:     va_dcl
  58: #endif
  59: {
  60:     va_list ap;
  61: #if __STDC__
  62:     va_start(ap, fmt);
  63: #else
  64:     va_start(ap);
  65: #endif
  66:     verr(eval, fmt, ap);
  67:     va_end(ap);
  68: }
  69: 
  70: void
  71: verr(eval, fmt, ap)
  72:     int eval;
  73:     char *fmt;
  74:     va_list ap;
  75: {
  76:     int sverrno;
  77: 
  78:     sverrno = errno;
  79:     putprog();
  80:     if (fmt != NULL) {
  81:         (void)vfprintf(stderr, fmt, ap);
  82:         putcolsp();
  83:     }
  84:     (void)fputs(strerror(sverrno), stderr);
  85:     (void)fputc('\n', stderr);
  86:     exit(eval);
  87: }
  88: 
  89: void
  90: #if __STDC__
  91: errx(int eval, const char *fmt, ...)
  92: #else
  93: errx(eval, fmt, va_alist)
  94:     int eval;
  95:     char *fmt;
  96:     va_dcl
  97: #endif
  98: {
  99:     va_list ap;
 100: #if __STDC__
 101:     va_start(ap, fmt);
 102: #else
 103:     va_start(ap);
 104: #endif
 105:     verrx(eval, fmt, ap);
 106:     va_end(ap);
 107: }
 108: 
 109: void
 110: verrx(eval, fmt, ap)
 111:     int eval;
 112:     char *fmt;
 113:     va_list ap;
 114: {
 115:     putprog();
 116:     if (fmt != NULL)
 117:         (void)vfprintf(stderr, fmt, ap);
 118:     (void)fputc('\n', stderr);
 119:     exit(eval);
 120: }
 121: 
 122: void
 123: #if __STDC__
 124: warn(const char *fmt, ...)
 125: #else
 126: warn(fmt, va_alist)
 127:     char *fmt;
 128:     va_dcl
 129: #endif
 130: {
 131:     va_list ap;
 132: #if __STDC__
 133:     va_start(ap, fmt);
 134: #else
 135:     va_start(ap);
 136: #endif
 137:     vwarn(fmt, ap);
 138:     va_end(ap);
 139: }
 140: 
 141: void
 142: vwarn(fmt, ap)
 143:     char *fmt;
 144:     va_list ap;
 145: {
 146:     int sverrno;
 147: 
 148:     sverrno = errno;
 149:     putprog();
 150:     if (fmt != NULL) {
 151:         (void)vfprintf(stderr, fmt, ap);
 152:         putcolsp();
 153:     }
 154:     (void)fputs(strerror(sverrno), stderr);
 155:     (void)fputc('\n', stderr);
 156: }
 157: 
 158: void
 159: #ifdef __STDC__
 160: warnx(const char *fmt, ...)
 161: #else
 162: warnx(fmt, va_alist)
 163:     char *fmt;
 164:     va_dcl
 165: #endif
 166: {
 167:     va_list ap;
 168: #ifdef __STDC__
 169:     va_start(ap, fmt);
 170: #else
 171:     va_start(ap);
 172: #endif
 173:     vwarnx(fmt, ap);
 174:     va_end(ap);
 175: }
 176: 
 177: void
 178: vwarnx(fmt, ap)
 179:     char *fmt;
 180:     va_list ap;
 181: {
 182:     putprog();
 183:     if (fmt != NULL)
 184:         (void)vfprintf(stderr, fmt, ap);
 185:     (void)fputc('\n', stderr);
 186: }
 187: 
 188: /*
 189:  * Helper routines.  Repeated constructs of the form "%s: " used up too
 190:  * much D space.  On a pdp-11 code can be overlaid but Data space is worth
 191:  * conserving.  An extra function call or two handling an error condition is
 192:  * a reasonable trade for 20 or 30 bytes of D space.
 193: */
 194: 
 195: static void
 196: putprog()
 197:     {
 198: 
 199:     fputs(__progname, stderr);
 200:     putcolsp();
 201:     }
 202: 
 203: static void
 204: putcolsp()
 205:     {
 206: 
 207:     fputc(':', stderr);
 208:     fputc(' ', stderr);
 209:     }

Defined functions

putcolsp defined in line 203; used 4 times
putprog defined in line 195; used 5 times
verr defined in line 70; used 1 times
  • in line 66
verrx defined in line 109; used 1 times
vwarn defined in line 141; used 1 times
vwarnx defined in line 177; used 2 times

Defined variables

sccsid defined in line 35; never used
Last modified: 1995-02-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3372
Valid CSS Valid XHTML 1.0 Strict