5 #define offsetof(s, m) (unsigned long)(&(((s*)0)->m))
8 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
11 #define ABS(x) ( (x) < 0 ? -(x) : (x) )
14 #define MAX(a,b) ( (a) > (b) ? (a) : (b) )
17 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
20 #define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) )
22 #define MAX4(a,b,c,d) MAX(MAX(a,b), MAX(c,d))
23 #define MIN4(a,b,c,d) MIN(MIN(a,b), MIN(c,d))
25 #define STRIDE(n, bcp) (((bpc) * (n) + 7) / 8)
27 /* plan9 stuff for utf-8 and path munging */
28 int chartorune(int *rune
, char *str
);
29 int runetochar(char *str
, int *rune
);
31 int runenlen(int *r
, int nrune
);
32 int fullrune(char *str
, int n
);
33 char *cleanname(char *name
);
35 typedef struct fz_error_s fz_error
;
46 #define fz_outofmem (&fz_koutofmem)
47 extern fz_error fz_koutofmem
;
50 #define fz_throw(...) fz_throw0(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
52 #define fz_throw(...) fz_throw0(__func__, __FILE__, __LINE__, __VA_ARGS__)
54 #define fz_throw fz_throw1
56 fz_error
*fz_throw0(const char *func
, const char *file
, int line
, char *fmt
, ...);
57 fz_error
*fz_throw1(char *fmt
, ...);
59 void fz_warn(char *fmt
, ...);
60 void fz_droperror(fz_error
*eo
);
62 typedef struct fz_memorycontext_s fz_memorycontext
;
64 struct fz_memorycontext_s
66 void * (*malloc
)(fz_memorycontext
*, int);
67 void * (*realloc
)(fz_memorycontext
*, void *, int);
68 void (*free
)(fz_memorycontext
*, void *);
71 fz_memorycontext
*fz_currentmemorycontext(void);
72 void fz_setmemorycontext(fz_memorycontext
*memorycontext
);
74 void *fz_malloc(int n
);
75 void *fz_realloc(void *p
, int n
);
76 void fz_free(void *p
);
78 char *fz_strdup(char *s
);