"Fossies" - the Fresh Open Source Software Archive

Member "userinfo-2.5/src/err.c" (15 Jan 2015, 1742 Bytes) of package /linux/privat/userinfo-2.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "err.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.4_vs_2.5.

    1 /*
    2     Copyright (C) 2001-2015 Ben Kibbey <bjk@luxsci.net>
    3 
    4     This program is free software; you can redistribute it and/or modify
    5     it under the terms of the GNU General Public License as published by
    6     the Free Software Foundation; either version 2 of the License, or
    7     (at your option) any later version.
    8 
    9     This program is distributed in the hope that it will be useful,
   10     but WITHOUT ANY WARRANTY; without even the implied warranty of
   11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12     GNU General Public License for more details.
   13 
   14     You should have received a copy of the GNU General Public License
   15     along with this program; if not, write to the Free Software
   16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02110-1301  USA
   17 */
   18 #ifdef HAVE_CONFIG_H
   19 #include <config.h>
   20 #endif
   21 
   22 #include <stdio.h>
   23 #include <stdlib.h>
   24 #include <stdarg.h>
   25 
   26 #ifdef HAVE_LIMITS_H
   27 #include <limits.h>
   28 #ifndef LINE_MAX
   29 #ifdef _POSIX2_LINE_MAX
   30 #define LINE_MAX _POSIX2_LINE_MAX
   31 #else
   32 #define LINE_MAX 2048
   33 #endif
   34 #endif
   35 #endif
   36 
   37 #define err(eval, fmt, ...) print_string(eval, 1, fmt, ## __VA_ARGS__)
   38 #define errx(eval, fmt, ...)    print_string(eval, 0, fmt, ## __VA_ARGS__)
   39 #define warn(fmt, ...)      print_string(-1, 0, fmt, ## __VA_ARGS__)
   40 #define warnx(fmt, ...)     print_string(-1, 1, fmt, ## __VA_ARGS__)
   41 
   42 void print_string(int eval, int prog, const char *fmt, ...)
   43 {
   44     va_list ap;
   45     char line[LINE_MAX];
   46 
   47 #ifndef HAVE___PROGNAME
   48     char *__progname = "ui";
   49 #else
   50     extern char *__progname;
   51 #endif
   52 
   53     va_start(ap, fmt);
   54     vsnprintf(line, sizeof(line), fmt, ap);
   55     va_end(ap);
   56 
   57     fprintf(stderr, "%s%s%s\n", (prog) ? __progname : "", (prog) ? ": " : "",
   58         line);
   59 
   60     if (eval > -1)
   61     exit(eval);
   62 }