File: errors.c

package info (click to toggle)
detachtty 5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 80 kB
  • ctags: 35
  • sloc: ansic: 365; makefile: 56
file content (32 lines) | stat: -rw-r--r-- 629 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
#include <stdio.h>
#include <stdarg.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <string.h>

FILE *log_fp=NULL;

int logprintf(char *progname, char *msg,...) {
  int n;
  va_list ap;
  va_start(ap, msg);
  fprintf(log_fp,";;; %s: %ld: ",progname,time(0));
  n=vfprintf(log_fp,msg,ap);
  va_end(ap);
  fprintf(log_fp,"\n");
  return n;
}

void bail(char *progname,char *msg,...) {
  int n;
  va_list ap;
  int e=errno;
  va_start(ap, msg);
  fprintf(log_fp,";;; %s: %ld: FATAL ",progname,time(0));
  n=vfprintf(log_fp,msg,ap);
  va_end(ap);
  fprintf(log_fp," (%s)\n",strerror(e));
  kill(getpid(),15);
}