3 * Common things for all utilities
5 * Jan Kara <jack@suse.cz> - sponsored by SuSE CR
7 * Jani Jaakkola <jjaakkol@cs.helsinki.fi> - syslog support
17 #include <sys/types.h>
23 static int enable_syslog=0;
27 openlog(progname,0,LOG_DAEMON);
31 static void do_syslog(int level, const char *format, va_list args)
36 vsnprintf(buf,sizeof(buf),format,args);
37 /* This while removes newlines from the log, so that
38 * syslog() will be called once for every line */
39 for (i = 0; buf[i]; i = j) {
40 for (j = i; buf[j] && buf[j] != '\n'; j++);
43 syslog(level, "%s", buf + i);
47 void die(int ret, char *fmtstr, ...)
51 va_start(args, fmtstr);
53 do_syslog(LOG_CRIT, fmtstr, args);
54 syslog(LOG_CRIT, "Exiting with status %d", ret);
56 fprintf(stderr, "%s: ", progname);
57 vfprintf(stderr, fmtstr, args);
63 void errstr(char *fmtstr, ...)
67 va_start(args, fmtstr);
69 do_syslog(LOG_ERR, fmtstr, args);
71 fprintf(stderr, "%s: ", progname);
72 vfprintf(stderr, fmtstr, args);
77 void *smalloc(size_t size)
79 void *ret = malloc(size);
82 fputs("Not enough memory.\n", stderr);
88 void *srealloc(void *ptr, size_t size)
90 void *ret = realloc(ptr, size);
93 fputs("Not enough memory.\n", stderr);
99 void sstrncpy(char *d, const char *s, size_t len)
105 void sstrncat(char *d, const char *s, size_t len)
111 char *sstrdup(const char *s)
116 puts("Not enough memory.");
124 printf(_("Quota utilities version %s.\n"), PACKAGE_VERSION);
125 printf(_("Compiled with:%s\n"), COMPILE_OPTS);
126 printf(_("Bugs to %s\n"), MY_EMAIL);