misc.c

Go to the documentation of this file.
00001 /*      misc.c - Miscellaneous stuff for cron           Author: Kees J. Bot
00002  *                                                              12 Jan 1997
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;                /* Name of this program. */
00013 time_t now;                     /* Cron's idea of the current time. */
00014 time_t next;                    /* Time to run the next job. */
00015 
00016 size_t alloc_count;             /* # Of chunks of memory allocated. */
00017 
00018 void *allocate(size_t len)
00019 /* Checked malloc().  Better not feed it length 0. */
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 /* Select where logging output should go, syslog or stdout. */
00043 {
00044         logto= where;
00045 }
00046 
00047 void log(int level, const char *fmt, ...)
00048 /* Like syslog(), but may go to stderr. */
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  * $PchId: misc.c,v 1.3 2000/07/17 19:01:57 philip Exp $
00068  */

Generated on Fri Apr 14 22:56:47 2006 for minix by  doxygen 1.4.6