summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2010-04-30 16:06:03 +0000
committerDaniel Silverstone <dsilvers@netsurf-browser.org>2010-04-30 16:06:03 +0000
commit5e887908b34b804a19b2b7370b0aa358d0e55973 (patch)
tree68935c8d2fe196a64a17bace1508884d538a5e17 /utils
parentf0237aac922a3ee5b14233fa98baf19df97866ed (diff)
downloadnetsurf-5e887908b34b804a19b2b7370b0aa358d0e55973.tar.gz
netsurf-5e887908b34b804a19b2b7370b0aa358d0e55973.tar.bz2
Consolidate several 'myrealloc' functions into ns_realloc, rename one which *is* different, thereby eliminating the word 'myrealloc' from the NS codebase
svn path=/trunk/netsurf/; revision=10530
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.c13
-rw-r--r--utils/utils.h12
2 files changed, 25 insertions, 0 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 175b33073..346fd5585 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -39,6 +39,19 @@
#include "utils/utf8.h"
#include "utils/utils.h"
+void *
+ns_realloc(void *ptr, size_t size, void *pw)
+{
+ (void)pw;
+
+ if (ptr == NULL)
+ return size > 0 ? malloc(size) : NULL;
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ }
+ return realloc(ptr, size);
+}
char * strip(char * const s)
{
diff --git a/utils/utils.h b/utils/utils.h
index f58a2632b..5b06d9caa 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -78,6 +78,18 @@ typedef struct
#define nsmkdir(dir, mode) mkdir((dir))
#endif
+/**
+ * Private-word-capable realloc() implementation which
+ * behaves as most NS libraries expect in the face of
+ * realloc(ptr, 0) and realloc(NULL, size).
+ *
+ * \param ptr The pointer for reallocation
+ * \param size The number of bytes for the allocation
+ * \param pw A "private word" which we ignore.
+ * \return The new pointer (NULL on frees or errors)
+ */
+void *ns_realloc(void *ptr, size_t size, void *pw);
+
char * strip(char * const s);
int whitespace(const char * str);
char * squash_whitespace(const char * s);