158449Sbostic /*-
2*61111Sbostic * Copyright (c) 1993
3*61111Sbostic * The Regents of the University of California. All rights reserved.
458449Sbostic *
558449Sbostic * %sccs.include.redist.c%
658449Sbostic */
758449Sbostic
858449Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*61111Sbostic static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 06/04/93";
1058449Sbostic #endif /* LIBC_SCCS and not lint */
1158449Sbostic
1258449Sbostic #include <err.h>
1358449Sbostic #include <errno.h>
1458449Sbostic #include <stdio.h>
1558449Sbostic #include <stdlib.h>
1658449Sbostic #include <string.h>
1758449Sbostic
1858449Sbostic #ifdef __STDC__
1958449Sbostic #include <stdarg.h>
2058449Sbostic #else
2158449Sbostic #include <varargs.h>
2258449Sbostic #endif
2358449Sbostic
2458449Sbostic extern char *__progname; /* Program name, from crt0. */
2558449Sbostic
2658449Sbostic __dead void
2758449Sbostic #ifdef __STDC__
err(int eval,const char * fmt,...)2858449Sbostic err(int eval, const char *fmt, ...)
2958449Sbostic #else
3058449Sbostic err(eval, fmt, va_alist)
3158449Sbostic int eval;
3258449Sbostic const char *fmt;
3358449Sbostic va_dcl
3458449Sbostic #endif
3558449Sbostic {
3658449Sbostic va_list ap;
3758449Sbostic #if __STDC__
3858449Sbostic va_start(ap, fmt);
3958449Sbostic #else
4058449Sbostic va_start(ap);
4158449Sbostic #endif
4258449Sbostic verr(eval, fmt, ap);
4358449Sbostic va_end(ap);
4458449Sbostic }
4558449Sbostic
4658449Sbostic __dead void
verr(eval,fmt,ap)4758449Sbostic verr(eval, fmt, ap)
4858449Sbostic int eval;
4958449Sbostic const char *fmt;
5058449Sbostic va_list ap;
5158449Sbostic {
5258449Sbostic int sverrno;
5358449Sbostic
5458449Sbostic sverrno = errno;
5558449Sbostic (void)fprintf(stderr, "%s: ", __progname);
5658738Sbostic if (fmt != NULL) {
5758738Sbostic (void)vfprintf(stderr, fmt, ap);
5858738Sbostic (void)fprintf(stderr, ": ");
5958738Sbostic }
6058738Sbostic (void)fprintf(stderr, "%s\n", strerror(sverrno));
6158449Sbostic exit(eval);
6258449Sbostic }
6358449Sbostic
6458449Sbostic __dead void
6558449Sbostic #if __STDC__
errx(int eval,const char * fmt,...)6658449Sbostic errx(int eval, const char *fmt, ...)
6758449Sbostic #else
6858449Sbostic errx(eval, fmt, va_alist)
6958449Sbostic int eval;
7058449Sbostic const char *fmt;
7158449Sbostic va_dcl
7258449Sbostic #endif
7358449Sbostic {
7458449Sbostic va_list ap;
7558449Sbostic #if __STDC__
7658449Sbostic va_start(ap, fmt);
7758449Sbostic #else
7858449Sbostic va_start(ap);
7958449Sbostic #endif
8058449Sbostic verrx(eval, fmt, ap);
8158449Sbostic va_end(ap);
8258449Sbostic }
8358449Sbostic
8458449Sbostic __dead void
verrx(eval,fmt,ap)8558449Sbostic verrx(eval, fmt, ap)
8658449Sbostic int eval;
8758449Sbostic const char *fmt;
8858449Sbostic va_list ap;
8958449Sbostic {
9058449Sbostic (void)fprintf(stderr, "%s: ", __progname);
9158738Sbostic if (fmt != NULL)
9258738Sbostic (void)vfprintf(stderr, fmt, ap);
9358449Sbostic (void)fprintf(stderr, "\n");
9458449Sbostic exit(eval);
9558449Sbostic }
9658449Sbostic
9758449Sbostic void
9858449Sbostic #if __STDC__
warn(const char * fmt,...)9958449Sbostic warn(const char *fmt, ...)
10058449Sbostic #else
10158449Sbostic warn(fmt, va_alist)
10258449Sbostic const char *fmt;
10358449Sbostic va_dcl
10458449Sbostic #endif
10558449Sbostic {
10658449Sbostic va_list ap;
10758449Sbostic #if __STDC__
10858449Sbostic va_start(ap, fmt);
10958449Sbostic #else
11058449Sbostic va_start(ap);
11158449Sbostic #endif
11258449Sbostic vwarn(fmt, ap);
11358449Sbostic va_end(ap);
11458449Sbostic }
11558449Sbostic
11658449Sbostic void
vwarn(fmt,ap)11758449Sbostic vwarn(fmt, ap)
11858449Sbostic const char *fmt;
11958449Sbostic va_list ap;
12058449Sbostic {
12158449Sbostic int sverrno;
12258449Sbostic
12358449Sbostic sverrno = errno;
12458449Sbostic (void)fprintf(stderr, "%s: ", __progname);
12558738Sbostic if (fmt != NULL) {
12658738Sbostic (void)vfprintf(stderr, fmt, ap);
12758738Sbostic (void)fprintf(stderr, ": ");
12858738Sbostic }
12958738Sbostic (void)fprintf(stderr, "%s\n", strerror(sverrno));
13058449Sbostic }
13158449Sbostic
13258449Sbostic void
13358449Sbostic #ifdef __STDC__
warnx(const char * fmt,...)13458449Sbostic warnx(const char *fmt, ...)
13558449Sbostic #else
13658449Sbostic warnx(fmt, va_alist)
13758449Sbostic const char *fmt;
13858449Sbostic va_dcl
13958449Sbostic #endif
14058449Sbostic {
14158449Sbostic va_list ap;
14258449Sbostic #ifdef __STDC__
14358449Sbostic va_start(ap, fmt);
14458449Sbostic #else
14558449Sbostic va_start(ap);
14658449Sbostic #endif
14758449Sbostic vwarnx(fmt, ap);
14858449Sbostic va_end(ap);
14958449Sbostic }
15058449Sbostic
15158449Sbostic void
vwarnx(fmt,ap)15258449Sbostic vwarnx(fmt, ap)
15358449Sbostic const char *fmt;
15458449Sbostic va_list ap;
15558449Sbostic {
15658449Sbostic (void)fprintf(stderr, "%s: ", __progname);
15758738Sbostic if (fmt != NULL)
15858738Sbostic (void)vfprintf(stderr, fmt, ap);
15958449Sbostic (void)fprintf(stderr, "\n");
16058449Sbostic }
161