]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libreplace: Introduce hexchars_{upper|lower}
authorVolker Lendecke <vl@samba.org>
Tue, 10 Sep 2024 06:45:31 +0000 (08:45 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 12 Nov 2024 12:09:35 +0000 (12:09 +0000)
We use that in quite a few places in our code.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/replace/inet_pton.c
lib/replace/replace.c
lib/replace/replace.h
lib/replace/snprintf.c

index 80e4865ef494cdfaf6bdf81e822c23b56a1fe4e1..9e461d770abb3f6dd9da83eb2b44d671b4498eb5 100644 (file)
@@ -131,8 +131,6 @@ inet_pton6(src, dst)
        const char *src;
        unsigned char *dst;
 {
-       static const char xdigits_l[] = "0123456789abcdef",
-                         xdigits_u[] = "0123456789ABCDEF";
        unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
        const char *xdigits, *curtok;
        int ch, saw_xdigit;
@@ -151,8 +149,8 @@ inet_pton6(src, dst)
        while ((ch = *src++) != '\0') {
                const char *pch;
 
-               if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
-                       pch = strchr((xdigits = xdigits_u), ch);
+               if ((pch = strchr((xdigits = hexchars_lower), ch)) == NULL)
+                       pch = strchr((xdigits = hexchars_upper), ch);
                if (pch != NULL) {
                        val <<= 4;
                        val |= (pch - xdigits);
index 68e0a38bca6171d2bc3dee3240927cdcd652e8f5..f7f26712614c18813f922a485e164fc5cd28a8dc 100644 (file)
@@ -1231,3 +1231,6 @@ int rep_renameat2(int __oldfd, const char *__old, int __newfd,
        return renameat(__oldfd, __old, __newfd, __new);
 }
 #endif /* ! HAVE_RENAMEAT2 */
+
+const char hexchars_lower[] = "0123456789abcdef";
+const char hexchars_upper[] = "0123456789ABCDEF";
index 586f4e0a5751f7eade6555a02310610cf0ee5a8a..b4bc1327824597cf3fa84a22c315564c3bbc3cca 100644 (file)
@@ -1101,6 +1101,9 @@ static inline bool hex_byte(const char *in, uint8_t *out)
        return ok;
 }
 
+extern const char hexchars_lower[];
+extern const char hexchars_upper[];
+
 /* Needed for Solaris atomic_add_XX functions. */
 #if defined(HAVE_SYS_ATOMIC_H)
 #include <sys/atomic.h>
index dd878fca113f71871a99de7fabbe03130ec88f93..63b0882e33f16e22f3dfbf8e378ececbcbfd8b5a 100644 (file)
@@ -832,9 +832,8 @@ static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
        if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
 
        do {
-               convert[place++] =
-                       (caps? "0123456789ABCDEF":"0123456789abcdef")
-                       [uvalue % (unsigned)base  ];
+               convert[place++] = (caps ? hex_upper
+                                        : hex_lower)[uvalue % (unsigned)base];
                uvalue = (uvalue / (unsigned)base );
        } while(uvalue && (place < sizeof(convert)));
        if (place == sizeof(convert)) place--;
@@ -1028,8 +1027,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
                idx = (int) ((temp -intpart +0.05)* 10.0);
                /* idx = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */
                /* printf ("%llf, %f, %x\n", temp, intpart, idx); */
-               iconvert[iplace++] =
-                       (caps? "0123456789ABCDEF":"0123456789abcdef")[idx];
+               iconvert[iplace++] = (caps ? hexchars_upper
+                                          : hexchars_lower)[idx];
        } while (intpart && (iplace < 311));
        if (iplace == 311) iplace--;
        iconvert[iplace] = 0;
@@ -1043,8 +1042,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
                        idx = (int) ((temp -fracpart +0.05)* 10.0);
                        /* idx = (int) ((((temp/10) -fracpart) +0.05) *10); */
                        /* printf ("%lf, %lf, %ld\n", temp, fracpart, idx ); */
-                       fconvert[fplace++] =
-                       (caps? "0123456789ABCDEF":"0123456789abcdef")[idx];
+                       fconvert[fplace++] = (caps ? hexchars_upper
+                                                  : hexchars_lower)[idx];
                } while(fracpart && (fplace < 311));
                if (fplace == 311) fplace--;
        }