util.h (2602B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <sys/types.h> 3 4 #include <regex.h> 5 #include <stddef.h> 6 #include <stdio.h> 7 8 #include "arg.h" 9 #include "compat.h" 10 11 #define UTF8_POINT(c) (((c) & 0xc0) != 0x80) 12 13 #undef MIN 14 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 15 #undef MAX 16 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 17 #undef LIMIT 18 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) 19 20 #define LEN(x) (sizeof (x) / sizeof *(x)) 21 22 extern char *argv0; 23 24 void *ecalloc(size_t, size_t); 25 void *emalloc(size_t); 26 void *erealloc(void *, size_t); 27 #undef reallocarray 28 void *reallocarray(void *, size_t, size_t); 29 void *ereallocarray(void *, size_t, size_t); 30 char *estrdup(const char *); 31 char *estrndup(const char *, size_t); 32 void *encalloc(int, size_t, size_t); 33 void *enmalloc(int, size_t); 34 void *enrealloc(int, void *, size_t); 35 void *enreallocarray(int, void *, size_t, size_t); 36 char *enstrdup(int, const char *); 37 char *enstrndup(int, const char *, size_t); 38 39 void enfshut(int, FILE *, const char *); 40 void efshut(FILE *, const char *); 41 int fshut(FILE *, const char *); 42 43 void enprintf(int, const char *, ...); 44 void eprintf(const char *, ...); 45 void weprintf(const char *, ...); 46 47 double estrtod(const char *); 48 49 #undef strcasestr 50 #define strcasestr xstrcasestr 51 char *strcasestr(const char *, const char *); 52 53 #undef strlcat 54 #define strlcat xstrlcat 55 size_t strlcat(char *, const char *, size_t); 56 size_t estrlcat(char *, const char *, size_t); 57 #undef strlcpy 58 #define strlcpy xstrlcpy 59 size_t strlcpy(char *, const char *, size_t); 60 size_t estrlcpy(char *, const char *, size_t); 61 62 #undef strsep 63 #define strsep xstrsep 64 char *strsep(char **, const char *); 65 66 /* regex */ 67 int enregcomp(int, regex_t *, const char *, int); 68 int eregcomp(regex_t *, const char *, int); 69 70 /* io */ 71 ssize_t writeall(int, const void *, size_t); 72 int concat(int, const char *, int, const char *); 73 74 /* misc */ 75 void enmasse(int, char **, int (*)(const char *, const char *, int)); 76 void fnck(const char *, const char *, int (*)(const char *, const char *, int), int); 77 mode_t getumask(void); 78 char *humansize(off_t); 79 mode_t parsemode(const char *, mode_t, mode_t); 80 off_t parseoffset(const char *); 81 void putword(FILE *, const char *); 82 #undef strtonum 83 #define strtonum xstrtonum 84 long long strtonum(const char *, long long, long long, const char **); 85 long long enstrtonum(int, const char *, long long, long long); 86 long long estrtonum(const char *, long long, long long); 87 size_t unescape(char *); 88 int mkdirp(const char *, mode_t, mode_t); 89 #undef memmem 90 #define memmem xmemmem 91 void *memmem(const void *, size_t, const void *, size_t);