source: trunk/minix/commands/cron/misc.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.2 KB
Line 
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"
11
12char *prog_name; /* Name of this program. */
13time_t now; /* Cron's idea of the current time. */
14time_t next; /* Time to run the next job. */
15
16size_t alloc_count; /* # Of chunks of memory allocated. */
17
18void *allocate(size_t len)
19/* Checked malloc(). Better not feed it length 0. */
20{
21 void *mem;
22
23 if ((mem= malloc(len)) == nil) {
24 log(LOG_ALERT, "Out of memory, exiting\n");
25 exit(1);
26 }
27 alloc_count++;
28 return mem;
29}
30
31void deallocate(void *mem)
32{
33 if (mem != nil) {
34 free(mem);
35 alloc_count--;
36 }
37}
38
39static enum logto logto= SYSLOG;
40
41void selectlog(enum logto where)
42/* Select where logging output should go, syslog or stdout. */
43{
44 logto= where;
45}
46
47void log(int level, const char *fmt, ...)
48/* Like syslog(), but may go to stderr. */
49{
50 va_list ap;
51
52 va_start(ap, fmt);
53
54#if __minix_vmd || !__minix
55 if (logto == SYSLOG) {
56 vsyslog(level, fmt, ap);
57 } else
58#endif
59 {
60 fprintf(stderr, "%s: ", prog_name);
61 vfprintf(stderr, fmt, ap);
62 }
63 va_end(ap);
64}
65
66/*
67 * $PchId: misc.c,v 1.3 2000/07/17 19:01:57 philip Exp $
68 */
Note: See TracBrowser for help on using the repository browser.