LibC: Add is*() functions to libc

This commit is contained in:
Bananymous 2023-01-16 19:13:11 +02:00
parent 5122d27f89
commit fd16c1cf58
3 changed files with 88 additions and 0 deletions

View File

@ -31,6 +31,7 @@ BUILDDIR=$(abspath build)
FREEOBJS=\
$(ARCH_FREEOBJS) \
ctype.o \
stdio/printf.o \
stdio/putchar.o \
stdio/puts.o \

66
libc/ctype.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <ctype.h>
int isalnum(int c)
{
return isdigit(c) || isalpha(c);
}
int isalpha(int c)
{
return islower(c) || isupper(c);
}
int isascii(int c)
{
return c <= 0x7F;
}
int isblank(int c)
{
return c == ' ' || c == '\t';
}
int iscntrl(int c)
{
return c < 32 || c == 0x7F;
}
int isdigit(int c)
{
return '0' <= c && c <= '9';
}
int isgraph(int c)
{
return 0x21 <= c && c <= 0x7E;
}
int islower(int c)
{
return 'a' <= c && c <= 'z';
}
int isprint(int c)
{
return isgraph(c) || c == ' ';
}
int ispunct(int c)
{
return isgraph(c) && !isalnum(c);
}
int isspace(int c)
{
return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v';
}
int isupper(int c)
{
return 'A' <= c && c <= 'Z';
}
int isxdigit(int c)
{
return isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F');
}

21
libc/include/ctype.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include <sys/cdefs.h>
__BEGIN_DECLS
int isalnum(int);
int isalpha(int);
int isascii(int);
int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
__END_DECLS