sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

util.h (2664B)


      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 void strnsubst(char **, const char *, const char *, size_t);
     67 
     68 /* regex */
     69 int enregcomp(int, regex_t *, const char *, int);
     70 int eregcomp(regex_t *, const char *, int);
     71 
     72 /* io */
     73 ssize_t writeall(int, const void *, size_t);
     74 int concat(int, const char *, int, const char *);
     75 
     76 /* misc */
     77 void enmasse(int, char **, int (*)(const char *, const char *, int));
     78 void fnck(const char *, const char *, int (*)(const char *, const char *, int), int);
     79 mode_t getumask(void);
     80 char *humansize(off_t);
     81 mode_t parsemode(const char *, mode_t, mode_t);
     82 off_t parseoffset(const char *);
     83 void putword(FILE *, const char *);
     84 #undef strtonum
     85 #define strtonum xstrtonum
     86 long long strtonum(const char *, long long, long long, const char **);
     87 long long enstrtonum(int, const char *, long long, long long);
     88 long long estrtonum(const char *, long long, long long);
     89 size_t unescape(char *);
     90 int mkdirp(const char *, mode_t, mode_t);
     91 #undef memmem
     92 #define memmem xmemmem
     93 void *memmem(const void *, size_t, const void *, size_t);