custom message type for SEMOP
[minix3.git] / commands / cron / misc.c
blob30b0b036f6a8a96efb7c82f33c8f391a6a7d0142
1 /* misc.c - Miscellaneous stuff for cron Author: Kees J. Bot
2 * 12 Jan 1997
3 */
4 #define nil ((void*)0)
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <time.h>
10 #include "misc.h"
12 char *prog_name; /* Name of this program. */
13 time_t now; /* Cron's idea of the current time. */
14 time_t next; /* Time to run the next job. */
16 size_t alloc_count; /* # Of chunks of memory allocated. */
18 void *allocate(size_t len)
19 /* Checked malloc(). Better not feed it length 0. */
21 void *mem;
23 if ((mem= malloc(len)) == nil) {
24 log(LOG_ALERT, "Out of memory, exiting\n");
25 exit(1);
27 alloc_count++;
28 return mem;
31 void deallocate(void *mem)
33 if (mem != nil) {
34 free(mem);
35 alloc_count--;
39 static enum logto logto= SYSLOG;
41 void selectlog(enum logto where)
42 /* Select where logging output should go, syslog or stdout. */
44 logto= where;
47 void log(int level, const char *fmt, ...)
48 /* Like syslog(), but may go to stderr. */
50 va_list ap;
52 va_start(ap, fmt);
54 #if __minix_vmd || !__minix
55 if (logto == SYSLOG) {
56 vsyslog(level, fmt, ap);
57 } else
58 #endif
60 fprintf(stderr, "%s: ", prog_name);
61 vfprintf(stderr, fmt, ap);
63 va_end(ap);
67 * $PchId: misc.c,v 1.3 2000/07/17 19:01:57 philip Exp $