1/*	$NetBSD: err.c,v 1.4 2005/05/11 01:01:56 lukem Exp $	*/
2
3/*
4 * Copyright 1997-2000 Luke Mewburn <lukem@NetBSD.org>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "tnftp.h"
31
32void
33err(int eval, const char *fmt, ...)
34{
35	va_list	ap;
36        int	sverrno;
37
38	sverrno = errno;
39        (void)fprintf(stderr, "%s: ", getprogname());
40	va_start(ap, fmt);
41        if (fmt != NULL) {
42                (void)vfprintf(stderr, fmt, ap);
43                (void)fprintf(stderr, ": ");
44        }
45	va_end(ap);
46        (void)fprintf(stderr, "%s\n", strerror(sverrno));
47        exit(eval);
48}
49
50void
51errx(int eval, const char *fmt, ...)
52{
53	va_list	ap;
54
55        (void)fprintf(stderr, "%s: ", getprogname());
56	va_start(ap, fmt);
57        if (fmt != NULL)
58                (void)vfprintf(stderr, fmt, ap);
59	va_end(ap);
60        (void)fprintf(stderr, "\n");
61        exit(eval);
62}
63
64void
65warn(const char *fmt, ...)
66{
67	va_list	ap;
68        int	sverrno;
69
70	sverrno = errno;
71        (void)fprintf(stderr, "%s: ", getprogname());
72	va_start(ap, fmt);
73        if (fmt != NULL) {
74                (void)vfprintf(stderr, fmt, ap);
75                (void)fprintf(stderr, ": ");
76        }
77	va_end(ap);
78        (void)fprintf(stderr, "%s\n", strerror(sverrno));
79}
80
81void
82warnx(const char *fmt, ...)
83{
84	va_list	ap;
85
86        (void)fprintf(stderr, "%s: ", getprogname());
87	va_start(ap, fmt);
88        if (fmt != NULL)
89                (void)vfprintf(stderr, fmt, ap);
90	va_end(ap);
91        (void)fprintf(stderr, "\n");
92}
93