From 89496ce1e6024ddb7802755a2a657bd25dcb6306 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Wed, 20 Dec 2006 20:12:11 +0000 Subject: [PATCH] - Implement zend_zstrndup() --- Zend/zend.h | 16 ++++++++-------- Zend/zend_alloc.c | 8 ++++++++ Zend/zend_alloc.h | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Zend/zend.h b/Zend/zend.h index c7434459fc..faf5b3c3be 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -221,13 +221,19 @@ char *alloca (); #define ZTS_V 0 #endif +#include + +typedef union _zstr { + char *s; + UChar *u; + void *v; +} zstr; + #include "zend_errors.h" #include "zend_alloc.h" #include "zend_types.h" -#include - #ifdef HAVE_LIMITS_H # include #endif @@ -240,12 +246,6 @@ char *alloca (); #define LONG_MIN (- LONG_MAX - 1) #endif -typedef union _zstr { - char *s; - UChar *u; - void *v; -} zstr; - #ifdef __GNUC__ # define ZSTR(x) ((zstr)(x)) # define NULL_ZSTR ZSTR((void*)NULL) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 5efd93765e..2509899af3 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -2033,6 +2033,14 @@ ZEND_API UChar *zend_ustrndup(const UChar *s, uint length) return p; } +ZEND_API zstr zend_zstrndup(int type, const zstr s, uint length) +{ + if (type == IS_STRING) { + return zend_strndup(s.s, length); + } else { + return zend_ustrndup(s.u, length); + } +} ZEND_API int zend_set_memory_limit(unsigned int memory_limit) { diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h index 00672f9b0b..186efdffe7 100644 --- a/Zend/zend_alloc.h +++ b/Zend/zend_alloc.h @@ -41,6 +41,7 @@ BEGIN_EXTERN_C() ZEND_API char *zend_strndup(const char *s, unsigned int length) ZEND_ATTRIBUTE_MALLOC; ZEND_API UChar *zend_ustrndup(const UChar *s, uint length) ZEND_ATTRIBUTE_MALLOC; +ZEND_API zstr zend_zstrndup(int type, const zstr s, uint length) ZEND_ATTRIBUTE_MALLOC; ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC; ZEND_API void *_safe_emalloc(size_t nmemb, size_t size, size_t offset ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC; -- 2.40.0