util.h (972B)
1#ifndef UTIL_H 2#define UTIL_H 3 4#include <stdlib.h> 5#include <stdarg.h> 6#include <string.h> 7#include <stdio.h> 8#include <errno.h> 9 10#define ARRSIZE(x) (sizeof(x)/sizeof((x)[0])) 11#define MIN(x,y) ((x) > (y) ? (y) : (x)) 12#define MAX(x,y) ((x) < (y) ? (y) : (x)) 13 14#define PRINTABLE(c) ((c) >= 32 ? (c) : ' ') 15 16#define ERR(...) printf("ERR: " __VA_ARGS__) 17 18#define FREE(p) do { free(p); p = NULL; } while (0) 19#define FCLOSE(f) do { if (f) fclose(f); f = NULL; } while (0) 20 21#define MHASHLEN 40 22 23enum { FAIL = 0, OK = 1 }; 24 25void* checkp(void *p); 26void* die(const char *fmtstr, ...); 27char* aprintf(const char *fmtstr, ...); 28 29const char* mhash(const char *filename, int len); 30int checkalph(const char *str, const char *alph); 31 32void freadstr(FILE *f, char **dst); 33void fputstr(FILE *f, char *s); 34 35const char* ask(const char *fmtstr, ...); 36void dump(const char *filepath); 37int strpfcmp(const char *prefix, const char *str); 38 39float fle32toh(float v); 40 41extern int echo; 42 43#endif