summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-09-09 20:45:10 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-09-09 20:45:10 +0800
commita8a0ef3c4d10bf576054dc26348d9b4e6efeecc2 (patch)
tree80f15b60c6675b7809f180f931a7ec48ae11a928
parent40fafbfba1a53581e9318c71d6366a24470173be (diff)
downloadpttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.tar
pttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.tar.gz
pttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.tar.bz2
pttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.tar.lz
pttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.tar.xz
pttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.tar.zst
pttbbs-a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2.zip
Using mmap instead of alloca to get buffer when CRITICAL_MEMORY is defined.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2185 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/brc.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/mbbsd/brc.c b/mbbsd/brc.c
index b3be8101..7e61e578 100644
--- a/mbbsd/brc.c
+++ b/mbbsd/brc.c
@@ -133,13 +133,34 @@ brc_enlarge_buf()
char *buffer;
if (brc_alloc >= BRC_MAXSIZE)
return 0;
- buffer = (char*)alloca(brc_alloc);
+
+#ifdef CRITICAL_MEMORY
+#define THE_MALLOC(X) MALLOC(X)
+#define THE_FREE(X) FREE(X)
+#else
+#define THE_MALLOC(X) alloca(X)
+#define THE_FREE(X) (void)(X)
+ /* alloca get memory from stack and automatically freed when
+ * function returns. */
+#endif
+
+ buffer = (char*)THE_MALLOC(brc_alloc);
+
memcpy(buffer, brc_buf, brc_alloc);
free(brc_buf);
brc_alloc += BRC_BLOCKSIZE;
brc_buf = (char*)malloc(brc_alloc);
memcpy(brc_buf, buffer, brc_alloc - BRC_BLOCKSIZE);
+
+#ifdef DEBUG
+ vmsg("brc enlarged to %d bytes", brc_alloc);
+#endif
+
+ THE_FREE(buffer);
return 1;
+
+#undef THE_MALLOC
+#undef THE_FREE
}
static inline void