File: error.c

package info (click to toggle)
mtr 0.96-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 972 kB
  • sloc: ansic: 10,665; python: 1,171; makefile: 164; sh: 141
file content (39 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 /*
   Linux error(3) function go around for systems that has err(3) and
   warn(3), but no error(3).  MacOS is good example of such.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation version 2.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA.
*/

#include <stdarg.h>
#include <err.h>

void error(int status, int errnum, const char *format, ...) {
  va_list arg;

  va_start(arg, format);
  if (errnum == 0) {
    if (status == 0)
      vwarnx(format, arg);
    else
      verrx(status, format, arg);
  } else {
    if (status == 0)
      vwarn(format, arg);
    else
      verr(status, format, arg);
  }
  va_end(arg);
}