summaryrefslogtreecommitdiff
path: root/main/php.h
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2000-08-27 09:30:15 +0000
committerSascha Schumann <sas@php.net>2000-08-27 09:30:15 +0000
commit365edaddd4f8d412cd5933cf2cfc6571a12ca887 (patch)
tree00d06ba70c3e87990ca57018c96a9e25d8f7679e /main/php.h
parentb79db079a6743ae3b1526cd19b5e46e0a3925b18 (diff)
downloadphp-git-365edaddd4f8d412cd5933cf2cfc6571a12ca887.tar.gz
Add PHP_STRLCPY macro. This macro should be used in new code instead of
strlcpy/strlcat which are intended for fixing broken code.
Diffstat (limited to 'main/php.h')
-rw-r--r--main/php.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/main/php.h b/main/php.h
index 8b6b9dd11b..727e789f76 100644
--- a/main/php.h
+++ b/main/php.h
@@ -97,6 +97,27 @@ extern unsigned char second_arg_allow_ref[];
#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);
#endif