summaryrefslogtreecommitdiff
path: root/include/system
diff options
context:
space:
mode:
Diffstat (limited to 'include/system')
-rw-r--r--include/system/alloca.h6
-rw-r--r--include/system/builtins_begin_.h94
-rw-r--r--include/system/builtins_end_.h28
-rw-r--r--include/system/ctype.h73
-rw-r--r--include/system/stdlib.h12
-rw-r--r--include/system/string.h51
-rw-r--r--include/system/strings.h9
7 files changed, 270 insertions, 3 deletions
diff --git a/include/system/alloca.h b/include/system/alloca.h
index dc11b60d..a9d1aab1 100644
--- a/include/system/alloca.h
+++ b/include/system/alloca.h
@@ -5,6 +5,12 @@
#ifndef _ALLOCA_H
#define _ALLOCA_H
+#include <builtins_begin_.h>
+mkbi1_(void *, alloca, size_t, size)
+#define alloca_with_align(size, alignment) __builtin_alloca_with_align(size, alignment)
+#define alloca_with_align_and_max(size, alignment, max) __builtin_alloca_with_align_and_max(size, alignment, max)
+#include <builtins_end_.h>
+
#endif /* !_ALLOCA_H */
#endif
// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/builtins_begin_.h b/include/system/builtins_begin_.h
new file mode 100644
index 00000000..92ea5e3a
--- /dev/null
+++ b/include/system/builtins_begin_.h
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+/**
+ * macros to build builtin wrappers
+ */
+#ifndef mkbi_cat_
+#define mkbi_cat_(a, b) a##b
+#endif
+#ifdef SHIM_STRING_C_
+
+#ifndef mkbi1_
+#define mkbi1_(rtype, x, typea, a) __typeof__(mkbi_cat_(__builtin_, x)) x;
+#endif
+#ifndef mkbi2_
+#define mkbi2_(rtype, x, typea, a, typeb, b) __typeof__(mkbi_cat_(__builtin_, x)) x;
+#endif
+
+#ifndef mkbi3_
+#define mkbi3_(rtype, x, typea, a, typeb, b, typec, c) __typeof__(mkbi_cat_(__builtin_, x)) x;
+#endif
+
+#ifndef mkdepbi1_
+#define mkdepbi1_(rtype, x, typea, a) __typeof__(mkbi_cat_(__builtin_, x)) x;
+#endif
+
+#ifndef mkdepbi2_
+#define mkdepbi2_(rtype, x, typea, a, typeb, b) __typeof__(mkbi_cat_(__builtin_, x)) x;
+#endif
+
+#else /* ! SHIM_STRING_C_ */
+
+#ifndef mkbi1_
+#define mkbi1_(rtype, x, typea, a) \
+ static inline __attribute__((__unused__)) \
+ rtype \
+ x(typea a) \
+ { \
+ return mkbi_cat_(__builtin_, x)(a); \
+ }
+#endif
+
+#ifndef mkbi2_
+#define mkbi2_(rtype, x, typea, a, typeb, b) \
+ static inline __attribute__((__unused__)) \
+ rtype \
+ x(typea a, typeb b) \
+ { \
+ return mkbi_cat_(__builtin_, x)(a, b); \
+ }
+#endif
+
+#ifndef mkbi3_
+#define mkbi3_(rtype, x, typea, a, typeb, b, typec, c) \
+ static inline __attribute__((__unused__)) \
+ rtype \
+ x(typea a, typeb b, typec c) \
+ { \
+ return mkbi_cat_(__builtin_, x)(a, b,c); \
+ }
+#endif
+
+#ifdef SHIM_DEPRECATE_STRLEN
+#ifndef mkdepbi_dep_
+#define mkdepbi_dep_ __attribute__((__deprecated__))
+#endif
+#else /* !SHIM_DEPRECATE_STRLEN */
+#ifndef mkdepbi_dep_
+#define mkdepbi_dep_
+#endif
+#endif /* SHIM_DEPRECATE_STRLEN */
+
+#ifndef mkdepbi1_
+#define mkdepbi1_(rtype, x, typea, a) \
+ static inline __attribute__((__unused__)) \
+ mkdepbi_dep_ \
+ rtype \
+ x(typea a) \
+ { \
+ return mkbi_cat_(__builtin_, x)(a); \
+ }
+#endif
+
+#ifndef mkdepbi2_
+#define mkdepbi2_(rtype, x, typea, a, typeb, b) \
+ static inline __attribute__((__unused__)) \
+ mkdepbi_dep_ \
+ rtype \
+ x(typea a, typeb b) \
+ { \
+ return mkbi_cat_(__builtin_, x)(a, b); \
+ }
+#endif
+#endif /* SHIM_STRING_C_ */
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/builtins_end_.h b/include/system/builtins_end_.h
new file mode 100644
index 00000000..0a6ad60a
--- /dev/null
+++ b/include/system/builtins_end_.h
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+
+#ifdef mkbi1_
+#undef mkbi1_
+#endif
+#ifdef mkbi2_
+#undef mkbi2_
+#endif
+#ifdef mkbi3_
+#undef mkbi3_
+#endif
+#ifdef mkdepbi1_
+#undef mkdepbi1_
+#endif
+#ifdef mkdepbi2_
+#undef mkdepbi2_
+#endif
+#ifdef mkdepbi_dep_
+#undef mkdepbi_dep_
+#endif
+#ifdef mkbi_cat_
+#undef mkbi_cat_
+#endif
+
+#ifdef _BUILTINS_BEGIN__H
+#undef _BUILTINS_BEGIN__H
+#endif
+// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/ctype.h b/include/system/ctype.h
index c771bb69..65e7348f 100644
--- a/include/system/ctype.h
+++ b/include/system/ctype.h
@@ -3,11 +3,82 @@
* ctype.h - standard ctype functions
*/
#ifdef SHIM_UNIT_TEST
-#include_next <string.h>
+#include_next <ctype.h>
#else
#ifndef _CTYPE_H
#define _CTYPE_H
+#define isprint(c) ((c) >= 0x20 && (c) <= 0x7e)
+
+/* Determines if a particular character is a decimal-digit character */
+static inline __attribute__((__unused__)) int
+isdigit(int c)
+{
+ //
+ // <digit> ::= [0-9]
+ //
+ return (('0' <= (c)) && ((c) <= '9'));
+}
+
+/* Determine if an integer represents character that is a hex digit */
+static inline __attribute__((__unused__)) int
+isxdigit(int c)
+{
+ //
+ // <hexdigit> ::= [0-9] | [a-f] | [A-F]
+ //
+ return ((('0' <= (c)) && ((c) <= '9')) ||
+ (('a' <= (c)) && ((c) <= 'f')) ||
+ (('A' <= (c)) && ((c) <= 'F')));
+}
+
+/* Determines if a particular character represents a space character */
+static inline __attribute__((__unused__)) int
+isspace(int c)
+{
+ //
+ // <space> ::= [ ]
+ //
+ return ((c) == ' ');
+}
+
+/* Determine if a particular character is an alphanumeric character */
+static inline __attribute__((__unused__)) int
+isalnum(int c)
+{
+ //
+ // <alnum> ::= [0-9] | [a-z] | [A-Z]
+ //
+ return ((('0' <= (c)) && ((c) <= '9')) ||
+ (('a' <= (c)) && ((c) <= 'z')) ||
+ (('A' <= (c)) && ((c) <= 'Z')));
+}
+
+/* Determines if a particular character is in upper case */
+static inline __attribute__((__unused__)) int
+isupper(int c)
+{
+ //
+ // <uppercase letter> := [A-Z]
+ //
+ return (('A' <= (c)) && ((c) <= 'Z'));
+}
+
+/* Convert character to lowercase */
+static inline __attribute__((__unused__)) int
+tolower(int c)
+{
+ if (('A' <= (c)) && ((c) <= 'Z')) {
+ return (c - ('A' - 'a'));
+ }
+ return (c);
+}
+
+static inline __attribute__((__unused__)) int
+toupper(int c)
+{
+ return ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c);
+}
#endif /* !_CTYPE_H */
#endif /* !SHIM_UNIT_TEST */
diff --git a/include/system/stdlib.h b/include/system/stdlib.h
index f2660f63..da7d3af9 100644
--- a/include/system/stdlib.h
+++ b/include/system/stdlib.h
@@ -11,6 +11,18 @@
*/
#include <stddef.h>
+static inline void abort(void) { }
+
+#include <builtins_begin_.h>
+mkbi1_(int, abs, int, j)
+mkbi1_(long int, labs, long int, j)
+mkbi1_(long long int, llabs, long long int, j)
+
+#ifdef _INTTYPES_H
+mkbi1_(intmax_t, imaxabs, intmax_t, j)
+#endif /* _INTTYPES_H */
+#include <builtins_end_.h>
+
#endif /* !_STDLIB_H */
#endif
// vim:fenc=utf-8:tw=75:noet
diff --git a/include/system/string.h b/include/system/string.h
index 21e46c1d..822e28fa 100644
--- a/include/system/string.h
+++ b/include/system/string.h
@@ -7,8 +7,55 @@
#include <stddef.h>
-__typeof__(__builtin_memset) memset;
-__typeof__(__builtin_memcpy) memcpy;
+#include <builtins_begin_.h>
+
+mkbi1_(long int, ffsl, long int, x)
+mkbi1_(long int, clzl, long int, x)
+mkbi1_(long int, ctzl, long int, x)
+mkbi1_(long int, clrsbl, long int, x)
+mkbi1_(long int, popcountl, long int, x)
+mkbi1_(long int, parityl, long int, x)
+mkbi1_(long long int, ffsll, long long int, x)
+mkbi1_(long long int, clzll, long long int, x)
+mkbi1_(long long int, ctzll, long long int, x)
+mkbi1_(long long int, clrsbll, long long int, x)
+mkbi1_(long long int, popcountll, long long int, x)
+mkbi1_(long long int, parityll, long long int, x)
+
+mkbi3_(int, bcmp, const void *, s1, const void *, s2, size_t, n)
+mkbi3_(void, bcopy, const void *, src, void *, dest, size_t, n)
+mkbi2_(void, bzero, void *, s, size_t, n)
+mkdepbi2_(char *, index, const char *, s, int, c)
+mkbi3_(void *, memchr, const void *, s, int, c, size_t, n)
+mkbi3_(int, memcmp, const void *, s1, const void *, s2, size_t, n)
+mkbi3_(void *, memcpy, void *, dest, const void *, src, size_t, n)
+mkbi3_(void *, memmove, void *, dest, const void *, src, size_t, n)
+mkbi3_(void *, mempcpy, void *, dest, const void *, src, size_t, n)
+mkdepbi2_(char *, rindex, const char *, s, int, c)
+mkdepbi2_(char *, stpcpy, char *, dest, const char *, src)
+mkbi3_(char *, stpncpy, char *, dest, const char *, src, size_t, n)
+mkdepbi2_(int, strcasecmp, const char *, s1, const char *, s2)
+mkdepbi2_(char *, strcat, char *, dest, const char *, src)
+mkdepbi2_(char *, strchr, const char *, s, int, c)
+mkdepbi2_(int, strcmp, const char *, s1, const char *, s2)
+mkdepbi2_(char *, strcpy, char *, dest, const char *, src)
+mkdepbi2_(size_t, strcspn, const char *, s, const char *, reject)
+mkdepbi1_(char *, strdup, const char *, s)
+mkbi2_(char *, strndup, const char *, s, size_t, n)
+mkdepbi1_(size_t, strlen, const char *, s)
+mkbi3_(int, strncasecmp, const char *, s1, const char *, s2, size_t, n)
+mkbi3_(char *, strncat, char *, dest, const char *, src, size_t, n)
+mkbi3_(int, strncmp, const char *, s1, const char *, s2, size_t, n)
+mkbi3_(char *, strncpy, char *, dest, const char *, src, size_t, n)
+mkbi2_(int, strnlen, const char *, s1, size_t, n)
+mkdepbi2_(char *, strpbrk, const char *, s, const char *, accept)
+mkdepbi2_(char *, strrchr, const char *, s, int, c)
+mkdepbi2_(size_t, strspn, const char *, s, const char *, accept)
+mkdepbi2_(char *, strstr, const char *, haystack, const char *, needle)
+
+mkbi3_(void *, memset, void *, s, int, c, size_t, n);
+
+#include <builtins_end_.h>
#endif /* _STRING_H */
#endif
diff --git a/include/system/strings.h b/include/system/strings.h
index c82bd917..99bc05f2 100644
--- a/include/system/strings.h
+++ b/include/system/strings.h
@@ -5,6 +5,15 @@
#ifndef _STRINGS_H
#define _STRINGS_H
+#include <builtins_begin_.h>
+mkbi1_(int, ffs, int, x)
+mkbi1_(int, clz, int, x)
+mkbi1_(int, ctz, int, x)
+mkbi1_(int, clrsb, int, x)
+mkbi1_(int, popcount, int, x)
+mkbi1_(int, parity, int, x)
+#include <builtins_end_.h>
+
#endif /* !_STRINGS_H */
#endif
// vim:fenc=utf-8:tw=75:noet