OSDN Git Service

add TortoisePlink
[tortoisegit/TortoiseGitJp.git] / src / TortoisePlink / PUTTYMEM.H
diff --git a/src/TortoisePlink/PUTTYMEM.H b/src/TortoisePlink/PUTTYMEM.H
new file mode 100644 (file)
index 0000000..d478f79
--- /dev/null
@@ -0,0 +1,42 @@
+/*\r
+ * PuTTY memory-handling header.\r
+ */\r
+\r
+#ifndef PUTTY_PUTTYMEM_H\r
+#define PUTTY_PUTTYMEM_H\r
+\r
+#include <stddef.h>                   /* for size_t */\r
+#include <string.h>                   /* for memcpy() */\r
+\r
+\r
+/* #define MALLOC_LOG  do this if you suspect putty of leaking memory */\r
+#ifdef MALLOC_LOG\r
+#define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z,1))\r
+#define snmalloc(z,s) (mlog(__FILE__,__LINE__), safemalloc(z,s))\r
+#define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z,1))\r
+#define snrealloc(y,z,s) (mlog(__FILE__,__LINE__), saferealloc(y,z,s))\r
+#define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))\r
+void mlog(char *, int);\r
+#else\r
+#define smalloc(z) safemalloc(z,1)\r
+#define snmalloc safemalloc\r
+#define srealloc(y,z) saferealloc(y,z,1)\r
+#define snrealloc saferealloc\r
+#define sfree safefree\r
+#endif\r
+\r
+void *safemalloc(size_t, size_t);\r
+void *saferealloc(void *, size_t, size_t);\r
+void safefree(void *);\r
+\r
+/*\r
+ * Direct use of smalloc within the code should be avoided where\r
+ * possible, in favour of these type-casting macros which ensure\r
+ * you don't mistakenly allocate enough space for one sort of\r
+ * structure and assign it to a different sort of pointer.\r
+ */\r
+#define snew(type) ((type *)snmalloc(1, sizeof(type)))\r
+#define snewn(n, type) ((type *)snmalloc((n), sizeof(type)))\r
+#define sresize(ptr, n, type) ((type *)snrealloc((ptr), (n), sizeof(type)))\r
+\r
+#endif\r