cvs: php4 /main php.h
| From: | Sascha Schumann | Date: | Sun, 27 Aug 2000 09:30:15 +0000 |
| Subject: | cvs: php4 /main php.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1403@lists.php.net to get a copy of this message | ||
sas Sun Aug 27 02:30:15 2000 EDT
Modified files:
/php4/main php.h
Log:
Add PHP_STRLCPY macro. This macro should be used in new code instead of
strlcpy/strlcat which are intended for fixing broken code.
Index: php4/main/php.h
diff -u php4/main/php.h:1.116 php4/main/php.h:1.117
--- php4/main/php.h:1.116 Thu Aug 24 11:49:49 2000
+++ php4/main/php.h Sun Aug 27 02:30:15 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php.h,v 1.116 2000/08/24 18:49:49 zeev Exp $ */
+/* $Id: php.h,v 1.117 2000/08/27 09:30:15 sas Exp $ */
#ifndef PHP_H
#define PHP_H
@@ -96,6 +96,27 @@
#if HAVE_ALLOCA_H
#include <alloca.h>
#endif
+
+/*
+ * This is a fast version of strlcpy which should be used, if you
+ * know the maximum size of the destination buffer and if you know
+ * the length of the source string.
+ *
+ * size is the allocated number of bytes
+ * src_size is the number of bytes excluding the NUL
+ */
+
+#define PHP_STRLCPY(dst, src, size, src_size) \
+ { \
+ size_t php_str_len; \
+ \
+ if (src_size >= size) \
+ php_str_len = size - 1; \
+ else \
+ php_str_len = src_size; \
+ memcpy(dst, src, php_str_len); \
+ dst[php_str_len] = '\0'; \
+ }
#ifndef HAVE_STRLCPY
PHPAPI size_t strlcpy(char *dst, const char *src, size_t siz);