]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ctype: remove all use of <ctype.h>, use our own versions
authorDaniel Stenberg <daniel@haxx.se>
Mon, 5 Sep 2022 22:17:36 +0000 (00:17 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 6 Sep 2022 06:32:36 +0000 (08:32 +0200)
Except in the test servers.

Closes #9433

lib/curl_setup_once.h
lib/hostip.c
lib/strcase.c
lib/strcase.h
lib/url.c
lib/urlapi.c
lib/vtls/x509asn1.c
src/tool_setopt.c
tests/server/tftpd.c

index e9730c928280b19613fc012185263216c5a5870d..d5c2d4d45470b0589a0acecd1e44dbb52d1b8253 100644 (file)
@@ -33,7 +33,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
-#include <ctype.h>
 #include <time.h>
 
 #ifdef HAVE_ERRNO_H
@@ -229,9 +228,6 @@ struct timeval {
 #  define sfcntl  fcntl
 #endif
 
-#define TOLOWER(x)  (tolower((int)  ((unsigned char)x)))
-
-
 /*
  * 'bool' stuff compatible with HP-UX headers.
  */
index 66f1f7d4b9e0d893dcb2550140d67e276ae60555..d08d4daec8518a4a0bfb9706ebb5e465ee121aa0 100644 (file)
@@ -181,7 +181,7 @@ create_hostcache_id(const char *name, int port, char *ptr, size_t buflen)
     len = buflen - 7;
   /* store and lower case the name */
   while(len--)
-    *ptr++ = (char)TOLOWER(*name++);
+    *ptr++ = Curl_raw_tolower(*name++);
   msnprintf(ptr, 7, ":%u", port);
 }
 
index f9324852043f851aebc61b504fb6992afd2e46ed..7f49e78687ae79a280d43b302a0a2f89b06eb855 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "strcase.h"
 
-static char raw_tolower(char in);
-
 /* Mapping table to go from lowercase to uppercase for plain ASCII.*/
 static const unsigned char touppermap[256] = {
 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
@@ -79,7 +77,7 @@ char Curl_raw_toupper(char in)
 
 /* Portable, consistent tolower. Do not use tolower() because its behavior is
    altered by the current locale. */
-static char raw_tolower(char in)
+char Curl_raw_tolower(char in)
 {
   return tolowermap[(unsigned char) in];
 }
@@ -165,7 +163,7 @@ void Curl_strntolower(char *dest, const char *src, size_t n)
     return;
 
   do {
-    *dest++ = raw_tolower(*src);
+    *dest++ = Curl_raw_tolower(*src);
   } while(*src++ && --n);
 }
 
index d245929227ec4a5a203133702492aea93cdb969f..8ebd42a07edfefdd5507d85b7c5e53452a9e2a9c 100644 (file)
@@ -43,6 +43,7 @@ int Curl_safe_strcasecompare(const char *first, const char *second);
 int Curl_strncasecompare(const char *first, const char *second, size_t max);
 
 char Curl_raw_toupper(char in);
+char Curl_raw_tolower(char in);
 
 /* checkprefix() is a shorter version of the above, used when the first
    argument is the string literal */
index 3d98423fb63a7f3cfcab01de5211beaa52b1e7e8..e3d963ee5c6ac8f51d95cac30f8e57d0eb8493a2 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -2376,7 +2376,7 @@ static char *detect_proxy(struct Curl_easy *data,
 
   /* Now, build <protocol>_proxy and check for such a one to use */
   while(*protop)
-    *envp++ = (char)tolower((int)*protop++);
+    *envp++ = Curl_raw_tolower(*protop++);
 
   /* append _proxy */
   strcpy(envp, "_proxy");
index 1e8046b741754cc7a997752f1527b7d6d915e352..0e07d0ba3eef5b8980acc6b4b8f7a5299e0625a7 100644 (file)
@@ -260,7 +260,7 @@ bool Curl_is_absolute_url(const char *url, char *buf, size_t buflen)
     if(buf) {
       buf[i] = 0;
       while(i--) {
-        buf[i] = (char)TOLOWER(url[i]);
+        buf[i] = Curl_raw_tolower(url[i]);
       }
     }
     return TRUE;
@@ -1664,8 +1664,8 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
         /* make sure percent encoded are lower case */
         if((*p == '%') && ISXDIGIT(p[1]) && ISXDIGIT(p[2]) &&
            (ISUPPER(p[1]) || ISUPPER(p[2]))) {
-          p[1] = (char)TOLOWER(p[1]);
-          p[2] = (char)TOLOWER(p[2]);
+          p[1] = Curl_raw_tolower(p[1]);
+          p[2] = Curl_raw_tolower(p[2]);
           p += 3;
         }
         else
index d5661b0976bcef7182e077d1b0e8d07ebb009d54..0cfcbe87dac8ccb50bfb294f9c62b2937e3d29ff 100644 (file)
@@ -45,6 +45,7 @@
 #include <curl/curl.h>
 #include "urldata.h"
 #include "strcase.h"
+#include "curl_ctype.h"
 #include "hostcheck.h"
 #include "vtls/vtls.h"
 #include "sendf.h"
@@ -716,7 +717,7 @@ static ssize_t encodeDN(char *buf, size_t buflen, struct Curl_asn1Element *dn)
       /* Encode delimiter.
          If attribute has a short uppercase name, delimiter is ", ". */
       if(l) {
-        for(p3 = str; isupper(*p3); p3++)
+        for(p3 = str; ISUPPER(*p3); p3++)
           ;
         for(p3 = (*p3 || p3 - str > 2)? "/": ", "; *p3; p3++) {
           if(l < buflen)
index 5ff86c7f5bb5576eb0e492e281e1585cc36ce3ef..764e1f73cefc9ca19c35018d8febd3a2d885d33f 100644 (file)
@@ -281,7 +281,7 @@ static char *c_escape(const char *str, curl_off_t len)
       strcpy(e, "\\?");
       e += 2;
     }
-    else if(!isprint(c)) {
+    else if(!ISPRINT(c)) {
       msnprintf(e, 5, "\\x%02x", (unsigned)c);
       e += 4;
     }
index 10f99d97b0aefcfbbf9b2c6e3fd7e0f3450cc262..c97c5a71fb722895a61079ca7eaa6a9241d91be3 100644 (file)
@@ -88,6 +88,8 @@
 #include <pwd.h>
 #endif
 
+#include <ctype.h>
+
 #define ENABLE_CURLX_PRINTF
 /* make the curlx header define all printf() functions to use the curlx_*
    versions instead */