1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
19 #endif /* __cplusplus */
21 #include <stdlib.h> /* size_t; actually stddef.h, but stdlib.h
22 * might be more reliable? --dwp */
26 #include "support.h" /* fc__warn_unused_result */
28 /* fc_malloc, fc_realloc, fc_calloc:
29 * fc_ stands for freeciv; the return value is checked,
30 * and freeciv-specific processing occurs if it is NULL:
31 * a log message, possibly cleanup, and ending with exit(1)
34 #define fc_malloc(sz) fc_real_malloc((sz), "malloc", \
35 __FC_LINE__, __FILE__)
36 #define fc_realloc(ptr,sz) fc_real_realloc((ptr), (sz), "realloc", \
37 __FC_LINE__, __FILE__)
38 #define fc_calloc(n,esz) fc_real_calloc((n), (esz), "calloc", \
39 __FC_LINE__, __FILE__)
41 #define FC_FREE(ptr) do { free(ptr); (ptr) = NULL; } while(0)
43 #define fc_strdup(str) real_fc_strdup((str), "strdup", __FC_LINE__, __FILE__)
45 /***********************************************************************/
47 /* You shouldn't call these functions directly;
48 * use the macros above instead.
50 void *fc_real_malloc(size_t size
,
51 const char *called_as
, int line
, const char *file
)
52 fc__warn_unused_result
;
53 void *fc_real_realloc(void *ptr
, size_t size
,
54 const char *called_as
, int line
, const char *file
)
55 fc__warn_unused_result
;
56 void *fc_real_calloc(size_t nelem
, size_t elsize
,
57 const char *called_as
, int line
, const char *file
)
58 fc__warn_unused_result
;
60 char *real_fc_strdup(const char *str
,
61 const char *called_as
, int line
, const char *file
)
62 fc__warn_unused_result
;
66 #endif /* __cplusplus */
68 #endif /* FC__MEM_H */