Commit e3db58ad authored by Daniel Salzman's avatar Daniel Salzman Committed by Mark Karpilovskij

Switch to locale-independent ctype functions

parent 1af57f28
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,9 +15,9 @@
*/
#include <stdio.h>
#include <ctype.h>
#include "contrib/print.h"
#include "contrib/ctype.h"
typedef int (*printf_t)(const char *fmt, ...);
......@@ -29,7 +29,7 @@ static void array_printf(const uint8_t *data, const unsigned length,
switch (type) {
case 't':
if (isprint(ch) != 0) {
if (is_print(ch)) {
print_handler("%c ", ch);
} else {
print_handler(" ");
......
......@@ -14,13 +14,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contrib/string.h"
#include "contrib/ctype.h"
uint8_t *memdup(const uint8_t *data, size_t data_size)
{
......@@ -71,13 +71,13 @@ char *strstrip(const char *str)
{
// leading white-spaces
const char *scan = str;
while (isspace((unsigned char)scan[0])) {
while (is_space(scan[0])) {
scan += 1;
}
// trailing white-spaces
size_t len = strlen(scan);
while (len > 0 && isspace((unsigned char)scan[len - 1])) {
while (len > 0 && is_space(scan[len - 1])) {
len -= 1;
}
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -20,13 +20,13 @@
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <ctype.h>
#include "libknot/errcode.h"
#include "contrib/ctype.h"
inline static int intmax_from_str(const char *src, intmax_t *dest)
{
if (!isdigit((unsigned char)*src) && *src != '-' && *src != '+') {
if (!is_digit(*src) && *src != '-' && *src != '+') {
return KNOT_EINVAL;
}
......@@ -48,7 +48,7 @@ inline static int intmax_from_str(const char *src, intmax_t *dest)
inline static int uintmax_from_str(const char *src, uintmax_t *dest)
{
if (!isdigit((unsigned char)*src) && *src != '+') {
if (!is_digit(*src) && *src != '+') {
return KNOT_EINVAL;
}
......
......@@ -15,7 +15,6 @@
*/
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
......@@ -23,6 +22,7 @@
#include <string.h>
#include "contrib/time.h"
#include "contrib/ctype.h"
#ifndef HAVE_CLOCK_GETTIME
#include <sys/time.h>
#endif
......@@ -168,7 +168,7 @@ static void parse_offset(time_ctx_t *ctx)
{
ctx->offset = 0;
ctx->error = -1;
while (isdigit((unsigned char)*ctx->parsed)) {
while (is_digit(*ctx->parsed)) {
ctx->offset *= 10;
ctx->offset += *ctx->parsed++ - '0';
ctx->error = 0;
......@@ -180,7 +180,7 @@ static void parse_calendar(time_ctx_t *ctx, int index)
int *cal_arr = (int *)&ctx->calendar;
cal_arr[index] = 0;
for (size_t i = 0; i < calendar_digits(index); i++) {
if (!isdigit((unsigned char)*ctx->parsed)) {
if (!is_digit(*ctx->parsed)) {
ctx->error = -1;
return;
}
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,13 +15,15 @@
*/
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "error.h"
#include "keyid.h"
#include "shared.h"
#include "../contrib/ctype.h"
#include "../contrib/tolower.h"
/* -- public API ----------------------------------------------------------- */
_public_
......@@ -36,7 +38,7 @@ bool dnssec_keyid_is_valid(const char *id)
}
for (int i = 0; i < DNSSEC_KEYID_SIZE; i++) {
if (!isxdigit((unsigned char)id[i])) {
if (!is_xdigit(id[i])) {
return false;
}
}
......@@ -52,8 +54,8 @@ void dnssec_keyid_normalize(char *id)
}
for (size_t i = 0; i < DNSSEC_KEYID_SIZE; i++) {
assert(id[i] != '\0' && isxdigit((unsigned char)id[i]));
id[i] = tolower((unsigned char)id[i]);
assert(id[i] != '\0' && is_xdigit(id[i]));
id[i] = knot_tolower(id[i]);
}
}
......
......@@ -15,13 +15,13 @@
*/
#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "dname.h"
#include "shared.h"
#include "../contrib/tolower.h"
/*!
* Get length of a domain name in wire format.
......@@ -86,7 +86,7 @@ static uint8_t normalize_label(uint8_t *label)
}
for (uint8_t *scan = label + 1, *end = scan + len; scan < end; scan++) {
*scan = tolower(*scan);
*scan = knot_tolower(*scan);
}
return len + 1;
......@@ -117,7 +117,7 @@ static int label_casecmp(const uint8_t *a, const uint8_t *b, uint8_t len)
assert(b);
for (const uint8_t *a_end = a + len; a < a_end; a++, b++) {
if (tolower(*a) != tolower(*b)) {
if (knot_tolower(*a) != knot_tolower(*b)) {
return false;
}
}
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,13 +15,14 @@
*/
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include "binary.h"
#include "error.h"
#include "../contrib/ctype.h"
/* -- binary to hex -------------------------------------------------------- */
static const char BIN_TO_HEX[] = { '0', '1', '2', '3', '4', '5', '6', '7',
......@@ -95,7 +96,7 @@ static bool hex_valid_input(const dnssec_binary_t *hex)
}
for (int i = 0; i < hex->size; i++) {
if (!isxdigit(hex->data[i])) {
if (!is_xdigit(hex->data[i])) {
return false;
}
}
......
......@@ -15,7 +15,6 @@
*/
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
......@@ -26,6 +25,7 @@
#include "libknot/dname.h"
#include "libknot/errcode.h"
#include "libknot/packet/wire.h"
#include "contrib/ctype.h"
#include "contrib/mempattern.h"
#include "contrib/tolower.h"
......@@ -250,10 +250,10 @@ char *knot_dname_to_str(char *dst, const knot_dname_t *name, size_t maxlen)
continue;
}
if (isalnum(c) != 0 || c == '-' || c == '_' || c == '*' ||
if (is_alnum(c) || c == '-' || c == '_' || c == '*' ||
c == '/') {
res[str_len++] = c;
} else if (ispunct(c) != 0 && c != '#') {
} else if (is_punct(c) && c != '#') {
/* Exclusion of '#' character is to avoid possible
* collision with rdata hex notation '\#'. So it is
* encoded in \ddd notation.
......@@ -398,11 +398,11 @@ knot_dname_t *knot_dname_from_str(uint8_t *dst, const char *name, size_t maxlen)
}
/* Check for \DDD notation. */
if (isdigit(*ch) != 0) {
if (is_digit(*ch)) {
/* Check for next two digits. */
if (ch + 2 >= end ||
isdigit(*(ch + 1)) == 0 ||
isdigit(*(ch + 2)) == 0) {
!is_digit(*(ch + 1)) ||
!is_digit(*(ch + 2))) {
goto dname_from_str_failed;
}
......
......@@ -15,7 +15,6 @@
*/
#include <arpa/inet.h>
#include <ctype.h>
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
......@@ -36,6 +35,7 @@
#include "libknot/lookup.h"
#include "contrib/base32hex.h"
#include "contrib/base64.h"
#include "contrib/ctype.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
......@@ -609,7 +609,7 @@ static void wire_text_to_str(rrset_dump_params_t *p, bool quote, bool with_heade
for (size_t i = 0; i < in_len; i++) {
uint8_t ch = p->in[i];
if (isprint(ch) != 0) {
if (is_print(ch)) {
// For special character print leading slash.
if (ch == '\\' || ch == '"') {
dump_string(p, "\\");
......
......@@ -15,7 +15,6 @@
*/
#include <arpa/inet.h>
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
......@@ -26,6 +25,7 @@
#include "libknot/dname.h"
#include "libknot/lookup.h"
#include "contrib/base64.h"
#include "contrib/ctype.h"
#include "contrib/sockaddr.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
......@@ -343,7 +343,7 @@ static uint8_t sock_type_guess(
for (size_t i = 0; i < len; i++) {
if (str[i] == '.') dots++;
else if (str[i] == ':') semicolons++;
else if (isdigit(str[i]) != 0) digits++;
else if (is_digit(str[i])) digits++;
}
// Guess socket type.
......@@ -759,8 +759,8 @@ int yp_hex_to_bin(
uint8_t buf[2] = { 0 };
wire_ctx_read(in, buf, sizeof(buf));
if (isxdigit(buf[0]) == 0 ||
isxdigit(buf[1]) == 0) {
if (!is_xdigit(buf[0]) ||
!is_xdigit(buf[1])) {
return KNOT_EINVAL;
}
......@@ -791,7 +791,7 @@ int yp_hex_to_txt(
// Check for printable string.
for (size_t i = 0; i < len; i++) {
if (isprint(in->position[i]) == 0) {
if (!is_print(in->position[i])) {
printable = false;
break;
}
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,11 +15,12 @@
*/
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "libknot/libknot.h"
#include "contrib/ctype.h"
#include "contrib/tolower.h"
/*!
* \brief Convert HEX char to byte.
......@@ -51,7 +52,7 @@ int hex_decode(const char *input, uint8_t **output, size_t *output_size)
}
for (size_t i = 0; i < input_size; i++) {
if (!isxdigit((unsigned char)input[i])) {
if (!is_xdigit(input[i])) {
return KNOT_EMALF;
}
}
......@@ -68,8 +69,8 @@ int hex_decode(const char *input, uint8_t **output, size_t *output_size)
// conversion
for (size_t i = 0; i < result_size; i++) {
int high_nib = tolower((unsigned char)input[2 * i]);
int low_nib = tolower((unsigned char)input[2 * i + 1]);
int high_nib = knot_tolower(input[2 * i]);
int low_nib = knot_tolower(input[2 * i + 1]);
result[i] = hex_to_num(high_nib) << 4 | hex_to_num(low_nib);
}
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -14,7 +14,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -22,6 +21,7 @@
#include "utils/common/token.h"
#include "utils/common/msg.h"
#include "libknot/libknot.h"
#include "contrib/ctype.h"
int tok_scan(const char* lp, const char **tbl, int *lpm)
{
......@@ -35,7 +35,7 @@ int tok_scan(const char* lp, const char **tbl, int *lpm)
unsigned char len = 0; /* Read length. */
for(;;) {
const char *tok = tbl[i];
if (*lp == '\0' || isspace((unsigned char)(*lp))) {
if (*lp == '\0' || is_space(*lp)) {
if (tok && TOK_L(tok) == len) { /* Consumed whole w? */
return i; /* Identifier */
} else { /* Word is shorter than cmd? */
......@@ -107,7 +107,7 @@ const char *tok_skipspace(const char *lp)
return NULL;
}
while (isspace((unsigned char)(*lp))) {
while (is_space(*lp)) {
lp += 1;
}
......
......@@ -14,9 +14,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <string.h>
#include "contrib/ctype.h"
#include "contrib/strtonum.h"
#include "dnssec/binary.h"
#include "dnssec/error.h"
......@@ -83,7 +83,7 @@ const param_t PRIVKEY_CONVERSION_TABLE[] = {
static int parse_algorithm(char *string, void *_algorithm)
{
char *end = string;
while (*end != '\0' && !isspace((unsigned char)*end)) {
while (*end != '\0' && !is_space(*end)) {
end += 1;
}
*end = '\0';
......@@ -144,12 +144,12 @@ static int parse_time(char *string, void *_time)
static void strip(char **value, size_t *length)
{
// strip from left
while (*length > 0 && isspace((unsigned char)**value)) {
while (*length > 0 && is_space(**value)) {
*value += 1;
*length -= 1;
}
// strip from right
while (*length > 0 && isspace((unsigned char)(*value)[*length - 1])) {
while (*length > 0 && is_space((*value)[*length - 1])) {
*length -= 1;
}
}
......
......@@ -14,23 +14,23 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils/keymgr/functions.h"
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <fcntl.h>
#include "utils/keymgr/functions.h"
#include "utils/keymgr/bind_privkey.h"
#include "contrib/base64.h"
#include "contrib/ctype.h"
#include "contrib/tolower.h"
#include "contrib/wire_ctx.h"
#include "dnssec/lib/dnssec/error.h"
#include "dnssec/shared/shared.h"
#include "knot/dnssec/kasp/policy.h"
#include "knot/dnssec/zone-keys.h"
#include "utils/keymgr/bind_privkey.h"
#include "zscanner/scanner.h"
#include "contrib/base64.h"
static bool is_timestamp(char *arg, knot_kasp_key_timing_t *timing)
{
......@@ -88,7 +88,7 @@ static bool genkeyargs(int argc, char *argv[], bool just_timing,
// parse args
for (int i = 0; i < argc; i++) {
if (!just_timing && strncasecmp(argv[i], "algorithm=", 10) == 0) {
if (isdigit((unsigned char)argv[i][10]) && atol(argv[i] + 10) < 256) {
if (is_digit(argv[i][10]) && atol(argv[i] + 10) < 256) {
*algorithm = atol(argv[i] + 10);
continue;
}
......@@ -105,7 +105,7 @@ static bool genkeyargs(int argc, char *argv[], bool just_timing,
return false;
}
} else if (!just_timing && strncasecmp(argv[i], "ksk=", 4) == 0) {
switch (tolower((unsigned char)argv[i][4])) {
switch (knot_tolower(argv[i][4])) {
case '1':
case 'y':
case 't':
......@@ -500,7 +500,7 @@ static long is_uint32(const char *string)
return -1;
}
for (const char *p = string; *p != '\0'; p++) {
if (!isdigit((unsigned char)*p)) {
if (!is_digit(*p)) {
return -1;
}
}
......@@ -511,7 +511,7 @@ static long is_uint32(const char *string)
static bool is_hex(const char *string)
{
for (const char *p = string; *p != '\0'; p++) {
if (!isxdigit((unsigned char)*p)) {
if (!is_xdigit(*p)) {
return false;
}
}
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -15,14 +15,12 @@
*/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
#include "contrib/getline.h"
#include "dnssec/random.h"
#include "utils/knsupdate/knsupdate_exec.h"
#include "utils/common/exec.h"
......@@ -32,6 +30,8 @@
#include "utils/common/sign.h"
#include "utils/common/token.h"
#include "libknot/libknot.h"
#include "contrib/ctype.h"
#include "contrib/getline.h"
#include "contrib/macros.h"
#include "contrib/string.h"
#include "contrib/strtonum.h"
......@@ -230,7 +230,7 @@ static int parse_partial_rr(zs_scanner_t *s, const char *lp, unsigned flags)
/* Now there could be [ttl] [class] [type [data...]]. */
char *np = NULL;
long ttl = strtol(lp, &np, 10);
if (ttl >= 0 && np && (*np == '\0' || isspace((unsigned char)(*np)))) {
if (ttl >= 0 && np && (*np == '\0' || is_space(*np))) {
DBG("%s: parsed ttl=%lu\n", __func__, ttl);
if (flags & PARSE_NOTTL) {
WARN("ignoring TTL value '%ld'\n", ttl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment