1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

libreplace: Introduce hexchars_{upper|lower}

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>
This commit is contained in:
Volker Lendecke 2024-09-10 08:45:31 +02:00 committed by Ralph Boehme
parent 72ff0312d1
commit fd5562bee7
4 changed files with 14 additions and 11 deletions

View 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);

View 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";

View 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>

View 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--;
}