]> granicus.if.org Git - php/commitdiff
- Implement ezstrndup()
authorMarcus Boerger <helly@php.net>
Fri, 22 Dec 2006 00:56:59 +0000 (00:56 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 22 Dec 2006 00:56:59 +0000 (00:56 +0000)
Zend/zend_alloc.c
Zend/zend_alloc.h
Zend/zend_interfaces.c

index f5548d3f9f80e784eb69ed3c617b631e7495ea9c..6a12f17934aa18aefd888437eefae784c9f594f6 100644 (file)
@@ -2003,6 +2003,16 @@ ZEND_API UChar *_eustrndup(const UChar *s, int length ZEND_FILE_LINE_DC ZEND_FIL
 }
 
 
+ZEND_API zstr _ezstrndup(int type, const zstr s, uint length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
+{
+       if (type == IS_STRING) {
+               return ZSTR(_estrndup(s.s, length ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC));
+       } else {
+               return ZSTR(_eustrndup(s.u, length ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC));
+       }
+}
+
+
 ZEND_API char *zend_strndup(const char *s, uint length)
 {
        char *p;
index c79d3ffd46fba4967013ca16a773ec2bf53f8cc5..0889e2aac4bc8bf849337120f0715bf4e14bc9b2 100644 (file)
@@ -53,6 +53,7 @@ ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
 ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
 ZEND_API UChar *_eustrdup(const UChar *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
 ZEND_API UChar *_eustrndup(const UChar *s, int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
+ZEND_API zstr _ezstrndup(int type, const zstr s, uint length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
 ZEND_API size_t _zend_mem_block_size(void *ptr TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
 
 /* Standard wrapper macros */
@@ -68,6 +69,7 @@ ZEND_API size_t _zend_mem_block_size(void *ptr TSRMLS_DC ZEND_FILE_LINE_DC ZEND_
 #define eurealloc(ptr, size)                   (UChar*)_erealloc((ptr), UBYTES(size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
 #define eustrndup(s, length)                   _eustrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
 #define eustrdup(s)                                            _eustrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
+#define ezstrndup(type, s, length)      _ezstrndup((type), (s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
 
 /* Relay wrapper macros */
 #define emalloc_rel(size)                                      _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
index 891061249547ff2c365439b0e91441f41fa5fc27..439ef932e19d48f610f10378e4b0bd46c2e99658 100755 (executable)
@@ -429,7 +429,7 @@ int zend_user_serialize(zval *object, int *type, zstr *buffer, zend_uint *buf_le
                        return FAILURE;
                case IS_UNICODE:
                case IS_STRING:
-                       *buffer = zend_zstrndup(Z_TYPE_P(retval), Z_UNIVAL_P(retval), Z_UNILEN_P(retval));
+                       *buffer = ezstrndup(Z_TYPE_P(retval), Z_UNIVAL_P(retval), Z_UNILEN_P(retval));
                        *buf_len = Z_UNILEN_P(retval);
                        *type = Z_TYPE_P(retval);
                        result = SUCCESS;