Skip to content

Commit

Permalink
libutils: isoc: implement more ctypes functions
Browse files Browse the repository at this point in the history
Implement missing functions from ctypes.h.

Signed-off-by: Yunjong Jeong <[email protected]>
Acked-by: Jerome Forissier <[email protected]>
  • Loading branch information
blukat29 authored and jforissier committed Feb 22, 2019
1 parent 1fcac77 commit 9c7ce04
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/libutils/isoc/isalnum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_isalnum(int c)
{
return isalpha(c) || isdigit(c);
}
12 changes: 12 additions & 0 deletions lib/libutils/isoc/iscntrl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_iscntrl(int c)
{
if (c < 0x20 || c == 0x7f)
return 1;
return 0;
}
12 changes: 12 additions & 0 deletions lib/libutils/isoc/isgraph.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_isgraph(int c)
{
if (c >= 0x21 && c < 0x7f)
return 1;
return 0;
}
10 changes: 10 additions & 0 deletions lib/libutils/isoc/islower.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_islower(int c)
{
return (c >= 'a' && c <= 'z');
}
12 changes: 12 additions & 0 deletions lib/libutils/isoc/isprint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_isprint(int c)
{
if (c >= 0x20 && c < 0x7f)
return 1;
return 0;
}
10 changes: 10 additions & 0 deletions lib/libutils/isoc/ispunct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_ispunct(int c)
{
return isgraph(c) && !isalnum(c);
}
7 changes: 7 additions & 0 deletions lib/libutils/isoc/sub.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ srcs-y += tolower.c
srcs-y += isalpha.c
srcs-y += isspace.c
srcs-y += isupper.c
srcs-y += isalnum.c
srcs-y += iscntrl.c
srcs-y += isgraph.c
srcs-y += islower.c
srcs-y += isprint.c
srcs-y += ispunct.c
srcs-y += toupper.c

subdirs-y += newlib
subdirs-$(arch_arm) += arch/$(ARCH)
12 changes: 12 additions & 0 deletions lib/libutils/isoc/toupper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2019, KAIST
*/
#include <ctype.h>

int __builtin_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return c - 'a' + 'A';
return c;
}

0 comments on commit 9c7ce04

Please sign in to comment.