00001
00002
00003
00004 #define nil ((void*)0)
00005 #include <sys/types.h>
00006 #include <stdio.h>
00007 #include <stdarg.h>
00008 #include <stdlib.h>
00009 #include <time.h>
00010 #include "misc.h"
00011
00012 char *prog_name;
00013 time_t now;
00014 time_t next;
00015
00016 size_t alloc_count;
00017
00018 void *allocate(size_t len)
00019
00020 {
00021 void *mem;
00022
00023 if ((mem= malloc(len)) == nil) {
00024 log(LOG_ALERT, "Out of memory, exiting\n");
00025 exit(1);
00026 }
00027 alloc_count++;
00028 return mem;
00029 }
00030
00031 void deallocate(void *mem)
00032 {
00033 if (mem != nil) {
00034 free(mem);
00035 alloc_count--;
00036 }
00037 }
00038
00039 static enum logto logto= SYSLOG;
00040
00041 void selectlog(enum logto where)
00042
00043 {
00044 logto= where;
00045 }
00046
00047 void log(int level, const char *fmt, ...)
00048
00049 {
00050 va_list ap;
00051
00052 va_start(ap, fmt);
00053
00054 #if __minix_vmd || !__minix
00055 if (logto == SYSLOG) {
00056 vsyslog(level, fmt, ap);
00057 } else
00058 #endif
00059 {
00060 fprintf(stderr, "%s: ", prog_name);
00061 vfprintf(stderr, fmt, ap);
00062 }
00063 va_end(ap);
00064 }
00065
00066
00067
00068