File: errors.c

package info (click to toggle)
detachtty 9
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge, squeeze
  • size: 96 kB
  • ctags: 37
  • sloc: ansic: 462; makefile: 56
file content (36 lines) | stat: -rw-r--r-- 704 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
#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);
    if(e>0) 
	fprintf(log_fp," (%s)\n",strerror(e));
    else
	fputc('\n',log_fp);

    kill(getpid(),15);
}