File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sudo / src / error.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 16:23:02 2012 UTC (12 years, 4 months ago) by misho
Branches: sudo, MAIN
CVS tags: v1_8_3p2, HEAD
sudo

    1: /*
    2:  * Copyright (c) 2004-2005, 2010 Todd C. Miller <Todd.Miller@courtesan.com>
    3:  *
    4:  * Permission to use, copy, modify, and distribute this software for any
    5:  * purpose with or without fee is hereby granted, provided that the above
    6:  * copyright notice and this permission notice appear in all copies.
    7:  *
    8:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    9:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   10:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   11:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   12:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   13:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   14:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   15:  */
   16: 
   17: #include <config.h>
   18: 
   19: #include <sys/types.h>
   20: 
   21: #include <errno.h>
   22: #include <stdio.h>
   23: #include <stdlib.h>
   24: #include <string.h>
   25: 
   26: #include "missing.h"
   27: #include "error.h"
   28: 
   29: #define DEFAULT_TEXT_DOMAIN	"sudo"
   30: #include "gettext.h"
   31: 
   32: static void _warning(int, const char *, va_list);
   33:        void cleanup(int);
   34: 
   35: void
   36: error(int eval, const char *fmt, ...)
   37: {
   38: 	va_list ap;
   39: 	va_start(ap, fmt);
   40: 	_warning(1, fmt, ap);
   41: 	va_end(ap);
   42: 	cleanup(0);
   43: 	exit(eval);
   44: }
   45: 
   46: void
   47: errorx(int eval, const char *fmt, ...)
   48: {
   49: 	va_list ap;
   50: 	va_start(ap, fmt);
   51: 	_warning(0, fmt, ap);
   52: 	va_end(ap);
   53: 	cleanup(0);
   54: 	exit(eval);
   55: }
   56: 
   57: void
   58: warning(const char *fmt, ...)
   59: {
   60: 	va_list ap;
   61: 	va_start(ap, fmt);
   62: 	_warning(1, fmt, ap);
   63: 	va_end(ap);
   64: }
   65: 
   66: void
   67: warningx(const char *fmt, ...)
   68: {
   69: 	va_list ap;
   70: 	va_start(ap, fmt);
   71: 	_warning(0, fmt, ap);
   72: 	va_end(ap);
   73: }
   74: 
   75: static void
   76: _warning(int use_errno, const char *fmt, va_list ap)
   77: {
   78: 	int serrno = errno;
   79: 
   80: 	fputs(getprogname(), stderr);
   81: 	if (fmt != NULL) {
   82: 		fputs(_(": "), stderr);
   83: 		vfprintf(stderr, fmt, ap);
   84: 	}
   85: 	if (use_errno) {
   86: 	    fputs(_(": "), stderr);
   87: 	    fputs(strerror(serrno), stderr);
   88: 	}
   89: 	putc('\n', stderr);
   90: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>