File: log.c

package info (click to toggle)
sn 0.3.4a-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 784 kB
  • ctags: 826
  • sloc: ansic: 9,023; sh: 339; makefile: 208
file content (46 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
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
40
41
42
43
44
45
46
/*
 * This file is part of the sn package.
 * Distribution of sn is covered by the GNU GPL. See file COPYING.
 * Copyright  1998-2000 Harold Tay.
 * Copyright  2000- Patrik Rdman.
 */

#include <stdarg.h>
#include <unistd.h>
#include "format.h"

char *progname = 0;
static char logbuf[1024];

void logv (char *fmt, va_list ap)
{
   int len = 0;

   if (progname)
   {
      for (; progname[len]; len++)
         logbuf[len] = progname[len];
      logbuf[len++] = ':';
   }
   len += formatv(logbuf + len, sizeof (logbuf) - len - 2, fmt, ap);
   logbuf[len] = '\n';
   write(2, logbuf, len + 1);
}

void log (char *fmt, ...)
{
   va_list ap;

   va_start(ap, fmt);
   logv(fmt, ap);
   va_end(ap);
}

void fail (int ex, char *fmt, ...)
{
   va_list ap;

   va_start(ap, fmt);
   logv(fmt, ap);
   _exit(ex);
}