]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
add openconnect__strchrnul function to compat.c
authorDaniel Lenski <dlenski@gmail.com>
Sat, 20 Feb 2021 17:39:07 +0000 (09:39 -0800)
committerDaniel Lenski <dlenski@gmail.com>
Mon, 29 Mar 2021 02:27:01 +0000 (19:27 -0700)
GNU strchrnul() is trivial to implement, and makes a bunch of string parsing
functions simpler and less error-prone.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
compat.c
configure.ac
gpst.c
openconnect-internal.h

index 14e7202f70aa104b01310cc5a245636be0dc2dbd..5a9406caf6238d8bed8de4e2a037d9f3ca8762e5 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -202,6 +202,14 @@ char *openconnect__strndup(const char *s, size_t n)
 }
 #endif
 
+#ifndef HAVE_STRCHRNUL
+const char *openconnect__strchrnul(const char *s, int c)
+{
+       while (*s && *s++ != c);
+       return s;
+}
+#endif
+
 #ifndef HAVE_INET_ATON
 /* XX: unlike "real" inet_aton(), inet_pton() only accepts dotted-decimal notation, not
  * looser/rarer formats like 32-bit decimal values. For example, inet_aton() accepts both
index 8dc46994590d3a74cc15162337ad053e85bc63bb..6133ae23d7d9b088c7d84b24ed15069e91fe5beb 100644 (file)
@@ -141,6 +141,7 @@ AC_CHECK_FUNC(getline, [AC_DEFINE(HAVE_GETLINE, 1, [Have getline() function])],
     [symver_getline="openconnect__getline;"])
 AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1, [Have strcasestr() function])], [])
 AC_CHECK_FUNC(strndup, [AC_DEFINE(HAVE_STRNDUP, 1, [Have strndup() function])], [])
+AC_CHECK_FUNC(strchrnul, [AC_DEFINE(HAVE_STRCHRNUL, 1, [Have strchrnul() function])], [])
 AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1, [Have asprintf() function])],
     [symver_asprintf="openconnect__asprintf;"])
 AC_CHECK_FUNC(vasprintf, [AC_DEFINE(HAVE_VASPRINTF, 1, [Have vasprintf() function])],
diff --git a/gpst.c b/gpst.c
index 345d5143d52e57db3641029775ad276437c6d1c2..17903d18772aa270a4b0535808a84dc88aac4244 100644 (file)
--- a/gpst.c
+++ b/gpst.c
@@ -105,13 +105,13 @@ static int filter_opts(struct oc_text_buf *buf, const char *query, const char *i
        const char *found, *comma;
 
        for (f = query; *f; f=(*endf) ? endf+1 : endf) {
-               endf = strchr(f, '&') ? : f+strlen(f);
+               endf = strchrnul(f, '&');
                eq = strchr(f, '=');
                if (!eq || eq > endf)
                        eq = endf;
 
                for (found = incexc; *found; found=(*comma) ? comma+1 : comma) {
-                       comma = strchr(found, ',') ? : found+strlen(found);
+                       comma = strchrnul(found, ',');
                        if (!strncmp(found, f, MAX(comma-found, eq-f)))
                                break;
                }
index 974248dc3c2ce8cb0f0627a4e80f1b907f52beff..feaff6585900878fcf9a9cbeb2e5ef3ed9bd42a8 100644 (file)
@@ -788,6 +788,11 @@ char *openconnect__strcasestr(const char *haystack, const char *needle);
 #define strndup openconnect__strndup
 char *openconnect__strndup(const char *s, size_t n);
 #endif
+#ifndef HAVE_STRCHRNUL
+#undef strchrnul
+#define strchrnul openconnect__strchrnul
+const char *openconnect__strchrnul(const char *s, int c);
+#endif
 
 #ifndef HAVE_INET_ATON
 #define inet_aton openconnect__inet_aton