Annotation of embedaddon/sudo/src/error.c, revision 1.1.1.2

1.1       misho       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
1.1.1.2 ! misho      36: error2(int eval, const char *fmt, ...)
1.1       misho      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
1.1.1.2 ! misho      47: errorx2(int eval, const char *fmt, ...)
1.1       misho      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
1.1.1.2 ! misho      58: warning2(const char *fmt, ...)
1.1       misho      59: {
                     60:        va_list ap;
                     61:        va_start(ap, fmt);
                     62:        _warning(1, fmt, ap);
                     63:        va_end(ap);
                     64: }
                     65: 
                     66: void
1.1.1.2 ! misho      67: warningx2(const char *fmt, ...)
1.1       misho      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>