Revision: 107
http://www.exim.org/viewvc/pcre2?view=rev&revision=107
Author: ph10
Date: 2014-10-12 16:45:05 +0100 (Sun, 12 Oct 2014)
Log Message:
-----------
Create PRIV(strcpy_c8) for copying config strings.
Modified Paths:
--------------
code/trunk/src/pcre2_config.c
code/trunk/src/pcre2_internal.h
code/trunk/src/pcre2_string_utils.c
Modified: code/trunk/src/pcre2_config.c
===================================================================
--- code/trunk/src/pcre2_config.c 2014-10-11 17:05:18 UTC (rev 106)
+++ code/trunk/src/pcre2_config.c 2014-10-12 15:45:05 UTC (rev 107)
@@ -150,11 +150,7 @@
#else
const char *v = "Unicode not supported";
#endif
- PCRE2_UCHAR *t = (PCRE2_UCHAR *)where;
- if (strlen(v) >= BYTES2CU(length) - 1) return PCRE2_ERROR_BADLENGTH;
- while (*v != 0) *t++ = *v++;
- *t = 0;
- return t - (PCRE2_UCHAR *)where;
+ return PRIV(strcpy_c8)((PCRE2_UCHAR *)where, BYTES2CU(length), v);
}
break;
@@ -187,14 +183,10 @@
case PCRE2_CONFIG_VERSION:
{
- PCRE2_UCHAR *t = (PCRE2_UCHAR *)where;
const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?
XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :
XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);
- if (strlen(v) >= BYTES2CU(length) - 1) return PCRE2_ERROR_BADLENGTH;
- while (*v != 0) *t++ = *v++;
- *t = 0;
- return t - (PCRE2_UCHAR *)where;
+ return PRIV(strcpy_c8)((PCRE2_UCHAR *)where, BYTES2CU(length), v);
}
}
Modified: code/trunk/src/pcre2_internal.h
===================================================================
--- code/trunk/src/pcre2_internal.h 2014-10-11 17:05:18 UTC (rev 106)
+++ code/trunk/src/pcre2_internal.h 2014-10-12 15:45:05 UTC (rev 107)
@@ -1865,13 +1865,14 @@
#define _pcre2_jit_get_size PCRE2_SUFFIX(_pcre2_jit_get_size_)
#define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_)
#define _pcre2_ord2utf PCRE2_SUFFIX(_pcre2_ord2utf_)
-#define _pcre2_strcmp PCRE2_SUFFIX(_pcre_strcmp_)
-#define _pcre2_strcmp_c8 PCRE2_SUFFIX(_pcre_strcmp_c8_)
-#define _pcre2_strlen PCRE2_SUFFIX(_pcre_strlen_)
-#define _pcre2_strncmp PCRE2_SUFFIX(_pcre_strncmp_)
-#define _pcre2_strncmp_c8 PCRE2_SUFFIX(_pcre_strncmp_c8_)
-#define _pcre2_study PCRE2_SUFFIX(_pcre_study_)
-#define _pcre2_valid_utf PCRE2_SUFFIX(_pcre_valid_utf_)
+#define _pcre2_strcmp PCRE2_SUFFIX(_pcre2_strcmp_)
+#define _pcre2_strcmp_c8 PCRE2_SUFFIX(_pcre2_strcmp_c8_)
+#define _pcre2_strcpy_c8 PCRE2_SUFFIX(_pcre2_strcpy_c8_)
+#define _pcre2_strlen PCRE2_SUFFIX(_pcre2_strlen_)
+#define _pcre2_strncmp PCRE2_SUFFIX(_pcre2_strncmp_)
+#define _pcre2_strncmp_c8 PCRE2_SUFFIX(_pcre2_strncmp_c8_)
+#define _pcre2_study PCRE2_SUFFIX(_pcre2_study_)
+#define _pcre2_valid_utf PCRE2_SUFFIX(_pcre2_valid_utf_)
#define _pcre2_was_newline PCRE2_SUFFIX(_pcre2_was_newline_)
#define _pcre2_xclass PCRE2_SUFFIX(_pcre2_xclass_)
@@ -1885,6 +1886,7 @@
extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *);
extern int _pcre2_strcmp(PCRE2_SPTR, PCRE2_SPTR);
extern int _pcre2_strcmp_c8(PCRE2_SPTR, const char *);
+extern int _pcre2_strcpy_c8(PCRE2_UCHAR *, size_t, const char *);
extern int _pcre2_strlen(PCRE2_SPTR);
extern int _pcre2_strncmp(PCRE2_SPTR, PCRE2_SPTR, size_t);
extern int _pcre2_strncmp_c8(PCRE2_SPTR, const char *, size_t);
Modified: code/trunk/src/pcre2_string_utils.c
===================================================================
--- code/trunk/src/pcre2_string_utils.c 2014-10-11 17:05:18 UTC (rev 106)
+++ code/trunk/src/pcre2_string_utils.c 2014-10-12 15:45:05 UTC (rev 107)
@@ -160,7 +160,6 @@
}
-
/*************************************************
* Find the length of a PCRE2 string *
*************************************************/
@@ -178,4 +177,28 @@
return c;
}
+
+/*************************************************
+* Copy 8-bit 0-terminated string to PCRE2 string *
+*************************************************/
+
+/* Arguments:
+ str1 buffer to receive the string
+ length length of buffer in code units
+ str2 8-bit string to be copied
+
+Returns: the number of code units used (excluding trailing zero)
+ PCRE2_ERROR_BADLENGTH (a negative number) if buffer is too small
+*/
+
+int
+PRIV(strcpy_c8)(PCRE2_UCHAR *str1, size_t length, const char *str2)
+{
+PCRE2_UCHAR *t = str1;
+if (strlen(str2) >= length) return PCRE2_ERROR_BADLENGTH;
+while (*str2 != 0) *t++ = *str2++;
+*t = 0;
+return t - str1;
+}
+
/* End of pcre2_string_utils.c */