util.h (2397B)
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 char *enstrdup(int, const char *); 36 char *enstrndup(int, const char *, size_t); 37 38 void enfshut(int, FILE *, const char *); 39 void efshut(FILE *, const char *); 40 int fshut(FILE *, const char *); 41 42 void enprintf(int, const char *, ...); 43 void eprintf(const char *, ...); 44 void weprintf(const char *, ...); 45 46 double estrtod(const char *); 47 48 #undef strcasestr 49 char *strcasestr(const char *, const char *); 50 51 #undef strlcat 52 size_t strlcat(char *, const char *, size_t); 53 size_t estrlcat(char *, const char *, size_t); 54 #undef strlcpy 55 size_t strlcpy(char *, const char *, size_t); 56 size_t estrlcpy(char *, const char *, size_t); 57 58 #undef strsep 59 char *strsep(char **, const char *); 60 61 /* regex */ 62 int enregcomp(int, regex_t *, const char *, int); 63 int eregcomp(regex_t *, const char *, int); 64 65 /* io */ 66 ssize_t writeall(int, const void *, size_t); 67 int concat(int, const char *, int, const char *); 68 69 /* misc */ 70 void enmasse(int, char **, int (*)(const char *, const char *, int)); 71 void fnck(const char *, const char *, int (*)(const char *, const char *, int), int); 72 mode_t getumask(void); 73 char *humansize(off_t); 74 mode_t parsemode(const char *, mode_t, mode_t); 75 off_t parseoffset(const char *); 76 void putword(FILE *, const char *); 77 #undef strtonum 78 long long strtonum(const char *, long long, long long, const char **); 79 long long enstrtonum(int, const char *, long long, long long); 80 long long estrtonum(const char *, long long, long long); 81 size_t unescape(char *); 82 int mkdirp(const char *, mode_t, mode_t); 83 #undef memmem 84 void *memmem(const void *, size_t, const void *, size_t);