OSDN Git Service

Add PuTTY 0.61 to contrib directory.
[ffftp/ffftp.git] / contrib / putty / CONTRIB / CYGTERMD / MALLOC.H
diff --git a/contrib/putty/CONTRIB/CYGTERMD/MALLOC.H b/contrib/putty/CONTRIB/CYGTERMD/MALLOC.H
new file mode 100644 (file)
index 0000000..0fd4a36
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+ * malloc.h: safe wrappers around malloc, realloc, free, strdup\r
+ */\r
+\r
+#ifndef UMLWRAP_MALLOC_H\r
+#define UMLWRAP_MALLOC_H\r
+\r
+#include <stddef.h>\r
+\r
+/*\r
+ * smalloc should guarantee to return a useful pointer - Halibut\r
+ * can do nothing except die when it's out of memory anyway.\r
+ */\r
+void *smalloc(size_t size);\r
+\r
+/*\r
+ * srealloc should guaranteeably be able to realloc NULL\r
+ */\r
+void *srealloc(void *p, size_t size);\r
+\r
+/*\r
+ * sfree should guaranteeably deal gracefully with freeing NULL\r
+ */\r
+void sfree(void *p);\r
+\r
+/*\r
+ * dupstr is like strdup, but with the never-return-NULL property\r
+ * of smalloc (and also reliably defined in all environments :-)\r
+ */\r
+char *dupstr(const char *s);\r
+\r
+/*\r
+ * snew allocates one instance of a given type, and casts the\r
+ * result so as to type-check that you're assigning it to the\r
+ * right kind of pointer. Protects against allocation bugs\r
+ * involving allocating the wrong size of thing.\r
+ */\r
+#define snew(type) \\r
+    ( (type *) smalloc (sizeof (type)) )\r
+\r
+/*\r
+ * snewn allocates n instances of a given type, for arrays.\r
+ */\r
+#define snewn(number, type) \\r
+    ( (type *) smalloc ((number) * sizeof (type)) )\r
+\r
+/*\r
+ * sresize wraps realloc so that you specify the new number of\r
+ * elements and the type of the element, with the same type-\r
+ * checking advantages. Also type-checks the input pointer.\r
+ */\r
+#define sresize(array, number, type) \\r
+    ( (void)sizeof((array)-(type *)0), \\r
+      (type *) srealloc ((array), (number) * sizeof (type)) )\r
+\r
+#endif /* UMLWRAP_MALLOC_H */\r