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