2007-12-10 00:25:14 -05:00
|
|
|
#ifndef CEO_UTIL_H
|
|
|
|
#define CEO_UTIL_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define NORETURN __attribute__((__noreturn__))
|
|
|
|
#else
|
|
|
|
#define NORETURN
|
|
|
|
#endif
|
|
|
|
|
2008-03-29 08:12:20 -04:00
|
|
|
#ifndef LOG_AUTHPRIV
|
|
|
|
#define LOG_AUTHPRIV LOG_AUTH
|
|
|
|
#endif
|
|
|
|
|
2007-12-10 00:25:14 -05:00
|
|
|
int spawnv(const char *, char *[]);
|
2009-01-30 23:40:22 -05:00
|
|
|
void init_log(const char *ident, int option, int facility);
|
2007-12-10 00:25:14 -05:00
|
|
|
|
|
|
|
NORETURN void fatal(const char *, ...);
|
|
|
|
NORETURN void fatalpe(const char *, ...);
|
|
|
|
NORETURN void badconf(const char *, ...);
|
|
|
|
NORETURN void deny(const char *, ...);
|
|
|
|
void error(const char *, ...);
|
|
|
|
void warn(const char *, ...);
|
2009-01-31 00:11:42 -05:00
|
|
|
void notice(const char *, ...);
|
2007-12-10 00:25:14 -05:00
|
|
|
void errorpe(const char *, ...);
|
|
|
|
void warnpe(const char *, ...);
|
2009-01-31 00:11:42 -05:00
|
|
|
void logmsg(int, const char *, ...);
|
2007-12-10 00:25:14 -05:00
|
|
|
|
|
|
|
static inline void *xmalloc(size_t size) {
|
|
|
|
void *alloc = malloc(size);
|
|
|
|
|
|
|
|
if (alloc == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
2009-01-31 01:05:41 -05:00
|
|
|
static inline void *xrealloc(void *ptr, size_t size) {
|
|
|
|
void *alloc = realloc(ptr, size);
|
|
|
|
|
|
|
|
if (alloc == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *xcalloc(size_t nmemb, size_t size) {
|
|
|
|
void *alloc = calloc(nmemb, size);
|
|
|
|
|
|
|
|
if (alloc == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-10 00:25:14 -05:00
|
|
|
static inline char *xstrdup(const char *s) {
|
|
|
|
char *dup = strdup(s);
|
|
|
|
|
|
|
|
if (dup == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|