]> granicus.if.org Git - php/commitdiff
- Implement zend_zstrndup()
authorMarcus Boerger <helly@php.net>
Wed, 20 Dec 2006 20:12:11 +0000 (20:12 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 20 Dec 2006 20:12:11 +0000 (20:12 +0000)
Zend/zend.h
Zend/zend_alloc.c
Zend/zend_alloc.h

index c7434459fcdb757568fcc6ab49e8c099e12656df..faf5b3c3be570f13cc720db0f0421f3600cdd23a 100644 (file)
@@ -221,13 +221,19 @@ char *alloca ();
 #define ZTS_V 0
 #endif
 
+#include <unicode/utypes.h>
+
+typedef union _zstr {
+       char  *s;
+       UChar *u;
+       void  *v;
+} zstr;
+
 #include "zend_errors.h"
 #include "zend_alloc.h"
 
 #include "zend_types.h"
 
-#include <unicode/utypes.h>
-
 #ifdef HAVE_LIMITS_H
 # include <limits.h>
 #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)
index 5efd93765effa7f198ce2299e09e868908435302..2509899af36626257066deb43b106b5e79386eda 100644 (file)
@@ -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)
 {
index 00672f9b0ba2e2085135ac7c66893429b43153ee..186efdffe7701936e6c9344135c9bf57db94eca5 100644 (file)
@@ -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;