| Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Common things for all utilities |
| 3 | * |
| 4 | * Jan Kara <jack@suse.cz> - sponsored by SuSE CR |
| 5 | * |
| 6 | * Jani Jaakkola <jjaakkol@cs.helsinki.fi> - syslog support |
| 7 | */ |
| 8 | |
| Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame^] | 9 | #include "config.h" |
| Aditya Kali | f239fef | 2011-07-20 11:40:02 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdarg.h> |
| 13 | #include <string.h> |
| 14 | #include <syslog.h> |
| 15 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> |
| 17 | |
| 18 | #include "common.h" |
| 19 | |
| 20 | void *smalloc(size_t size) |
| 21 | { |
| 22 | void *ret = malloc(size); |
| 23 | |
| 24 | if (!ret) { |
| 25 | fputs("Not enough memory.\n", stderr); |
| 26 | exit(3); |
| 27 | } |
| 28 | return ret; |
| 29 | } |
| 30 | |
| 31 | void *srealloc(void *ptr, size_t size) |
| 32 | { |
| 33 | void *ret = realloc(ptr, size); |
| 34 | |
| 35 | if (!ret) { |
| 36 | fputs("Not enough memory.\n", stderr); |
| 37 | exit(3); |
| 38 | } |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | void sstrncpy(char *d, const char *s, size_t len) |
| 43 | { |
| 44 | strncpy(d, s, len); |
| 45 | d[len - 1] = 0; |
| 46 | } |
| 47 | |
| 48 | void sstrncat(char *d, const char *s, size_t len) |
| 49 | { |
| 50 | strncat(d, s, len); |
| 51 | d[len - 1] = 0; |
| 52 | } |
| 53 | |
| 54 | char *sstrdup(const char *s) |
| 55 | { |
| 56 | char *r = strdup(s); |
| 57 | |
| 58 | if (!r) { |
| 59 | puts("Not enough memory."); |
| 60 | exit(3); |
| 61 | } |
| 62 | return r; |
| 63 | } |