Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

err.c

Go to the documentation of this file.
00001 /*
00002  * err.c
00003  *
00004  * Adapted from OpenBSD libc *err* *warn* code.
00005  *
00006  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
00007  *
00008  * Copyright (c) 1993
00009  *      The Regents of the University of California.  All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. All advertising materials mentioning features or use of this software
00020  *    must display the following acknowledgement:
00021  *      This product includes software developed by the University of
00022  *      California, Berkeley and its contributors.
00023  * 4. Neither the name of the University nor the names of its contributors
00024  *    may be used to endorse or promote products derived from this software
00025  *    without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00028  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00031  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00033  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00034  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00035  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00036  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00037  * SUCH DAMAGE.
00038  */
00039 
00040 #ifdef _WIN32
00041 #include <windows.h>
00042 #endif
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <stdarg.h>
00046 #include <string.h>
00047 #include <errno.h>
00048 
00049 void
00050 err(int eval, const char *fmt, ...)
00051 {
00052         va_list ap;
00053         
00054         va_start(ap, fmt);
00055         if (fmt != NULL) {
00056                 (void)vfprintf(stderr, fmt, ap);
00057                 (void)fprintf(stderr, ": ");
00058         }
00059         va_end(ap);
00060 #ifdef _WIN32
00061         (void)fprintf(stderr, "error %lu\n", GetLastError());
00062 #else
00063         (void)fprintf(stderr, "%s\n", strerror(errno));
00064 #endif
00065         exit(eval);
00066 }
00067 
00068 void
00069 warn(const char *fmt, ...)
00070 {
00071         va_list ap;
00072         
00073         va_start(ap, fmt);
00074         if (fmt != NULL) {
00075                 (void)vfprintf(stderr, fmt, ap);
00076                 (void)fprintf(stderr, ": ");
00077         }
00078         va_end(ap);
00079 #ifdef _WIN32
00080         (void)fprintf(stderr, "error %lu\n", GetLastError());
00081 #else
00082         (void)fprintf(stderr, "%s\n", strerror(errno));
00083 #endif
00084 }
00085 
00086 void
00087 errx(int eval, const char *fmt, ...)
00088 {
00089         va_list ap;
00090         
00091         va_start(ap, fmt);
00092         if (fmt != NULL)
00093                 (void)vfprintf(stderr, fmt, ap);
00094         (void)fprintf(stderr, "\n");
00095         va_end(ap);
00096         exit(eval);
00097 }
00098 
00099 void
00100 warnx(const char *fmt, ...)
00101 {
00102         va_list ap;
00103         
00104         va_start(ap, fmt);
00105         if (fmt != NULL)
00106                 (void)vfprintf(stderr, fmt, ap);
00107         (void)fprintf(stderr, "\n");
00108         va_end(ap);
00109 }
00110 

Generated on Sun May 14 14:51:11 2006 by  doxygen 1.4.2