aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

util.h (3733B)


      1 /* see LICENSE file for copyright and license details */
      2 #ifndef UTIL_H
      3 #define UTIL_H
      4 
      5 #include <sys/types.h>
      6 
      7 #include <regex.h>
      8 #include <stdarg.h>
      9 #include <stddef.h>
     10 #include <stdio.h>
     11 #include <string.h>
     12 
     13 #include "arg.h"
     14 #include "compat.h"
     15 #include "net.h"
     16 #include "sysinfo.h"
     17 
     18 #define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
     19 
     20 #undef MIN
     21 #define MIN(x, y) ((x) < (y) ? (x) : (y))
     22 #undef MAX
     23 #define MAX(x, y) ((x) > (y) ? (x) : (y))
     24 #undef LIMIT
     25 #define LIMIT(x, a, b) (x) = (x)<(a) ? (a) : (x)>(b) ? (b) : (x)
     26 
     27 #define LEN(x) (sizeof(x) / sizeof *(x))
     28 
     29 extern char *argv0;
     30 
     31 void *ecalloc(size_t, size_t);
     32 void *emalloc(size_t);
     33 void *erealloc(void *, size_t);
     34 #undef reallocarray
     35 void *reallocarray(void *, size_t, size_t);
     36 void *ereallocarray(void *, size_t, size_t);
     37 char *estrdup(const char *);
     38 char *estrndup(const char *, size_t);
     39 void *encalloc(int, size_t, size_t);
     40 void *enmalloc(int, size_t);
     41 void *enrealloc(int, void *, size_t);
     42 void *enreallocarray(int, void *, size_t, size_t);
     43 char *enstrdup(int, const char *);
     44 char *enstrndup(int, const char *, size_t);
     45 
     46 void enfshut(int, FILE *, const char *);
     47 void efshut(FILE *, const char *);
     48 int  fshut(FILE *, const char *);
     49 
     50 void enprintf(int, const char *, ...) __attribute__((noreturn));
     51 void eprintf(const char *, ...) __attribute__((noreturn));
     52 void weprintf(const char *, ...);
     53 void xvprintf(const char *, va_list);
     54 
     55 int confirm(const char *, ...);
     56 
     57 double estrtod(const char *);
     58 
     59 #undef strcasestr
     60 #define strcasestr xstrcasestr
     61 char *strcasestr(const char *, const char *);
     62 
     63 #undef strlcat
     64 #define strlcat xstrlcat
     65 size_t strlcat(char *, const char *, size_t);
     66 size_t estrlcat(char *, const char *, size_t);
     67 #undef strlcpy
     68 #define strlcpy xstrlcpy
     69 size_t strlcpy(char *, const char *, size_t);
     70 size_t estrlcpy(char *, const char *, size_t);
     71 
     72 #undef strsep
     73 #define strsep xstrsep
     74 char *strsep(char **, const char *);
     75 
     76 void strnsubst(char **, const char *, const char *, size_t);
     77 
     78 /* regex */
     79 int enregcomp(int, regex_t *, const char *, int);
     80 int eregcomp(regex_t *, const char *, int);
     81 
     82 /* io */
     83 ssize_t writeall(int, const void *, size_t);
     84 int     copyall(int, int);
     85 int     concat(int, const char *, int, const char *);
     86 
     87 /* misc */
     88 void   enmasse(int, char **, int (*)(const char *, const char *, int));
     89 void   fnck(const char *, const char *, int (*)(const char *, const char *, int), int);
     90 mode_t getumask(void);
     91 int    hexval(int);
     92 char  *humansize(off_t);
     93 mode_t parsemode(const char *, mode_t, mode_t);
     94 off_t  parseoffset(const char *);
     95 void   putword(FILE *, const char *);
     96 #undef strtonum
     97 #define strtonum xstrtonum
     98 long long strtonum(const char *, long long, long long, const char **);
     99 long long enstrtonum(int, const char *, long long, long long);
    100 long long estrtonum(const char *, long long, long long);
    101 size_t    unescape(char *);
    102 int       mkdirp(const char *, mode_t, mode_t);
    103 #undef memmem
    104 #define memmem xmemmem
    105 void *memmem(const void *, size_t, const void *, size_t);
    106 
    107 /* ubase functions */
    108 char         *agetcwd(void);
    109 void          apathmax(char **, long *);
    110 long          estrtol(const char *, int);
    111 unsigned long estrtoul(const char *, int);
    112 #undef explicit_bzero
    113 void        explicit_bzero(void *, size_t);
    114 void        recurse_dir(const char *, void (*)(const char *));
    115 void        devtotty(int, int *, int *);
    116 int         ttytostr(int, int, char *, size_t);
    117 const char *ttyconsole(void);
    118 const char *ttyconsterm(void);
    119 void        ttyhangup(void);
    120 
    121 /* getopt starts over on a new argument list, the way each system's libc
    122  * is told to: a getopt_<os>.c per system */
    123 void getopt_reset(void);
    124 
    125 #if FEATURE_NOEXEC || FEATURE_NOFORK
    126 #include "wexec.h"
    127 #define exit(code)  wexec_exit(code)
    128 #define _exit(code) wexec_exit(code)
    129 #endif
    130 
    131 #endif