Sat, 19 Jan 2002 19:14:36 +0100
trunk: changeset 38
Warning callbacks (thanks to Lukas Schroeder). libtu now depends on
the asprintf functions and one implementation is included in
snprintf_2.2/.
5 | 1 | /* |
2 | * libtu/misc.h | |
3 | * | |
9 | 4 | * Copyright (c) Tuomo Valkonen 1999-2000. |
5 | 5 | * See the included file LICENSE for details. |
6 | */ | |
7 | ||
8 | 8 | #ifndef LIBTU_MISC_H |
9 | #define LIBTU_MISC_H | |
5 | 10 | |
11 | #include <stdlib.h> | |
12 | #include <stdio.h> | |
13 | #include <assert.h> | |
14 | #include "types.h" | |
15 | ||
16 | #define TR(X) X | |
17 | #define DUMMY_TR(X) X | |
18 | ||
19 | #define ALLOC(X) (X*)malloczero(sizeof(X)) | |
20 | #define ALLOC_N(X, N) (X*)malloczero(sizeof(X)*(N)) | |
21 | #define REALLOC_N(PTR, X, S, N) (X*)remalloczero(PTR, sizeof(X)*(S), sizeof(X)*(N)) | |
22 | ||
20 | 23 | #define FREE(X) do{if(X!=NULL)free(X);}while(0) |
5 | 24 | |
25 | extern void* malloczero(size_t size); | |
26 | extern void* remalloczero(void *ptr, size_t oldsize, size_t newsize); | |
27 | ||
28 | extern char* scopy(const char *p); | |
29 | extern char* scat(const char *p1, const char *p2); | |
30 | extern char* scatn(const char *p1, ssize_t n1, const char *p2, ssize_t n2); | |
31 | extern char* scat3(const char *p1, const char *p2, const char *p3); | |
32 | 32 | extern void stripws(char *p); |
5 | 33 | |
34 | extern const char* simple_basename(const char *name); | |
35 | ||
36 | /* I dislike fread and fwrite... */ | |
37 | extern bool readf(FILE *fd, void *buf, size_t n); | |
38 | extern bool writef(FILE *fd, const void *buf, size_t n); | |
39 | ||
8 | 40 | #endif /* LIBTU_MISC_H */ |