aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.h
blob: 32555ce106404d8de23051b2a12320190b3f6c53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef UTIL_H
#define UTIL_H

#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#define ARRSIZE(x)  (sizeof(x)/sizeof((x)[0]))
#define MIN(x,y)    ((x) > (y) ? (y) : (x))
#define MAX(x,y)    ((x) < (y) ? (y) : (x))

#define ERR(...) fprintf(stderr, "ERR: " __VA_ARGS__)

#define NFREE(p) do { free(p); p = NULL; } while (0)
#define NFCLOSE(f) do { fclose(f); f = NULL; } while (0)

#define MHASHLEN 40

enum { FAIL = 0, OK = 1 };

void* checkp(void *p);
void* die(const char *fmtstr, ...);
char* aprintf(const char *fmtstr, ...);

const char* mhash(const char *filename, int len);
int checkalph(const char *str, const char *alph);

void freadstr(FILE *f, char **dst);
void fputstr(FILE *f, char *s);

const char* ask(const char *fmtstr, ...);
void dump(const char *filepath);
int strpfcmp(const char *prefix, const char *str);

float fle32toh(float v);

extern int echo;

#endif /* UTIL_H */