mbdemux

git clone https://orangeshoelaces.net/git/mbdemux.git

/err.c

   1 /* Copyright 2018 Vasilii Kolobkov */
   2 
   3 /* This program is free software: you can redistribute it and/or modify   */
   4 /* it under the terms of the GNU General Public License as published by   */
   5 /* the Free Software Foundation, either version 3 of the License, or      */
   6 /* (at your option) any later version.                                    */
   7 
   8 /* This program is distributed in the hope that it will be useful,        */
   9 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  10 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  11 /* GNU General Public License for more details.                           */
  12 
  13 /* You should have received a copy of the GNU General Public License      */
  14 /* along with this program.  If not, see <https://www.gnu.org/licenses/>. */
  15 
  16 #include <errno.h>
  17 #include <stdarg.h>
  18 #include <stdio.h>
  19 #include <stdlib.h>
  20 #include <string.h>
  21 #include <unistd.h>
  22 
  23 extern char *prog;
  24 
  25 static void
  26 vwarn(char *fmt, va_list ap)
  27 {
  28         dprintf(STDERR_FILENO, fmt ? "%s: " : "%s", prog);
  29         if (fmt) vdprintf(STDERR_FILENO, fmt, ap);
  30         dprintf(STDERR_FILENO, ": %s\n", strerror(errno));
  31 }
  32 
  33 static void
  34 vwarnx(char *fmt, va_list ap)
  35 {
  36         dprintf(STDERR_FILENO, fmt ? "%s: " : "%s", prog);
  37         if (fmt) vdprintf(STDERR_FILENO, fmt, ap);
  38         dprintf(STDERR_FILENO, "\n");
  39 }
  40 
  41 void
  42 warn(char *fmt, ...)
  43 {
  44         va_list ap;
  45 
  46         va_start(ap, fmt);
  47         vwarn(fmt, ap);
  48         va_end(ap);
  49 }
  50 
  51 void
  52 warnx(char *fmt, ...)
  53 {
  54         va_list ap;
  55 
  56         va_start(ap, fmt);
  57         vwarnx(fmt, ap);
  58         va_end(ap);
  59 }
  60 
  61 void
  62 err(int s, char *fmt, ...)
  63 {
  64         va_list ap;
  65 
  66         va_start(ap, fmt);
  67         vwarn(fmt, ap);
  68         va_end(ap);
  69         exit(s);
  70 }
  71 
  72 void
  73 errx(int s, char *fmt, ...)
  74 {
  75         va_list ap;
  76 
  77         va_start(ap, fmt);
  78         vwarnx(fmt, ap);
  79         va_end(ap);
  80         exit(s);
  81 }