summaryrefslogtreecommitdiff
path: root/epan/strutil.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-10-17 16:10:53 -0700
committerGuy Harris <guy@alum.mit.edu>2014-10-17 23:11:18 +0000
commit033f096ee909b63c0692b80416797f743940d054 (patch)
tree0ec827ec1bfa5a7893c19e81f27d782797a66644 /epan/strutil.c
parent344c2bbb5e2a23764fe21adeaf2439d267960a96 (diff)
downloadwireshark-033f096ee909b63c0692b80416797f743940d054.tar.gz
Don't use ctype.h routines.
That avoids locale dependency and handles possibly-signed chars (which we weren't always doing before). Change-Id: Ieceb93029252f646397b6488f2df8a57c6d2a23d Reviewed-on: https://code.wireshark.org/review/4794 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/strutil.c')
-rw-r--r--epan/strutil.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/epan/strutil.c b/epan/strutil.c
index de52320568..53c646036d 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
#include <glib.h>
#include "strutil.h"
#include "emem.h"
@@ -293,7 +292,7 @@ format_text_wsp(const guchar *string, size_t len)
if (g_ascii_isprint(c)) {
fmtbuf[idx][column] = c;
column++;
- } else if (isspace(c)) {
+ } else if (g_ascii_isspace(c)) {
fmtbuf[idx][column] = ' ';
column++;
} else {
@@ -404,7 +403,7 @@ format_text_chr(const guchar *string, const size_t len, const guchar chr)
fmtbuf[idx][column] = c;
column++;
}
- else if (isspace(c))
+ else if (g_ascii_isspace(c))
{
fmtbuf[idx][column] = ' ';
column++;
@@ -432,7 +431,7 @@ gboolean
hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separators)
{
guint8 val;
- const guchar *p, *q, *r, *s, *punct;
+ const gchar *p, *q, *r, *s, *punct;
char four_digits_first_half[3];
char four_digits_second_half[3];
char two_digits[3];
@@ -442,15 +441,15 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separato
return FALSE;
}
g_byte_array_set_size(bytes, 0);
- p = (const guchar *)hex_str;
+ p = hex_str;
while (*p) {
q = p+1;
r = p+2;
s = p+3;
if (*q && *r && *s
- && isxdigit(*p) && isxdigit(*q) &&
- isxdigit(*r) && isxdigit(*s)) {
+ && g_ascii_isxdigit(*p) && g_ascii_isxdigit(*q) &&
+ g_ascii_isxdigit(*r) && g_ascii_isxdigit(*s)) {
four_digits_first_half[0] = *p;
four_digits_first_half[1] = *q;
four_digits_first_half[2] = '\0';
@@ -486,7 +485,7 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separato
p = punct;
continue;
}
- else if (*q && isxdigit(*p) && isxdigit(*q)) {
+ else if (*q && g_ascii_isxdigit(*p) && g_ascii_isxdigit(*q)) {
two_digits[0] = *p;
two_digits[1] = *q;
two_digits[2] = '\0';
@@ -516,7 +515,7 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separato
p = punct;
continue;
}
- else if (*q && isxdigit(*p) && is_byte_sep(*q)) {
+ else if (*q && g_ascii_isxdigit(*p) && is_byte_sep(*q)) {
one_digit[0] = *p;
one_digit[1] = '\0';
@@ -528,7 +527,7 @@ hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separato
p = q + 1;
continue;
}
- else if (!*q && isxdigit(*p)) {
+ else if (!*q && g_ascii_isxdigit(*p)) {
one_digit[0] = *p;
one_digit[1] = '\0';
@@ -574,7 +573,7 @@ get_valid_byte_sep(gchar c, const guint encoding)
retval = 0;
break;
default:
- if (isxdigit(c) && (encoding & ENC_SEP_NONE))
+ if (g_ascii_isxdigit(c) && (encoding & ENC_SEP_NONE))
retval = 0;
/* anything else means we've got a failure */
break;
@@ -621,7 +620,7 @@ hex_str_to_bytes_encoding(const gchar *hex_str, GByteArray *bytes, const gchar *
};
/* we must see two hex chars at the beginning, or fail */
- if (bytes && *end && isxdigit(*end) && isxdigit(*(end+1))) {
+ if (bytes && *end && g_ascii_isxdigit(*end) && g_ascii_isxdigit(*(end+1))) {
retval = TRUE;
/* set the separator character we'll allow; if this returns a -1, it means something's
@@ -682,15 +681,15 @@ gboolean
uri_str_to_bytes(const char *uri_str, GByteArray *bytes)
{
guint8 val;
- const guchar *p;
- guchar hex_digit[HEX_DIGIT_BUF_LEN];
+ const gchar *p;
+ gchar hex_digit[HEX_DIGIT_BUF_LEN];
g_byte_array_set_size(bytes, 0);
if (! uri_str) {
return FALSE;
}
- p = (const guchar *)uri_str;
+ p = uri_str;
while (*p) {
if (!g_ascii_isprint(*p))
@@ -703,9 +702,9 @@ uri_str_to_bytes(const char *uri_str, GByteArray *bytes)
if (*p == '\0') return FALSE;
hex_digit[1] = *p;
hex_digit[2] = '\0';
- if (! isxdigit(hex_digit[0]) || ! isxdigit(hex_digit[1]))
+ if (! g_ascii_isxdigit(hex_digit[0]) || ! g_ascii_isxdigit(hex_digit[1]))
return FALSE;
- val = (guint8) strtoul((char *)hex_digit, NULL, 16);
+ val = (guint8) strtoul(hex_digit, NULL, 16);
g_byte_array_append(bytes, &val, 1);
} else {
g_byte_array_append(bytes, (const guint8 *) p, 1);
@@ -826,7 +825,7 @@ rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, gboolean is_absolut
p = oid_str;
dot = NULL;
while (*p) {
- if (!isdigit((guchar)*p) && (*p != '.')) return FALSE;
+ if (!g_ascii_isdigit(*p) && (*p != '.')) return FALSE;
if (*p == '.') {
if (p == oid_str && is_absolute) return FALSE;
if (!*(p+1)) return FALSE;
@@ -843,7 +842,7 @@ rel_oid_str_to_bytes(const char *oid_str, GByteArray *bytes, gboolean is_absolut
subid0 = 0; /* squelch GCC complaints */
while (*p) {
subid = 0;
- while (isdigit((guchar)*p)) {
+ while (g_ascii_isdigit(*p)) {
subid *= 10;
subid += *p - '0';
p++;
@@ -977,7 +976,7 @@ convert_string_to_hex(const char *string, size_t *nbytes)
{
size_t n_bytes;
const char *p;
- guchar c;
+ gchar c;
guint8 *bytes, *q, byte_val;
n_bytes = 0;
@@ -986,11 +985,11 @@ convert_string_to_hex(const char *string, size_t *nbytes)
c = *p++;
if (c == '\0')
break;
- if (isspace(c))
+ if (g_ascii_isspace(c))
continue; /* allow white space */
if (c==':' || c=='.' || c=='-')
continue; /* skip any ':', '.', or '-' between bytes */
- if (!isxdigit(c)) {
+ if (!g_ascii_isxdigit(c)) {
/* Not a valid hex digit - fail */
return NULL;
}
@@ -1000,7 +999,7 @@ convert_string_to_hex(const char *string, size_t *nbytes)
* hex digit immediately after that hex digit.
*/
c = *p++;
- if (!isxdigit(c))
+ if (!g_ascii_isxdigit(c))
return NULL;
/* 2 hex digits = 1 byte */
@@ -1026,7 +1025,7 @@ convert_string_to_hex(const char *string, size_t *nbytes)
c = *p++;
if (c == '\0')
break;
- if (isspace(c))
+ if (g_ascii_isspace(c))
continue; /* allow white space */
if (c==':' || c=='.' || c=='-')
continue; /* skip any ':', '.', or '-' between bytes */