Reformat the source code
[tftp-hpa.git] / tftpd / misc.c
blob07684ddbe054a687a10299b9ffd5278f513b5cfe
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2001-2007 H. Peter Anvin - All Rights Reserved
5 * This program is free software available under the same license
6 * as the "OpenBSD" operating system, distributed at
7 * http://www.openbsd.org/.
9 * ----------------------------------------------------------------------- */
12 * misc.c
14 * Minor help routines.
17 #include "config.h" /* Must be included first! */
18 #include <syslog.h>
19 #include "tftpd.h"
22 * Set the signal handler and flags. Basically a user-friendly
23 * wrapper around sigaction().
25 void set_signal(int signum, void (*handler) (int), int flags)
27 struct sigaction sa;
29 memset(&sa, 0, sizeof sa);
30 sa.sa_handler = handler;
31 sigemptyset(&sa.sa_mask);
32 sa.sa_flags = flags;
34 if (sigaction(signum, &sa, NULL)) {
35 syslog(LOG_ERR, "sigaction: %m");
36 exit(EX_OSERR);
41 * malloc() that syslogs an error message and bails if it fails.
43 void *tfmalloc(size_t size)
45 void *p = malloc(size);
47 if (!p) {
48 syslog(LOG_ERR, "malloc: %m");
49 exit(EX_OSERR);
52 return p;
56 * strdup() that does the equivalent
58 char *tfstrdup(const char *str)
60 char *p = strdup(str);
62 if (!p) {
63 syslog(LOG_ERR, "strdup: %m");
64 exit(EX_OSERR);
67 return p;