summaryrefslogtreecommitdiff
path: root/lib/libc/ctype
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
commitfc00c656c96528112d05cf0edf8631bd5eaea446 (patch)
treea6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/ctype
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/ctype')
-rw-r--r--lib/libc/ctype/isalnum.c12
-rw-r--r--lib/libc/ctype/isalpha.c8
-rw-r--r--lib/libc/ctype/isblank.c8
-rw-r--r--lib/libc/ctype/iscntrl.c8
-rw-r--r--lib/libc/ctype/isdigit.c8
-rw-r--r--lib/libc/ctype/isgraph.c8
-rw-r--r--lib/libc/ctype/islower.c8
-rw-r--r--lib/libc/ctype/isprint.c8
-rw-r--r--lib/libc/ctype/ispunct.c12
-rw-r--r--lib/libc/ctype/isspace.c8
-rw-r--r--lib/libc/ctype/isupper.c8
-rw-r--r--lib/libc/ctype/isxdigit.c6
-rw-r--r--lib/libc/ctype/tolower.c14
-rw-r--r--lib/libc/ctype/toupper.c14
14 files changed, 130 insertions, 0 deletions
diff --git a/lib/libc/ctype/isalnum.c b/lib/libc/ctype/isalnum.c
new file mode 100644
index 00000000..04e94fc6
--- /dev/null
+++ b/lib/libc/ctype/isalnum.c
@@ -0,0 +1,12 @@
+#include <libc.h>
+#include <ctype.h>
+
+int isalnum(int c)
+{
+ return isalpha(c) || isdigit(c);
+}
+
+weak int isalnum_l(int c, locale_t unused locale)
+{
+ return isalnum(c);
+}
diff --git a/lib/libc/ctype/isalpha.c b/lib/libc/ctype/isalpha.c
new file mode 100644
index 00000000..d046c09e
--- /dev/null
+++ b/lib/libc/ctype/isalpha.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isalpha(int c)
+{
+ return ((unsigned)c | 32) - 'a' < 26;
+}
+
+weak_reference(isalpha, isalpha_l);
diff --git a/lib/libc/ctype/isblank.c b/lib/libc/ctype/isblank.c
new file mode 100644
index 00000000..7ad08709
--- /dev/null
+++ b/lib/libc/ctype/isblank.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isblank(int c)
+{
+ return (c == ' ' || c == '\t');
+}
+
+weak_reference(isblank, isblank_l);
diff --git a/lib/libc/ctype/iscntrl.c b/lib/libc/ctype/iscntrl.c
new file mode 100644
index 00000000..6d4ff5a8
--- /dev/null
+++ b/lib/libc/ctype/iscntrl.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int iscntrl(int c)
+{
+ return (unsigned)c < 0x20 || c == 0x7f;
+}
+
+weak_reference(iscntrl, iscntrl_l);
diff --git a/lib/libc/ctype/isdigit.c b/lib/libc/ctype/isdigit.c
new file mode 100644
index 00000000..445e1cdc
--- /dev/null
+++ b/lib/libc/ctype/isdigit.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isdigit(int c)
+{
+ return (unsigned)c - '0' < 10;
+}
+
+weak_reference(isdigit, isdigit_l);
diff --git a/lib/libc/ctype/isgraph.c b/lib/libc/ctype/isgraph.c
new file mode 100644
index 00000000..03919200
--- /dev/null
+++ b/lib/libc/ctype/isgraph.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isgraph(int c)
+{
+ return (unsigned)c - 0x21 < 0x5e;
+}
+
+weak_reference(isgraph, isgraph_l);
diff --git a/lib/libc/ctype/islower.c b/lib/libc/ctype/islower.c
new file mode 100644
index 00000000..34980da6
--- /dev/null
+++ b/lib/libc/ctype/islower.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int islower(int c)
+{
+ return (unsigned)c - 'a' < 26;
+}
+
+weak_reference(islower, islower_l);
diff --git a/lib/libc/ctype/isprint.c b/lib/libc/ctype/isprint.c
new file mode 100644
index 00000000..76524050
--- /dev/null
+++ b/lib/libc/ctype/isprint.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isprint(int c)
+{
+ return (unsigned)c - 0x20 < 0x5f;
+}
+
+weak_reference(isprint, isprint_l);
diff --git a/lib/libc/ctype/ispunct.c b/lib/libc/ctype/ispunct.c
new file mode 100644
index 00000000..2bd08c38
--- /dev/null
+++ b/lib/libc/ctype/ispunct.c
@@ -0,0 +1,12 @@
+#include <libc.h>
+#include <ctype.h>
+
+int ispunct(int c)
+{
+ return isgraph(c) && !isalnum(c);
+}
+
+weak int ispunct_l(int c, locale_t locale)
+{
+ return ispunct(c);
+}
diff --git a/lib/libc/ctype/isspace.c b/lib/libc/ctype/isspace.c
new file mode 100644
index 00000000..86630c66
--- /dev/null
+++ b/lib/libc/ctype/isspace.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isspace(int c)
+{
+ return c == ' ' || (unsigned)c - '\t' < 5;
+}
+
+weak_reference(isspace, isspace_l);
diff --git a/lib/libc/ctype/isupper.c b/lib/libc/ctype/isupper.c
new file mode 100644
index 00000000..458990df
--- /dev/null
+++ b/lib/libc/ctype/isupper.c
@@ -0,0 +1,8 @@
+#include <libc.h>
+
+int isupper(int c)
+{
+ return (unsigned)c - 'A' < 26;
+}
+
+weak_reference(isupper, isupper_l);
diff --git a/lib/libc/ctype/isxdigit.c b/lib/libc/ctype/isxdigit.c
new file mode 100644
index 00000000..588df77a
--- /dev/null
+++ b/lib/libc/ctype/isxdigit.c
@@ -0,0 +1,6 @@
+#include <ctype.h>
+
+int isxdigit(int c)
+{
+ return isdigit(c) || ((unsigned)c | 32) - 'a' < 6;
+}
diff --git a/lib/libc/ctype/tolower.c b/lib/libc/ctype/tolower.c
new file mode 100644
index 00000000..abeab42a
--- /dev/null
+++ b/lib/libc/ctype/tolower.c
@@ -0,0 +1,14 @@
+#include <libc.h>
+#include <ctype.h>
+
+int tolower(int c)
+{
+ if (isupper(c))
+ return c | 32;
+ return c;
+}
+
+weak int tolower_l(int c, locale_t unused locale)
+{
+ return tolower(c);
+}
diff --git a/lib/libc/ctype/toupper.c b/lib/libc/ctype/toupper.c
new file mode 100644
index 00000000..e952acd9
--- /dev/null
+++ b/lib/libc/ctype/toupper.c
@@ -0,0 +1,14 @@
+#include <libc.h>
+#include <ctype.h>
+
+int toupper(int c)
+{
+ if (islower(c))
+ return c & 0x5f;
+ return c;
+}
+
+int toupper_l(int c, locale_t unused locale)
+{
+ return toupper(c);
+}