summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-28 21:10:57 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-28 21:10:57 -0500
commit08d8fd2767733d893380ebf5c8a4743dd371528d (patch)
treeb3aff9fe38cd3cd94d99ca51b76e3de0f34037f2
parentb4409255ad7f446ad0a3386dc3669bbf270bb327 (diff)
fix ctype functions in the C/POSIX locale
-rw-r--r--src/ctype/iscntrl.c2
-rw-r--r--src/ctype/isgraph.c2
-rw-r--r--src/ctype/isprint.c2
-rw-r--r--src/ctype/tolower.c5
-rw-r--r--src/ctype/toupper.c6
-rw-r--r--src/nonstd/_locale.h6
m---------test0
7 files changed, 17 insertions, 6 deletions
diff --git a/src/ctype/iscntrl.c b/src/ctype/iscntrl.c
index eead7f5f..9d295d26 100644
--- a/src/ctype/iscntrl.c
+++ b/src/ctype/iscntrl.c
@@ -14,7 +14,7 @@ int iscntrl(int c)
RETURN(0, ARGUMENT(c) is not a control character);
*/
- return map[c] == 0 || (map[c] == CT_SPACE && c != ' ');
+ return map[c] & CT_CNTRL;
}
/***
diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c
index 206a09b7..ecf88a34 100644
--- a/src/ctype/isgraph.c
+++ b/src/ctype/isgraph.c
@@ -14,7 +14,7 @@ int isgraph(int c)
RETURN(0, ARGUMENT(c) is not a graphic character);
*/
- return map[c] & ~CT_SPACE;
+ return map[c] & CT_GRAPH;
}
/***
diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c
index 19847118..41ed6bcf 100644
--- a/src/ctype/isprint.c
+++ b/src/ctype/isprint.c
@@ -14,7 +14,7 @@ int isprint(int c)
RETURN(0, ARGUMENT(c) is not a printable character);
*/
- return map[c] & ~CT_SPACE || c == ' ';
+ return map[c] & CT_PRINT;
}
/***
diff --git a/src/ctype/tolower.c b/src/ctype/tolower.c
index 793de6bb..7ef5057a 100644
--- a/src/ctype/tolower.c
+++ b/src/ctype/tolower.c
@@ -1,4 +1,5 @@
#include <ctype.h>
+#include "stdio.h"
#include "limits.h"
#include "nonstd/assert.h"
#include "nonstd/ctype.h"
@@ -14,6 +15,10 @@ int tolower(int c)
RETURN_FAILURE(ARGUMENT(c), ARGUMENT(c) was not an uppercase letter or it has no equivalent lowercase letter);
*/
+ if (c == EOF) {
+ return EOF;
+ }
+
return map[c];
}
diff --git a/src/ctype/toupper.c b/src/ctype/toupper.c
index 35b7c9e2..4844a702 100644
--- a/src/ctype/toupper.c
+++ b/src/ctype/toupper.c
@@ -1,4 +1,5 @@
#include <ctype.h>
+#include "stdio.h"
#include "limits.h"
#include "nonstd/assert.h"
#include "nonstd/ctype.h"
@@ -13,6 +14,11 @@ int toupper(int c)
RETURN_SUCCESS(ARGUMENT(c) converted to uppercase);
RETURN_FAILURE(ARGUMENT(c), ARGUMENT(c) was not a lowercase letter or it has no equivalent upercase letter);
*/
+
+ if (c == EOF) {
+ return EOF;
+ }
+
return map[c];
}
diff --git a/src/nonstd/_locale.h b/src/nonstd/_locale.h
index 036fd836..79904e1f 100644
--- a/src/nonstd/_locale.h
+++ b/src/nonstd/_locale.h
@@ -18,7 +18,7 @@
#define setall(_map, _input, _mask) do { \
size_t _i; \
- for (_i = 0; _i < sizeof(_input); _i++) { \
+ for (_i = 0; _i < sizeof(_input) - 1; _i++) { \
_map[(int)_input[_i]] |= _mask; \
} \
} while (0)
@@ -61,7 +61,7 @@ static char * (__load_locale)(struct __locale_t *loc, int mask, const char *name
char blank[] = " \t";
size_t i;
- memset(loc->lc_ctype.ctattr, 0, CHAR_MAX);
+ memset(loc->lc_ctype.ctattr, 0, sizeof(loc->lc_ctype.ctattr));
for (i = 0; i < 32; i++) {
loc->lc_ctype.ctattr[i] = CT_CNTRL;
@@ -89,7 +89,7 @@ static char * (__load_locale)(struct __locale_t *loc, int mask, const char *name
loc->lc_ctype.ctattr[' '] |= CT_PRINT;
- for (i = 0; i < CHAR_MAX; i++) {
+ for (i = 0; i < UCHAR_MAX; i++) {
loc->lc_ctype.ctoupper[i] = i;
loc->lc_ctype.ctolower[i] = i;
}
diff --git a/test b/test
-Subproject 0055f0fed6b87296d668b13256100b2885728cb
+Subproject a9803100f1a3925d1e79d2dd7ddd2630edcca3b