Alexandre Julliard : libport: Add a replacement implementation for strnlen.

Alexandre Julliard julliard at winehq.org
Sun Mar 18 09:02:33 CDT 2018


Module: wine
Branch: oldstable
Commit: 322f430f2d6eaf2e731a25cd7d16ea052029acf0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=322f430f2d6eaf2e731a25cd7d16ea052029acf0

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Dec 15 10:48:48 2017 +0100

libport: Add a replacement implementation for strnlen.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 9d36aad4571b288f5208d35425e1720c6f145376)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 configure             |  1 +
 configure.ac          |  1 +
 include/config.h.in   |  3 +++
 include/wine/port.h   |  5 +++++
 libs/port/Makefile.in |  1 +
 libs/port/strnlen.c   | 31 +++++++++++++++++++++++++++++++
 6 files changed, 42 insertions(+)

diff --git a/configure b/configure
index 9ae516f..caa68be 100755
--- a/configure
+++ b/configure
@@ -15280,6 +15280,7 @@ for ac_func in \
 	strdup \
 	strerror \
 	strncasecmp \
+	strnlen \
 	strtold \
 	strtoll \
 	strtoull \
diff --git a/configure.ac b/configure.ac
index acf9349..c507d7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2050,6 +2050,7 @@ AC_CHECK_FUNCS(\
 	strdup \
 	strerror \
 	strncasecmp \
+	strnlen \
 	strtold \
 	strtoll \
 	strtoull \
diff --git a/include/config.h.in b/include/config.h.in
index 99906bd..76664df 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -906,6 +906,9 @@
 /* Define to 1 if you have the `strncasecmp' function. */
 #undef HAVE_STRNCASECMP
 
+/* Define to 1 if you have the `strnlen' function. */
+#undef HAVE_STRNLEN
+
 /* Define to 1 if you have the <stropts.h> header file. */
 #undef HAVE_STROPTS_H
 
diff --git a/include/wine/port.h b/include/wine/port.h
index addece0..fb7251e 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -344,6 +344,10 @@ int strncasecmp(const char *str1, const char *str2, size_t n);
 # endif
 #endif /* !defined(HAVE_STRNCASECMP) */
 
+#ifndef HAVE_STRNLEN
+size_t strnlen( const char *str, size_t maxlen );
+#endif /* !defined(HAVE_STRNLEN) */
+
 #ifndef HAVE_STRERROR
 const char *strerror(int err);
 #endif /* !defined(HAVE_STRERROR) */
@@ -538,6 +542,7 @@ extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compa
 #define strcasecmp              __WINE_NOT_PORTABLE(strcasecmp)
 #define strerror                __WINE_NOT_PORTABLE(strerror)
 #define strncasecmp             __WINE_NOT_PORTABLE(strncasecmp)
+#define strnlen                 __WINE_NOT_PORTABLE(strnlen)
 #define usleep                  __WINE_NOT_PORTABLE(usleep)
 
 #endif /* NO_LIBWINE_PORT */
diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in
index 7fefda1..c87b99de 100644
--- a/libs/port/Makefile.in
+++ b/libs/port/Makefile.in
@@ -102,6 +102,7 @@ C_SRCS = \
 	strcasecmp.c \
 	strerror.c \
 	strncasecmp.c \
+	strnlen.c \
 	symlink.c \
 	usleep.c \
 	utf8.c \
diff --git a/libs/port/strnlen.c b/libs/port/strnlen.c
new file mode 100644
index 0000000..ab6668d
--- /dev/null
+++ b/libs/port/strnlen.c
@@ -0,0 +1,31 @@
+/*
+ * strnlen function
+ *
+ * Copyright 2017 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#ifndef HAVE_STRNLEN
+size_t strnlen( const char *str, size_t maxlen )
+{
+    const char *ptr = memchr( str, 0, maxlen );
+    if (!ptr) return maxlen;
+    return ptr - str;
+}
+#endif /* HAVE_STRNLEN */




More information about the wine-cvs mailing list