|
1 /* |
|
2 * libtu/misc.h |
|
3 * |
|
4 * Copyright (c) Tuomo Valkonen 1999-2000. |
|
5 * |
|
6 * This file is distributed under the terms of the "Artistic License". |
|
7 * See the included file LICENSE for details. |
|
8 */ |
|
9 |
|
10 #ifndef __LIBTU_MISC_H |
|
11 #define __LIBTU_MISC_H |
|
12 |
|
13 #include <stdlib.h> |
|
14 #include <stdio.h> |
|
15 #include <malloc.h> |
|
16 #include <assert.h> |
|
17 #include "types.h" |
|
18 |
|
19 #define TR(X) X |
|
20 #define DUMMY_TR(X) X |
|
21 |
|
22 #define ALLOC(X) (X*)malloczero(sizeof(X)) |
|
23 #define ALLOC_N(X, N) (X*)malloczero(sizeof(X)*(N)) |
|
24 #define REALLOC_N(PTR, X, S, N) (X*)remalloczero(PTR, sizeof(X)*(S), sizeof(X)*(N)) |
|
25 |
|
26 #define FREE(X) ({if(X!=NULL) free(X);}) |
|
27 |
|
28 extern void* malloczero(int size); |
|
29 extern void* remalloczero(void *ptr, int oldsize, int newsize); |
|
30 |
|
31 extern char* scopy(const char *p); |
|
32 extern char* scat(const char *p1, const char *p2); |
|
33 extern char* scat3(const char *p1, const char *p2, const char *p3); |
|
34 |
|
35 extern const char* simple_basename(const char *name); |
|
36 |
|
37 /* I dislike fread and fwrite... */ |
|
38 extern bool readf(FILE *fd, void *buf, size_t n); |
|
39 extern bool writef(FILE *fd, const void *buf, size_t n); |
|
40 |
|
41 #endif /* __LIBTU_MISC_H */ |