From: Sascha Schumann Date: Sun, 27 Aug 2000 09:30:15 +0000 (+0000) Subject: Add PHP_STRLCPY macro. This macro should be used in new code instead of X-Git-Tag: php-4.0.2~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=365edaddd4f8d412cd5933cf2cfc6571a12ca887;p=php Add PHP_STRLCPY macro. This macro should be used in new code instead of strlcpy/strlcat which are intended for fixing broken code. --- 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 #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