aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/apos/builtin.h8
-rw-r--r--include/apos/bytes.h56
-rw-r--r--include/apos/string.h53
-rw-r--r--include/apos/types.h37
-rw-r--r--include/libfdt_env.h1
5 files changed, 120 insertions, 35 deletions
diff --git a/include/apos/builtin.h b/include/apos/builtin.h
new file mode 100644
index 0000000..52a3fa2
--- /dev/null
+++ b/include/apos/builtin.h
@@ -0,0 +1,8 @@
+#ifndef APOS_BUILTIN_H
+#define APOS_BUILTIN_H
+
+#ifndef __has_builtin
+#define __has_builtin(x) (0)
+#endif
+
+#endif /* APOS_BUILTIN_H */
diff --git a/include/apos/bytes.h b/include/apos/bytes.h
new file mode 100644
index 0000000..da0ab67
--- /dev/null
+++ b/include/apos/bytes.h
@@ -0,0 +1,56 @@
+#ifndef APOS_BYTES_H
+#define APOS_BYTES_H
+
+#include <apos/types.h>
+
+uint16_t __bswap16(uint16_t u);
+uint32_t __bswap32(uint32_t u);
+uint64_t __bswap64(uint64_t u);
+
+#if __has_builtin(__builtin_bswap16)
+#define __bswap16(x) __builtin_bswap16(x)
+#endif
+
+#if __has_builtin(__builtin_bswap32)
+#define __bswap32(x) __builtin_bswap32(x)
+#endif
+
+#if __has_builtin(__builtin_bswap64)
+#define __bswap64(x) __builtin_bswap64(x)
+#endif
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define be16_to_cpu(x) __bswap16(x)
+#define be32_to_cpu(x) __bswap32(x)
+#define be64_to_cpu(x) __bswap64(x)
+
+#define cpu_to_be16(x) __bswap16(x)
+#define cpu_to_be32(x) __bswap32(x)
+#define cpu_to_be64(x) __bswap64(x)
+
+#define le16_to_cpu(x) (x)
+#define le32_to_cpu(x) (x)
+#define le64_to_cpu(x) (x)
+
+#define cpu_to_le16(x) (x)
+#define cpu_to_le32(x) (x)
+#define cpu_to_le64(x) (x)
+#else
+#define be16_to_cpu(x) (x)
+#define be32_to_cpu(x) (x)
+#define be64_to_cpu(x) (x)
+
+#define cpu_to_be16(x) (x)
+#define cpu_to_be32(x) (x)
+#define cpu_to_be64(x) (x)
+
+#define le16_to_cpu(x) __bswap16(x)
+#define le32_to_cpu(x) __bswap32(x)
+#define le64_to_cpu(x) __bswap64(x)
+
+#define cpu_to_le16(x) __bswap16(x)
+#define cpu_to_le32(x) __bswap32(x)
+#define cpu_to_le64(x) __bswap64(x)
+#endif
+
+#endif /* APOS_BYTES_H */
diff --git a/include/apos/string.h b/include/apos/string.h
index 787f630..67cdae8 100644
--- a/include/apos/string.h
+++ b/include/apos/string.h
@@ -2,6 +2,7 @@
#define APOS_STRING_H
#include <apos/types.h>
+#include <apos/builtin.h>
/* follow C library functions, drop location and error functions */
@@ -51,28 +52,80 @@ int memcmp(const void *ptr1, const void *ptr2, size_t num);
* an issue.
*/
+#if __has_builtin(__builtin_memcpy)
#define memcpy(dst, src, num) __builtin_memcpy(dst, src, num)
+#endif
+
+#if __has_builtin(__builtin_memmove)
#define memmove(dst, src, num) __builtin_memmove(dst, src, num)
+#endif
+
+#if __has_builtin(__builtin_strcpy)
#define strcpy(dst, src) __builtin_strcpy(dst, src)
+#endif
+
+#if __has_builtin(__builtin_strncpy)
#define strncpy(dst, src, num) __builtin_strncpy(dst, src, num)
+#endif
+#if __has_builtin(__builtin_strcat)
#define strcat(dst, src) __builtin_strcat(dst, src)
+#endif
+
+#if __has_builtin(__builtin_strncat)
#define strncat(dst, src, num) __builtin_strncat(dst, src, num)
+#endif
+#if __has_builtin(__builtin_memcmp)
#define memcmp(p1, p2, num) __builtin_memcmp(p1, p2, num)
+#endif
+
+#if __has_builtin(__builtin_strcmp)
#define strcmp(s1, s2) __builtin_strcmp(s1, s2)
+#endif
+
+#if __has_builtin(__builtin_strncmp)
#define strncmp(s1, s2, num) __builtin_strncmp(s1, s2, num)
+#endif
+#if __has_builtin(__builtin_strncmp)
#define memchr(ptr, val, num) __builtin_memchr(ptr, val, num)
+#endif
+
+#if __has_builtin(__builtin_strchr)
#define strchr(str, chr) __builtin_strchr(str, chr)
+#endif
+
+#if __has_builtin(__builtin_strcspn)
#define strcspn(s1, s2) __builtin_strcspn(s1, s2)
+#endif
+
+#if __has_builtin(__builtin_strpbrk)
#define strpbrk(s1, s2) __builtin_strpbrk(s1, s2)
+#endif
+
+#if __has_builtin(__builtin_strchr)
#define strrchr(s1, s2) __builtin_strrchr(s1, s2)
+#endif
+
+#if __has_builtin(__builtin_strspn)
#define strspn(s1, s2) __builtin_strspn(s1, s2)
+#endif
+
+#if __has_builtin(__builtin_strstr)
#define strstr(s1, s2) __builtin_strstr(s1, s2)
+#endif
+
+#if __has_builtin(__builtin_strtok)
#define strtok(s1, s2) __builtin_strtok(s1, s2)
+#endif
+#if __has_builtin(__builtin_memset)
#define memset(p, v, n) __builtin_memset(p, v, n)
+#endif
+
+#if __has_builtin(__builtin_strlen)
#define strlen(s) __builtin_strlen(s)
+#endif
#endif /* APOS_STRING_H */
diff --git a/include/apos/types.h b/include/apos/types.h
index f63857b..791c394 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -1,6 +1,8 @@
#ifndef APOS_TYPES_H
#define APOS_TYPES_H
+#include <apos/builtin.h>
+
typedef _Bool bool;
#define true 1
#define false 0
@@ -10,7 +12,6 @@ typedef __WCHAR_TYPE__ wchar_t;
typedef __WINT_TYPE__ wint_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;
-typedef __SIG_ATOMIC_TYPE__ sig_atomic_t;
typedef __INT8_TYPE__ int8_t;
typedef __INT16_TYPE__ int16_t;
typedef __INT32_TYPE__ int32_t;
@@ -174,40 +175,6 @@ typedef intmax_t ssize_t;
#define UINTPTR_WIDTH __INTPTR_WIDTH__
#define UINTMAX_WIDTH __INTMAX_WIDTH__
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define be16_to_cpu(x) __builtin_bswap16(x)
-#define be32_to_cpu(x) __builtin_bswap32(x)
-#define be64_to_cpu(x) __builtin_bswap64(x)
-
-#define cpu_to_be16(x) __builtin_bswap16(x)
-#define cpu_to_be32(x) __builtin_bswap32(x)
-#define cpu_to_be64(x) __builtin_bswap64(x)
-
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#define le64_to_cpu(x) (x)
-
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_le64(x) (x)
-#else
-#define be16_to_cpu(x) (x)
-#define be32_to_cpu(x) (x)
-#define be64_to_cpu(x) (x)
-
-#define cpu_to_be16(x) (x)
-#define cpu_to_be32(x) (x)
-#define cpu_to_be64(x) (x)
-
-#define le16_to_cpu(x) __builtin_bswap16(x)
-#define le32_to_cpu(x) __builtin_bswap32(x)
-#define le64_to_cpu(x) __builtin_bswap64(x)
-
-#define cpu_to_le16(x) __builtin_bswap16(x)
-#define cpu_to_le32(x) __builtin_bswap32(x)
-#define cpu_to_le64(x) __builtin_bswap64(x)
-#endif
-
#define NULL 0
#endif /* APOS_TYPES_H */
diff --git a/include/libfdt_env.h b/include/libfdt_env.h
index 166b558..96da42e 100644
--- a/include/libfdt_env.h
+++ b/include/libfdt_env.h
@@ -4,6 +4,7 @@
#include <apos/types.h>
#include <apos/string.h>
+#include <apos/bytes.h>
typedef int16_t fdt16_t;
typedef int32_t fdt32_t;