harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

util.h (875B)


      1 #ifndef HARE_UTIL_H
      2 #define HARE_UTIL_H
      3 #include <assert.h>
      4 #include <stdint.h>
      5 
      6 extern const char **sources;
      7 
      8 #define FNV1A_INIT 2166136261u
      9 
     10 uint32_t fnv1a(uint32_t hash, unsigned char c);
     11 uint32_t fnv1a_u32(uint32_t hash, uint32_t u32);
     12 uint32_t fnv1a_u64(uint32_t hash, uint64_t u64);
     13 uint32_t fnv1a_size(uint32_t hash, size_t sz);
     14 uint32_t fnv1a_s(uint32_t hash, const char *str);
     15 void *xcalloc(size_t n, size_t s);
     16 void *xrealloc(void *p, size_t s);
     17 
     18 #define malloc(a) (void *)sizeof(struct { static_assert(0, "Use xcalloc instead"); int _; });
     19 #define calloc(a, b) (void *)sizeof(struct { static_assert(0, "Use xcalloc instead"); int _; });
     20 #define realloc(a, b) (void *)sizeof(struct { static_assert(0, "Use xrealloc instead"); int _; });
     21 
     22 struct pathspec {
     23 	const char *var;
     24 	const char *path;
     25 };
     26 
     27 char *getpath(const struct pathspec *paths, size_t npaths);
     28 
     29 #endif