OSDN Git Service

Change OpenSSL context mode flags.
[ffftp/ffftp.git] / putty / CONTRIB / CYGTERMD / MALLOC.H
1 /*\r
2  * malloc.h: safe wrappers around malloc, realloc, free, strdup\r
3  */\r
4 \r
5 #ifndef UMLWRAP_MALLOC_H\r
6 #define UMLWRAP_MALLOC_H\r
7 \r
8 #include <stddef.h>\r
9 \r
10 /*\r
11  * smalloc should guarantee to return a useful pointer - Halibut\r
12  * can do nothing except die when it's out of memory anyway.\r
13  */\r
14 void *smalloc(size_t size);\r
15 \r
16 /*\r
17  * srealloc should guaranteeably be able to realloc NULL\r
18  */\r
19 void *srealloc(void *p, size_t size);\r
20 \r
21 /*\r
22  * sfree should guaranteeably deal gracefully with freeing NULL\r
23  */\r
24 void sfree(void *p);\r
25 \r
26 /*\r
27  * dupstr is like strdup, but with the never-return-NULL property\r
28  * of smalloc (and also reliably defined in all environments :-)\r
29  */\r
30 char *dupstr(const char *s);\r
31 \r
32 /*\r
33  * snew allocates one instance of a given type, and casts the\r
34  * result so as to type-check that you're assigning it to the\r
35  * right kind of pointer. Protects against allocation bugs\r
36  * involving allocating the wrong size of thing.\r
37  */\r
38 #define snew(type) \\r
39     ( (type *) smalloc (sizeof (type)) )\r
40 \r
41 /*\r
42  * snewn allocates n instances of a given type, for arrays.\r
43  */\r
44 #define snewn(number, type) \\r
45     ( (type *) smalloc ((number) * sizeof (type)) )\r
46 \r
47 /*\r
48  * sresize wraps realloc so that you specify the new number of\r
49  * elements and the type of the element, with the same type-\r
50  * checking advantages. Also type-checks the input pointer.\r
51  */\r
52 #define sresize(array, number, type) \\r
53     ( (void)sizeof((array)-(type *)0), \\r
54       (type *) srealloc ((array), (number) * sizeof (type)) )\r
55 \r
56 #endif /* UMLWRAP_MALLOC_H */\r