harec

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

util.h (1094B)


      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 char *xstrdup(const char *s);
     18 
     19 #define malloc(a) (void *)sizeof(struct { static_assert(0, "Use xcalloc instead"); int _; })
     20 #define calloc(a, b) (void *)sizeof(struct { static_assert(0, "Use xcalloc instead"); int _; })
     21 #define realloc(a, b) (void *)sizeof(struct { static_assert(0, "Use xrealloc instead"); int _; })
     22 #define strdup(s) (char *)(sizeof(struct { static_assert(0, "Use xstrdup instead"); int _; })
     23 
     24 char *gen_name(int *id, const char *fmt);
     25 
     26 struct pathspec {
     27 	const char *var;
     28 	const char *path;
     29 };
     30 
     31 char *getpath(const struct pathspec *paths, size_t npaths);
     32 
     33 int errline(const char* path, int lineno, int colno);
     34 
     35 #endif