pyceo/src/util.h

90 lines
2.4 KiB
C
Raw Permalink Normal View History

#ifndef CEO_UTIL_H
#define CEO_UTIL_H
#include <stdlib.h>
2009-01-31 01:40:18 -05:00
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
2009-01-31 01:40:18 -05:00
#include <syslog.h>
#include <sys/types.h>
#include <dirent.h>
#include "strbuf.h"
#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
2009-01-31 01:12:37 -05:00
#define PRINTF_LIKE(extra) __attribute__((format(printf, extra+1, extra+2)))
#else
#define NORETURN
2009-01-31 01:12:37 -05:00
#define PRINTF_LIKE(extra)
#endif
2008-03-29 08:12:20 -04:00
#ifndef LOG_AUTHPRIV
#define LOG_AUTHPRIV LOG_AUTH
#endif
2009-01-31 01:40:18 -05:00
extern char **environ;
2009-01-31 01:10:02 -05:00
int spawnv(const char *path, char *const *argv);
2009-01-31 01:40:18 -05:00
int spawnv_msg(const char *path, char *const *argv, const struct strbuf *output);
int spawnvem(const char *path, char *const *argv, char *const *envp, const struct strbuf *output, struct strbuf *input, int cap_stderr);
2009-09-09 17:37:35 -04:00
int spawnvemu(const char *path, char *const *argv, char *const *envp, const struct strbuf *output, struct strbuf *input, int cap_stderr, char *user);
2009-01-31 01:40:18 -05:00
void full_write(int fd, const void *buf, size_t count);
ssize_t full_read(int fd, void *buf, size_t len);
FILE *fopenat(DIR *d, const char *path, int flags);
void make_env(char **envp, ...);
void free_env(char **envp);
void init_log(const char *ident, int option, int facility, int lstderr);
2009-01-31 01:40:18 -05:00
int check_group(char *username, char *group);
2009-09-08 17:45:09 -04:00
void log_set_maxprio(int prio);
2009-01-31 01:12:37 -05:00
PRINTF_LIKE(0) NORETURN void fatal(const char *, ...);
PRINTF_LIKE(0) NORETURN void fatalpe(const char *, ...);
PRINTF_LIKE(0) NORETURN void badconf(const char *, ...);
PRINTF_LIKE(0) NORETURN void deny(const char *, ...);
PRINTF_LIKE(0) void error(const char *, ...);
PRINTF_LIKE(0) void warn(const char *, ...);
PRINTF_LIKE(0) void notice(const char *, ...);
PRINTF_LIKE(0) void debug(const char *, ...);
PRINTF_LIKE(0) void errorpe(const char *, ...);
PRINTF_LIKE(0) void warnpe(const char *, ...);
PRINTF_LIKE(1) void logmsg(int priority, const char *, ...);
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;
}
static inline char *xstrdup(const char *s) {
char *dup = strdup(s);
if (dup == NULL)
fatal("out of memory");
return dup;
}
#endif