vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

util.h

(963B)


      1 #ifndef UTIL_H
      2 #define UTIL_H
      3 
      4 #include <stdint.h>
      5 #include <stdbool.h>
      6 
      7 #define LENGTH(x)  ((int)(sizeof (x) / sizeof *(x)))
      8 #define MIN(a, b)  ((a) > (b) ? (b) : (a))
      9 #define MAX(a, b)  ((a) < (b) ? (b) : (a))
     10 
     11 /* is c the start of a utf8 sequence? */
     12 #define ISUTF8(c)   (((c)&0xC0)!=0x80)
     13 #define ISASCII(ch) ((unsigned char)ch < 0x80)
     14 
     15 #if GCC_VERSION>=5004000 || CLANG_VERSION>=4000000
     16 #define addu __builtin_add_overflow
     17 #else
     18 static inline bool addu(size_t a, size_t b, size_t *c) {
     19 	if (SIZE_MAX - a < b)
     20 		return false;
     21 	*c = a + b;
     22 	return true;
     23 }
     24 #endif
     25 
     26 #if !HAVE_MEMRCHR
     27 /* MIT licensed implementation from musl libc */
     28 static void *memrchr(const void *m, int c, size_t n)
     29 {
     30 	const unsigned char *s = m;
     31 	c = (unsigned char)c;
     32 	while (n--) if (s[n]==c) return (void *)(s+n);
     33 	return 0;
     34 }
     35 #endif
     36 
     37 /* Needed for building on GNU Hurd */
     38 
     39 #ifndef PIPE_BUF
     40 #define PIPE_BUF 4096
     41 #endif
     42 
     43 #ifndef PATH_MAX
     44 #define PATH_MAX 4096
     45 #endif
     46 
     47 #endif /* UTIL_H */