From 8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 22:22:16 +0100 Subject: Add bin/true and bin/false implementations - Added assembly implementations for `true` and `false` commands. - Updated Kbuild files to include new binaries. - Removed unused libraries and headers. - Cleaned up makefile and unused code. --- .gitignore | 2 + Kbuild | 1 + bin/Kbuild | 2 + bin/false/Kbuild | 3 + bin/false/arch/Kbuild | 1 + bin/false/arch/x86_64/Kbuild | 1 + bin/false/arch/x86_64/false.s | 6 + bin/false/false | Bin 0 -> 824 bytes bin/true/Kbuild | 3 + bin/true/arch/Kbuild | 1 + bin/true/arch/x86_64/Kbuild | 1 + bin/true/arch/x86_64/true.s | 7 + bin/true/true | Bin 0 -> 824 bytes include/assert.h | 21 - include/bits/errno.h | 12 + include/bits/sigevent.h | 2 + include/bits/timespec.h | 2 + include/bits/wait.h | 22 + include/fnmatch.h | 4 +- include/monetary.h | 11 - include/net/if.h | 4 +- include/stdbool.h | 4 +- include/stdckdint.h | 8 + include/stddef.h | 3 + include/stdint.h | 4 +- include/stdio.h | 3 + include/stdlib.h | 23 +- include/string.h | 7 +- include/sys/wait.h | 21 +- include/time.h | 5 +- include/wchar.h | 112 --- include/wctype.h | 49 -- lib/Kbuild | 1 - lib/libc/assert/Kbuild | 1 + lib/libc/ctype/Kbuild | 14 + lib/libc/ctype/isalnum.c | 2 +- lib/libc/ctype/ispunct.c | 2 +- lib/libc/ctype/tolower.c | 2 +- lib/libc/ctype/toupper.c | 2 +- lib/libc/devctl/Kbuild | 1 + lib/libc/devctl/posix_devctl.c | 2 +- lib/libc/dirent/Kbuild | 6 + lib/libc/dirent/readdir_r.c | 14 +- lib/libc/endian/Kbuild | 12 + lib/libc/errno/Kbuild | 1 + lib/libc/fcntl/Kbuild | 6 + lib/libc/grp/Kbuild | 2 + lib/libc/include/__locale.h | 41 - lib/libc/include/features.h | 2 +- lib/libc/include/io.h | 19 - lib/libc/include/libc.h | 6 +- lib/libc/inttypes/Kbuild | 4 + lib/libc/libc.a | Bin 0 -> 1152260 bytes lib/libc/libgen/Kbuild | 2 + lib/libc/mman/Kbuild | 9 + lib/libc/monetary/strfmon.c | 131 --- lib/libc/msg/Kbuild | 1 + lib/libc/poll/Kbuild | 2 + lib/libc/pwd/Kbuild | 2 + lib/libc/select/Kbuild | 2 + lib/libc/sem/Kbuild | 3 + lib/libc/setjmp/Kbuild | 1 + lib/libc/signal/Kbuild | 21 + lib/libc/signal/pthread_sigmask.c | 1 + lib/libc/socket/Kbuild | 19 + lib/libc/socket/listen.c | 2 +- lib/libc/stat/Kbuild | 16 + lib/libc/stat/fstatat.c | 10 +- lib/libc/statvfs/Kbuild | 2 + lib/libc/stdio/Kbuild | 48 ++ lib/libc/stdio/dtoa.c | 11 +- lib/libc/stdio/fdopen.c | 2 +- lib/libc/stdio/fflush.c | 1 + lib/libc/stdio/fmemopen.c | 2 +- lib/libc/stdio/fopen.c | 2 +- lib/libc/stdio/fprintf.c | 2 +- lib/libc/stdio/stdin.c | 2 +- lib/libc/stdio/stdout.c | 2 +- lib/libc/stdio/vfprintf.c | 5 - lib/libc/stdio/vsnprintf.c | 1 + lib/libc/stdlib/malloc.c | 2 +- lib/libc/string/Kbuild | 32 + lib/libc/string/memcpy.c | 2 +- lib/libc/string/strcoll.c | 2 +- lib/libc/string/strerror.c | 2 +- lib/libc/string/strxfrm.c | 4 +- lib/libc/strings/Kbuild | 5 + lib/libc/strings/ffs.c | 4 +- lib/libc/strings/ffsl.c | 12 +- lib/libc/strings/strcasecmp.c | 3 +- lib/libc/strings/strncasecmp.c | 4 +- lib/libc/sys/Kbuild | 4 + lib/libc/syslog/Kbuild | 4 + lib/libc/syslog/openlog.c | 1 + lib/libc/syslog/setlogmask.c | 1 + lib/libc/syslog/syslog.c | 2 + lib/libc/time/strftime.c | 4 +- lib/libc/uio/Kbuild | 2 + lib/libc/unistd/Kbuild | 77 ++ lib/libc/unistd/execlp.c | 6 +- lib/libc/unistd/execvp.c | 3 +- lib/libc/unistd/getentropy.c | 2 + lib/libc/unistd/gethostname.c | 2 + lib/libc/unistd/getlogin_r.c | 2 + lib/libc/unistd/lockf.c | 3 + lib/libc/unistd/nice.c | 1 + lib/libc/unistd/posix_close.c | 2 +- lib/libc/utsname/Kbuild | 1 + lib/libc/wait/Kbuild | 3 + lib/libc/wchar/wctob.c | 16 - lib/libc/wctype/iswalnum.c | 12 - lib/libc/wctype/iswalpha.c | 22 - lib/libc/wctype/iswblank.c | 13 - lib/libc/wctype/iswdigit.c | 12 - lib/libc/wctype/iswgraph.c | 12 - lib/libc/wctype/iswlower.c | 12 - lib/libc/wctype/iswprint.c | 14 - lib/libc/wctype/iswpunct.c | 327 -------- lib/libc/wctype/iswspace.c | 20 - lib/libc/wctype/iswupper.c | 12 - lib/libc/wctype/iswxdigit.c | 12 - lib/libc/wctype/towctrans.c | 348 -------- lib/libc/wctype/wctype.c | 32 - lib/libjson/Kbuild | 3 - lib/libjson/json.c | 1607 ------------------------------------- lib/libjson/json.h | 602 -------------- lib/main.c | 7 - lib/other.c | 6 - makefile | 6 +- 129 files changed, 498 insertions(+), 3576 deletions(-) create mode 100644 bin/Kbuild create mode 100644 bin/false/Kbuild create mode 100644 bin/false/arch/Kbuild create mode 100644 bin/false/arch/x86_64/Kbuild create mode 100644 bin/false/arch/x86_64/false.s create mode 100755 bin/false/false create mode 100644 bin/true/Kbuild create mode 100644 bin/true/arch/Kbuild create mode 100644 bin/true/arch/x86_64/Kbuild create mode 100644 bin/true/arch/x86_64/true.s create mode 100755 bin/true/true create mode 100644 include/bits/errno.h create mode 100644 include/bits/wait.h delete mode 100644 include/monetary.h create mode 100644 include/stdckdint.h delete mode 100644 include/wchar.h delete mode 100644 include/wctype.h create mode 100644 lib/libc/assert/Kbuild create mode 100644 lib/libc/ctype/Kbuild create mode 100644 lib/libc/devctl/Kbuild create mode 100644 lib/libc/dirent/Kbuild create mode 100644 lib/libc/endian/Kbuild create mode 100644 lib/libc/errno/Kbuild create mode 100644 lib/libc/fcntl/Kbuild create mode 100644 lib/libc/grp/Kbuild delete mode 100644 lib/libc/include/__locale.h create mode 100644 lib/libc/inttypes/Kbuild create mode 100644 lib/libc/libc.a create mode 100644 lib/libc/libgen/Kbuild create mode 100644 lib/libc/mman/Kbuild delete mode 100644 lib/libc/monetary/strfmon.c create mode 100644 lib/libc/msg/Kbuild create mode 100644 lib/libc/poll/Kbuild create mode 100644 lib/libc/pwd/Kbuild create mode 100644 lib/libc/select/Kbuild create mode 100644 lib/libc/sem/Kbuild create mode 100644 lib/libc/setjmp/Kbuild create mode 100644 lib/libc/signal/Kbuild create mode 100644 lib/libc/socket/Kbuild create mode 100644 lib/libc/stat/Kbuild create mode 100644 lib/libc/statvfs/Kbuild create mode 100644 lib/libc/stdio/Kbuild create mode 100644 lib/libc/string/Kbuild create mode 100644 lib/libc/strings/Kbuild create mode 100644 lib/libc/sys/Kbuild create mode 100644 lib/libc/syslog/Kbuild create mode 100644 lib/libc/uio/Kbuild create mode 100644 lib/libc/unistd/Kbuild create mode 100644 lib/libc/utsname/Kbuild create mode 100644 lib/libc/wait/Kbuild delete mode 100644 lib/libc/wchar/wctob.c delete mode 100644 lib/libc/wctype/iswalnum.c delete mode 100644 lib/libc/wctype/iswalpha.c delete mode 100644 lib/libc/wctype/iswblank.c delete mode 100644 lib/libc/wctype/iswdigit.c delete mode 100644 lib/libc/wctype/iswgraph.c delete mode 100644 lib/libc/wctype/iswlower.c delete mode 100644 lib/libc/wctype/iswprint.c delete mode 100644 lib/libc/wctype/iswpunct.c delete mode 100644 lib/libc/wctype/iswspace.c delete mode 100644 lib/libc/wctype/iswupper.c delete mode 100644 lib/libc/wctype/iswxdigit.c delete mode 100644 lib/libc/wctype/towctrans.c delete mode 100644 lib/libc/wctype/wctype.c delete mode 100644 lib/libjson/Kbuild delete mode 100644 lib/libjson/json.c delete mode 100644 lib/libjson/json.h delete mode 100644 lib/main.c delete mode 100644 lib/other.c diff --git a/.gitignore b/.gitignore index 553ddcef..f301536f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.o +.cache + .config .config.old diff --git a/Kbuild b/Kbuild index cdaefffb..f40b4f44 100644 --- a/Kbuild +++ b/Kbuild @@ -1 +1,2 @@ obj-y += lib/ +obj-y += bin/ diff --git a/bin/Kbuild b/bin/Kbuild new file mode 100644 index 00000000..a252cb2c --- /dev/null +++ b/bin/Kbuild @@ -0,0 +1,2 @@ +obj-y += true/ +obj-y += false/ diff --git a/bin/false/Kbuild b/bin/false/Kbuild new file mode 100644 index 00000000..3b6f0687 --- /dev/null +++ b/bin/false/Kbuild @@ -0,0 +1,3 @@ +bin-y := false + +obj-y += arch/ diff --git a/bin/false/arch/Kbuild b/bin/false/arch/Kbuild new file mode 100644 index 00000000..ad3a7486 --- /dev/null +++ b/bin/false/arch/Kbuild @@ -0,0 +1 @@ +obj-y += $(ARCH)/ diff --git a/bin/false/arch/x86_64/Kbuild b/bin/false/arch/x86_64/Kbuild new file mode 100644 index 00000000..9958368e --- /dev/null +++ b/bin/false/arch/x86_64/Kbuild @@ -0,0 +1 @@ +obj-y += false.o diff --git a/bin/false/arch/x86_64/false.s b/bin/false/arch/x86_64/false.s new file mode 100644 index 00000000..f1f36b6b --- /dev/null +++ b/bin/false/arch/x86_64/false.s @@ -0,0 +1,6 @@ +.globl _start + +_start: + mov $60, %rax + mov $1, %rdi + syscall diff --git a/bin/false/false b/bin/false/false new file mode 100755 index 00000000..554098bc Binary files /dev/null and b/bin/false/false differ diff --git a/bin/true/Kbuild b/bin/true/Kbuild new file mode 100644 index 00000000..d0565b08 --- /dev/null +++ b/bin/true/Kbuild @@ -0,0 +1,3 @@ +bin-y := true + +obj-y += arch/ diff --git a/bin/true/arch/Kbuild b/bin/true/arch/Kbuild new file mode 100644 index 00000000..ad3a7486 --- /dev/null +++ b/bin/true/arch/Kbuild @@ -0,0 +1 @@ +obj-y += $(ARCH)/ diff --git a/bin/true/arch/x86_64/Kbuild b/bin/true/arch/x86_64/Kbuild new file mode 100644 index 00000000..e4710aaa --- /dev/null +++ b/bin/true/arch/x86_64/Kbuild @@ -0,0 +1 @@ +obj-y += true.o diff --git a/bin/true/arch/x86_64/true.s b/bin/true/arch/x86_64/true.s new file mode 100644 index 00000000..782ef00d --- /dev/null +++ b/bin/true/arch/x86_64/true.s @@ -0,0 +1,7 @@ +.globl _start + +_start: + mov 60, %rax + xor %rdi, %rdi + syscall + diff --git a/bin/true/true b/bin/true/true new file mode 100755 index 00000000..49700c41 Binary files /dev/null and b/bin/true/true differ diff --git a/include/assert.h b/include/assert.h index f69aa43d..56d7d1e2 100644 --- a/include/assert.h +++ b/include/assert.h @@ -5,27 +5,6 @@ #define assert(ignore) ((void)0) #else -/** - * @def assert(expr) - * @brief Macro to perform runtime assertions. - * - * The assert() macro shall insert diagnostics into programs; it shall expand to - * a void expression. When it is executed, if expression (which shall have a - * scalar type) is false (that is, compares equal to 0), assert() shall write - * information about the particular call that failed on stderr and shall call - * abort(). The information written about the call that failed shall include the - * text of the argument, the name of the source file, the source file line - * number, and the name of the enclosing function; the latter are, respectively, - * the values of the preprocessing * macros __FILE__ and __LINE__ and of the - * identifier __func__. Forcing a definition of the name NDEBUG, either from the - * compiler command line or with the preprocessor control statement #define - * NDEBUG ahead of the #include statement, shall stop assertions from - * being compiled into the program. - * - * @param expr The expression to be evaluated. - * - * @see abort - */ #define assert(__expr) \ ((__expr) ? \ (void)0 : \ diff --git a/include/bits/errno.h b/include/bits/errno.h new file mode 100644 index 00000000..4789fef8 --- /dev/null +++ b/include/bits/errno.h @@ -0,0 +1,12 @@ +#ifndef __BITS_ERRNO_H +#define __BITS_ERRNO_H + +#ifndef __BITS_ERRNO_H_ +#error "Internal header — include the public API header instead." +#else +#undef __BITS_ERRNO_H_ +#endif + +typedef int errno_t; + +#endif diff --git a/include/bits/sigevent.h b/include/bits/sigevent.h index b36e676c..ddf4c4d7 100644 --- a/include/bits/sigevent.h +++ b/include/bits/sigevent.h @@ -3,6 +3,8 @@ #ifndef __BITS_SIGEVENT_H_ #error "Internal header — include the public API header instead." +#else +#undef __BITS_SIGEVENT_H_ #endif union sigval { diff --git a/include/bits/timespec.h b/include/bits/timespec.h index ebcacf76..646c76f7 100644 --- a/include/bits/timespec.h +++ b/include/bits/timespec.h @@ -3,6 +3,8 @@ #ifndef __BITS_TIMESPEC_H_ #error "Never include directly; use instead." +#else +#undef __BITS_TIMESPEC_H_ #endif typedef __INT64_TYPE__ time_t; diff --git a/include/bits/wait.h b/include/bits/wait.h new file mode 100644 index 00000000..5e346276 --- /dev/null +++ b/include/bits/wait.h @@ -0,0 +1,22 @@ +#ifndef __BITS_WAIT_H +#define __BITS_WAIT_H + +#ifndef __BITS_WAIT_H_ +#error "Internal header — include the public API header instead." +#else +#undef __BITS_WAIT_H_ +#endif + +#define WNOHANG 0x00000001 +#define WUNTRACED 0x00000002 + +#define WEXITSTATUS(__status) (((__status) & 0xff00) >> 8) +#define WCOREDUMP(__status) ((__status) & 0x80) +#define WTERMSIG(__status) ((__status) & 0x7f) +#define WSTOPSIG(__status) WEXITSTATUS(__status) +#define WIFEXITED(__status) (WTERMSIG(__status) == 0) +#define WIFSTOPPED(__status) (((__status) & 0xff) == 0x7f) +#define WIFSIGNALED(__status) (((__status) & 0xffff) - 1U < 0xffu) +#define WSTOPSIG(__status) WEXITSTATUS(__status) + +#endif diff --git a/include/fnmatch.h b/include/fnmatch.h index 0f3c71be..2067f595 100644 --- a/include/fnmatch.h +++ b/include/fnmatch.h @@ -1,5 +1,5 @@ -#ifndef __FNMATCH_H__ -#define __FNMATCH_H__ +#ifndef __FNMATCH_H +#define __FNMATCH_H #define FNM_PATHNAME 0x1 #define FNM_NOESCAPE 0x2 diff --git a/include/monetary.h b/include/monetary.h deleted file mode 100644 index 6a17a7c4..00000000 --- a/include/monetary.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __MONETARY_H -#define __MONETARY_H - -typedef struct __locale_t *locale_t; -typedef __SIZE_TYPE__ size_t; -typedef __INT64_TYPE__ ssize_t; - -ssize_t strfmon(char *restrict, size_t, const char *restrict, ...); -ssize_t strfmon_l(char *restrict, size_t, locale_t, const char *restrict, ...); - -#endif diff --git a/include/net/if.h b/include/net/if.h index fcebbc62..3bb6b5c8 100644 --- a/include/net/if.h +++ b/include/net/if.h @@ -1,5 +1,5 @@ -#ifndef __NET_IF_H__ -#define __NET_IF_H__ +#ifndef __NET_IF_H +#define __NET_IF_H struct if_nameindex { unsigned if_index; diff --git a/include/stdbool.h b/include/stdbool.h index 4b677e27..3d942ff4 100644 --- a/include/stdbool.h +++ b/include/stdbool.h @@ -1,5 +1,5 @@ -#ifndef __STDBOOL_H__ -#define __STDBOOL_H__ +#ifndef __STDBOOL_H +#define __STDBOOL_H #define bool _Bool #define true 1 diff --git a/include/stdckdint.h b/include/stdckdint.h new file mode 100644 index 00000000..52c88a12 --- /dev/null +++ b/include/stdckdint.h @@ -0,0 +1,8 @@ +#ifndef __STDCKDINT_H +#define __STDCKDINT_H + +#define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R)) +#define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R)) +#define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R)) + +#endif diff --git a/include/stddef.h b/include/stddef.h index bb8d1925..dfae9a12 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -1,6 +1,9 @@ #ifndef __STDDEF_H #define __STDDEF_H +#define __BITS_ERRNO_H_ +#include + #ifndef NULL #define NULL ((void *)0) #endif diff --git a/include/stdint.h b/include/stdint.h index 87b72193..a1a2768d 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -1,5 +1,5 @@ -#ifndef __STDINT_H__ -#define __STDINT_H__ +#ifndef __STDINT_H +#define __STDINT_H #undef WCHAR_MAX #undef WCHAR_MIN diff --git a/include/stdio.h b/include/stdio.h index 3cc457b3..c6067775 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,6 +1,9 @@ #ifndef __STDIO_H #define __STDIO_H +#define __BITS_ERRNO_H_ +#include + #ifndef NULL #define NULL ((void *)0) #endif diff --git a/include/stdlib.h b/include/stdlib.h index 4f9c1eb8..a9480d38 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,5 +1,11 @@ -#ifndef __STDLIB_H__ -#define __STDLIB_H__ +#ifndef __STDLIB_H +#define __STDLIB_H + +#define __BITS_WAIT_H_ +#include + +#define __BITS_ERRNO_H_ +#include #ifndef NULL #define NULL ((void *)0) @@ -8,18 +14,7 @@ #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 -#define WNOHANG 1 -#define WUNTRACED 2 - -#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) -#define WTERMSIG(s) ((s) & 0x7f) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) ((short)((((s) & 0xffff) * 0x10001U) >> 8) > 0x7f00) -#define WIFSIGNALED(s) (((s) & 0xffff) - 1U < 0xffu) - -int ___mb_cur_max(void); -#define MB_CUR_MAX (___mb_cur_max()) +#define MB_CUR_MAX 1 #define RAND_MAX (0x7fffffff) diff --git a/include/string.h b/include/string.h index f9a1a829..17ad87e5 100644 --- a/include/string.h +++ b/include/string.h @@ -1,13 +1,16 @@ #ifndef __STRING_H #define __STRING_H -typedef __SIZE_TYPE__ size_t; -typedef struct __locale_t *locale_t; +#define __BITS_ERRNO_H_ +#include #ifndef NULL #define NULL ((void *)0) #endif +typedef __SIZE_TYPE__ size_t; +typedef struct __locale_t *locale_t; + void *memccpy(void *restrict, const void *restrict, int, size_t); void *memchr(const void *, int, size_t); int memcmp(const void *, const void *, size_t); diff --git a/include/sys/wait.h b/include/sys/wait.h index bbe8a8fe..2a7438d7 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -1,20 +1,13 @@ #ifndef __WAIT_H #define __WAIT_H -#define WCONTINUED 0x00000008 -#define WNOHANG 0x00000001 -#define WUNTRACED 0x00000002 -#define WCOREDUMP(__s) ((__s) & 0x80) -#define WIFCONTINUED(__s) ((__s) == 0xffff) -#define WIFEXITED(__s) (!WTERMSIG(__s)) -#define WIFSIGNALED(__s) (((s) & 0xffff) - 1U < 0xffu) -#define WIFSTOPPED(__s) ((short)((((__s) & 0xffff) * 0x10001U) >> 8) > 0x7f00) -#define WSTOPSIG(__s) WEXITSTATUS(__s) -#define WTERMSIG(__s) ((__s) & 0x7f) - -#define WEXITED -#define WNOWAIT -#define WSTOPPED +#define __BITS_WAIT_H_ +#include + +#define WCONTINUED 0x00000008 +#define WEXITED 0x00000004 +#define WNOWAIT 0x01000000 +#define WSTOPPED WUNTRACED typedef __UINT32_TYPE__ id_t; typedef __INT64_TYPE__ pid_t; diff --git a/include/time.h b/include/time.h index 745e626c..fc089cda 100644 --- a/include/time.h +++ b/include/time.h @@ -3,11 +3,12 @@ #define __BITS_TIMESPEC_H_ #include -#undef __BITS_TIMESPEC_H_ #define __BITS_SIGEVENT_H_ #include -#undef __BITS_SIGEVENT_H_ + +#define __BITS_ERRNO_H_ +#include #ifndef NULL #define NULL ((void *)0) diff --git a/include/wchar.h b/include/wchar.h deleted file mode 100644 index 85e58328..00000000 --- a/include/wchar.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef __WCHAR_H__ -#define __WCHAR_H__ - -typedef struct __FILE FILE; -typedef struct __locale_t *locale_t; -typedef struct __mbstate_t mbstate_t; -typedef __SIZE_TYPE__ size_t; -typedef __builtin_va_list va_list; -typedef __WCHAR_TYPE__ wchar_t; -typedef unsigned wint_t; -struct tm; - -#undef WCHAR_MAX -#undef WCHAR_MIN -#if L'\0' - 1 > 0 -#define WCHAR_MAX (0xffffffffu + L'\0') -#define WCHAR_MIN (0 + L'\0') -#else -#define WCHAR_MAX (0x7fffffff + L'\0') -#define WCHAR_MIN (-1 - 0x7fffffff + L'\0') -#endif - -#undef WEOF -#define WEOF 0xffffffffU - -#undef NULL -#define NULL ((void *)0) - -wint_t btowc(int); -wint_t fgetwc(FILE *); -wchar_t *fgetws(wchar_t *restrict, int, FILE *restrict); -wint_t fputwc(wchar_t, FILE *); -int fputws(const wchar_t *restrict, FILE *restrict); -int fwide(FILE *, int); -int fwprintf(FILE *restrict, const wchar_t *restrict, ...); -int fwscanf(FILE *restrict, const wchar_t *restrict, ...); -wint_t getwc(FILE *); -wint_t getwchar(void); -size_t mbrlen(const char *restrict, size_t, mbstate_t *restrict); -size_t mbrtowc(wchar_t *restrict, const char *restrict, size_t, - mbstate_t *restrict); -int mbsinit(const mbstate_t *); -size_t mbsnrtowcs(wchar_t *restrict, const char **restrict, size_t, size_t, - mbstate_t *restrict); -size_t mbsrtowcs(wchar_t *restrict, const char **restrict, size_t, - mbstate_t *restrict); -FILE *open_wmemstream(wchar_t **, size_t *); -wint_t putwc(wchar_t, FILE *); -wint_t putwchar(wchar_t); -int swprintf(wchar_t *restrict, size_t, const wchar_t *restrict, ...); -int swscanf(const wchar_t *restrict, const wchar_t *restrict, ...); -wint_t ungetwc(wint_t, FILE *); -int vfwprintf(FILE *restrict, const wchar_t *restrict, va_list); -int vfwscanf(FILE *restrict, const wchar_t *restrict, va_list); -int vswprintf(wchar_t *restrict, size_t, const wchar_t *restrict, va_list); -int vswscanf(const wchar_t *restrict, const wchar_t *restrict, va_list); -int vwprintf(const wchar_t *restrict, va_list); -int vwscanf(const wchar_t *restrict, va_list); -wchar_t *wcpcpy(wchar_t *restrict, const wchar_t *restrict); -wchar_t *wcpncpy(wchar_t *restrict, const wchar_t *restrict, size_t); -size_t wcrtomb(char *restrict, wchar_t, mbstate_t *restrict); -int wcscasecmp(const wchar_t *, const wchar_t *); -int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); -wchar_t *wcscat(wchar_t *restrict, const wchar_t *restrict); -wchar_t *wcschr(const wchar_t *, wchar_t); -int wcscmp(const wchar_t *, const wchar_t *); -int wcscoll(const wchar_t *, const wchar_t *); -int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); -wchar_t *wcscpy(wchar_t *restrict, const wchar_t *restrict); -size_t wcscspn(const wchar_t *, const wchar_t *); -wchar_t *wcsdup(const wchar_t *); -size_t wcsftime(wchar_t *restrict, size_t, const wchar_t *restrict, - const struct tm *restrict); -size_t wcslcat(wchar_t *restrict, const wchar_t *restrict, size_t); -size_t wcslcpy(wchar_t *restrict, const wchar_t *restrict, size_t); -size_t wcslen(const wchar_t *); -int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); -int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); -wchar_t *wcsncat(wchar_t *restrict, const wchar_t *restrict, size_t); -int wcsncmp(const wchar_t *, const wchar_t *, size_t); -wchar_t *wcsncpy(wchar_t *restrict, const wchar_t *restrict, size_t); -size_t wcsnlen(const wchar_t *, size_t); -size_t wcsnrtombs(char *restrict, const wchar_t **restrict, size_t, size_t, - mbstate_t *restrict); -wchar_t *wcspbrk(const wchar_t *, const wchar_t *); -wchar_t *wcsrchr(const wchar_t *, wchar_t); -size_t wcsrtombs(char *restrict, const wchar_t **restrict, size_t, - mbstate_t *restrict); -size_t wcsspn(const wchar_t *, const wchar_t *); -wchar_t *wcsstr(const wchar_t *restrict, const wchar_t *restrict); -double wcstod(const wchar_t *restrict, wchar_t **restrict); -float wcstof(const wchar_t *restrict, wchar_t **restrict); -wchar_t *wcstok(wchar_t *restrict, const wchar_t *restrict, wchar_t **restrict); -long wcstol(const wchar_t *restrict, wchar_t **restrict, int); -long double wcstold(const wchar_t *restrict, wchar_t **restrict); -long long wcstoll(const wchar_t *restrict, wchar_t **restrict, int); -unsigned long wcstoul(const wchar_t *restrict, wchar_t **restrict, int); -unsigned long long wcstoull(const wchar_t *restrict, wchar_t **restrict, int); -int wcswidth(const wchar_t *, size_t); -size_t wcsxfrm(wchar_t *restrict, const wchar_t *restrict, size_t); -size_t wcsxfrm_l(wchar_t *restrict, const wchar_t *restrict, size_t, locale_t); -int wctob(wint_t); -int wcwidth(wchar_t); -wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); -int wmemcmp(const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy(wchar_t *restrict, const wchar_t *restrict, size_t); -wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); -wchar_t *wmemset(wchar_t *, wchar_t, size_t); -int wprintf(const wchar_t *restrict, ...); -int wscanf(const wchar_t *restrict, ...); - -#endif diff --git a/include/wctype.h b/include/wctype.h deleted file mode 100644 index 391c3d6b..00000000 --- a/include/wctype.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __WCTYPE_H -#define __WCTYPE_H - -#undef WEOF -#define WEOF 0xffffffffU - -typedef unsigned wint_t; -typedef const int *wctrans_t; -typedef unsigned long wctype_t; -typedef struct __locale_t *locale_t; - -int iswalnum(wint_t); -int iswalnum_l(wint_t, locale_t); -int iswalpha(wint_t); -int iswalpha_l(wint_t, locale_t); -int iswblank(wint_t); -int iswblank_l(wint_t, locale_t); -int iswcntrl(wint_t); -int iswcntrl_l(wint_t, locale_t); -int iswctype(wint_t, wctype_t); -int iswctype_l(wint_t, wctype_t, locale_t); -int iswdigit(wint_t); -int iswdigit_l(wint_t, locale_t); -int iswgraph(wint_t); -int iswgraph_l(wint_t, locale_t); -int iswlower(wint_t); -int iswlower_l(wint_t, locale_t); -int iswprint(wint_t); -int iswprint_l(wint_t, locale_t); -int iswpunct(wint_t); -int iswpunct_l(wint_t, locale_t); -int iswspace(wint_t); -int iswspace_l(wint_t, locale_t); -int iswupper(wint_t); -int iswupper_l(wint_t, locale_t); -int iswxdigit(wint_t); -int iswxdigit_l(wint_t, locale_t); -wint_t towctrans(wint_t, wctrans_t); -wint_t towctrans_l(wint_t, wctrans_t, locale_t); -wint_t towlower(wint_t); -wint_t towlower_l(wint_t, locale_t); -wint_t towupper(wint_t); -wint_t towupper_l(wint_t, locale_t); -wctrans_t wctrans(const char *); -wctrans_t wctrans_l(const char *, locale_t); -wctype_t wctype(const char *); -wctype_t wctype_l(const char *, locale_t); - -#endif diff --git a/lib/Kbuild b/lib/Kbuild index 78923b86..09d3058e 100644 --- a/lib/Kbuild +++ b/lib/Kbuild @@ -1,2 +1 @@ -obj-y += libjson/ obj-y += libc/ diff --git a/lib/libc/assert/Kbuild b/lib/libc/assert/Kbuild new file mode 100644 index 00000000..98ba0577 --- /dev/null +++ b/lib/libc/assert/Kbuild @@ -0,0 +1 @@ +obj-y += assert.o diff --git a/lib/libc/ctype/Kbuild b/lib/libc/ctype/Kbuild new file mode 100644 index 00000000..6022400b --- /dev/null +++ b/lib/libc/ctype/Kbuild @@ -0,0 +1,14 @@ +obj-y += isalnum.o +obj-y += isalpha.o +obj-y += isblank.o +obj-y += iscntrl.o +obj-y += isdigit.o +obj-y += isgraph.o +obj-y += islower.o +obj-y += isprint.o +obj-y += ispunct.o +obj-y += isspace.o +obj-y += isupper.o +obj-y += isxdigit.o +obj-y += tolower.o +obj-y += toupper.o diff --git a/lib/libc/ctype/isalnum.c b/lib/libc/ctype/isalnum.c index 04e94fc6..3384aa56 100644 --- a/lib/libc/ctype/isalnum.c +++ b/lib/libc/ctype/isalnum.c @@ -6,7 +6,7 @@ int isalnum(int c) return isalpha(c) || isdigit(c); } -weak int isalnum_l(int c, locale_t unused locale) +__weak int isalnum_l(int c, locale_t __unused locale) { return isalnum(c); } diff --git a/lib/libc/ctype/ispunct.c b/lib/libc/ctype/ispunct.c index 2bd08c38..24627809 100644 --- a/lib/libc/ctype/ispunct.c +++ b/lib/libc/ctype/ispunct.c @@ -6,7 +6,7 @@ int ispunct(int c) return isgraph(c) && !isalnum(c); } -weak int ispunct_l(int c, locale_t locale) +__weak int ispunct_l(int c, locale_t __unused locale) { return ispunct(c); } diff --git a/lib/libc/ctype/tolower.c b/lib/libc/ctype/tolower.c index abeab42a..aeb462d8 100644 --- a/lib/libc/ctype/tolower.c +++ b/lib/libc/ctype/tolower.c @@ -8,7 +8,7 @@ int tolower(int c) return c; } -weak int tolower_l(int c, locale_t unused locale) +__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 index e952acd9..934841fa 100644 --- a/lib/libc/ctype/toupper.c +++ b/lib/libc/ctype/toupper.c @@ -8,7 +8,7 @@ int toupper(int c) return c; } -int toupper_l(int c, locale_t unused locale) +int toupper_l(int c, locale_t __unused locale) { return toupper(c); } diff --git a/lib/libc/devctl/Kbuild b/lib/libc/devctl/Kbuild new file mode 100644 index 00000000..922f854e --- /dev/null +++ b/lib/libc/devctl/Kbuild @@ -0,0 +1 @@ +obj-y += posix_devctl.o diff --git a/lib/libc/devctl/posix_devctl.c b/lib/libc/devctl/posix_devctl.c index bc8e7331..b7c24d79 100644 --- a/lib/libc/devctl/posix_devctl.c +++ b/lib/libc/devctl/posix_devctl.c @@ -4,7 +4,7 @@ #include int posix_devctl(int fildes, int dcmd, void *restrict dev_data_ptr, - size_t unused nbyte, int *restrict dev_info_ptr) + size_t __unused nbyte, int *restrict dev_info_ptr) { long r; diff --git a/lib/libc/dirent/Kbuild b/lib/libc/dirent/Kbuild new file mode 100644 index 00000000..355b905c --- /dev/null +++ b/lib/libc/dirent/Kbuild @@ -0,0 +1,6 @@ +obj-y += closedir.o +obj-y += dirfd.o +obj-y += fdopendir.o +obj-y += opendir.o +obj-y += readdir_r.o +obj-y += readdir.o diff --git a/lib/libc/dirent/readdir_r.c b/lib/libc/dirent/readdir_r.c index 9d8bf49b..98b12426 100644 --- a/lib/libc/dirent/readdir_r.c +++ b/lib/libc/dirent/readdir_r.c @@ -29,9 +29,9 @@ int readdir_r(DIR *restrict dirp, struct dirent *restrict entry, ldir = (void *)(dirp->buffer + dirp->offset); /* Validate buffer bounds */ - if (dirp->offset >= sizeof(dirp->buffer) || - dirp->offset + sizeof(struct linux_dirent64) > - sizeof(dirp->buffer)) { + if (dirp->offset >= (off_t)sizeof(dirp->buffer) || + dirp->offset + (off_t)sizeof(struct linux_dirent64) > + (off_t)sizeof(dirp->buffer)) { dirp->cached = 0; *result = NULL; return 0; @@ -40,7 +40,8 @@ int readdir_r(DIR *restrict dirp, struct dirent *restrict entry, /* Validate record length */ if (ldir->d_reclen < offsetof(struct linux_dirent64, d_name) + 1 || - dirp->offset + ldir->d_reclen > sizeof(dirp->buffer) || + dirp->offset + (off_t)ldir->d_reclen > + (off_t)sizeof(dirp->buffer) || ldir->d_reclen == 0) { dirp->cached = 0; *result = NULL; @@ -90,7 +91,7 @@ int readdir_r(DIR *restrict dirp, struct dirent *restrict entry, nread = ret; /* Validate first entry bounds */ - if (nread < sizeof(struct linux_dirent64) || + if (nread < (ssize_t)sizeof(struct linux_dirent64) || ldir->d_reclen < offsetof(struct linux_dirent64, d_name) + 1 || ldir->d_reclen > nread || ldir->d_reclen == 0) { *result = NULL; @@ -124,7 +125,8 @@ int readdir_r(DIR *restrict dirp, struct dirent *restrict entry, (void *)(dirp->buffer + buffer_offset); /* Validate entry bounds to prevent infinite loops */ - if (buffer_offset + sizeof(struct linux_dirent64) > nread || + if (buffer_offset + (ssize_t)sizeof(struct linux_dirent64) > + nread || next_ldir->d_reclen < offsetof(struct linux_dirent64, d_name) + 1 || buffer_offset + next_ldir->d_reclen > nread || diff --git a/lib/libc/endian/Kbuild b/lib/libc/endian/Kbuild new file mode 100644 index 00000000..3fc2c4f1 --- /dev/null +++ b/lib/libc/endian/Kbuild @@ -0,0 +1,12 @@ +obj-y += be16toh.o +obj-y += be32toh.o +obj-y += be64toh.o +obj-y += htobe16.o +obj-y += htobe32.o +obj-y += htobe64.o +obj-y += htole16.o +obj-y += htole32.o +obj-y += htole64.o +obj-y += le16toh.o +obj-y += le32toh.o +obj-y += le64toh.o diff --git a/lib/libc/errno/Kbuild b/lib/libc/errno/Kbuild new file mode 100644 index 00000000..c9db6e67 --- /dev/null +++ b/lib/libc/errno/Kbuild @@ -0,0 +1 @@ +obj-y += errno.o diff --git a/lib/libc/fcntl/Kbuild b/lib/libc/fcntl/Kbuild new file mode 100644 index 00000000..04f1783c --- /dev/null +++ b/lib/libc/fcntl/Kbuild @@ -0,0 +1,6 @@ +obj-y += creat.o +obj-y += fcntl.o +obj-y += open.o +obj-y += openat.o +obj-y += posix_fadvise.o +obj-y += posix_fallocate.o diff --git a/lib/libc/grp/Kbuild b/lib/libc/grp/Kbuild new file mode 100644 index 00000000..698f244a --- /dev/null +++ b/lib/libc/grp/Kbuild @@ -0,0 +1,2 @@ +obj-y += getgrgid_r.o +obj-y += getgrgid.o diff --git a/lib/libc/include/__locale.h b/lib/libc/include/__locale.h deleted file mode 100644 index 0a709c78..00000000 --- a/lib/libc/include/__locale.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __LIBC_LOCALE_H -#define __LIBC_LOCALE_H - -#include -#include - -typedef __SIZE_TYPE__ size_t; - -struct __locale_t { - struct __locale_map { - const void *map; - size_t map_size; - char name[24]; - } maps[6]; -}; - -typedef struct __locale_t *locale_t; - -static const struct __locale_t __c_locale = { 0 }; - -static const struct __locale_t __utf8_locale = { - .maps[LC_CTYPE] = { .map = &((const uint32_t[]){ 0x950412de, 0, -1, -1, - -1 }), - .map_size = sizeof(uint32_t) * 5, - .name = "C.UTF-8" }, -}; - -#undef MB_CUR_MAX -#define MB_CUR_MAX (((locale_t) & __utf8_locale) ? 4 : 1) - -static inline int __mb_cur_max(void) -{ - return MB_CUR_MAX; -} - -static inline int __locale_allocated(locale_t loc) -{ - return loc != (locale_t)&__c_locale && loc != (locale_t)&__utf8_locale; -} - -#endif diff --git a/lib/libc/include/features.h b/lib/libc/include/features.h index 62472259..8f7fa940 100644 --- a/lib/libc/include/features.h +++ b/lib/libc/include/features.h @@ -1,6 +1,6 @@ #ifndef __LIBC_FEATURES_H #define __LIBC_FEATURES_H -#define weak extern __attribute__((weak)) +#define __weak extern __attribute__((weak)) #endif diff --git a/lib/libc/include/io.h b/lib/libc/include/io.h index 675a3cc3..ebda4b22 100644 --- a/lib/libc/include/io.h +++ b/lib/libc/include/io.h @@ -14,25 +14,6 @@ typedef __SIZE_TYPE__ size_t; #define _IO_EOF 0x8 #define _IO_WIDE 0x10 -/* Buffering modes */ -#define _IOFBF 0 /* Full buffering */ -#define _IOLBF 1 /* Line buffering */ -#define _IONBF 2 /* No buffering */ - -/* File access modes */ -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#define O_ACCMODE 3 -#endif - -/* Atomic operations for threading */ -#define LIBC_LOCK(x) \ - while (atomic_flag_test_and_set(&(x))) { \ - } -#define LIBC_UNLOCK(x) atomic_flag_clear(&(x)) - struct __FILE { int fd; uint32_t flags; diff --git a/lib/libc/include/libc.h b/lib/libc/include/libc.h index 3f5f2644..d59c2b3c 100644 --- a/lib/libc/include/libc.h +++ b/lib/libc/include/libc.h @@ -1,14 +1,13 @@ #ifndef __LIBC_LIBC_H #define __LIBC_LIBC_H -#include <__locale.h> #include #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) -#define unused __attribute__((unused)) +#define __unused __attribute__((unused)) #define aligned(type) __attribute__((aligned(__alignof__(type)))) -#define weak __attribute__((__weak__)) +#define __weak __attribute__((__weak__)) #define weak_reference(old, new) \ extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) @@ -21,7 +20,6 @@ static struct { volatile atomic_flag malloc; volatile atomic_flag environ; } lock; - struct __locale_t locale; } libc = { .lock = { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT } }; #endif diff --git a/lib/libc/inttypes/Kbuild b/lib/libc/inttypes/Kbuild new file mode 100644 index 00000000..6a44475c --- /dev/null +++ b/lib/libc/inttypes/Kbuild @@ -0,0 +1,4 @@ +obj-y += imaxabs.o +obj-y += imaxdiv.o +obj-y += strtoimax.o +obj-y += strtoumax.o diff --git a/lib/libc/libc.a b/lib/libc/libc.a new file mode 100644 index 00000000..4f874074 Binary files /dev/null and b/lib/libc/libc.a differ diff --git a/lib/libc/libgen/Kbuild b/lib/libc/libgen/Kbuild new file mode 100644 index 00000000..8143f22a --- /dev/null +++ b/lib/libc/libgen/Kbuild @@ -0,0 +1,2 @@ +obj-y += basename.o +obj-y += dirname.o diff --git a/lib/libc/mman/Kbuild b/lib/libc/mman/Kbuild new file mode 100644 index 00000000..b235d6c9 --- /dev/null +++ b/lib/libc/mman/Kbuild @@ -0,0 +1,9 @@ +obj-y += mlock.o +obj-y += mlockall.o +obj-y += mmap.o +obj-y += mprotect.o +obj-y += msync.o +obj-y += munlock.o +obj-y += munlockall.o +obj-y += munmap.o +obj-y += posix_madvise.o diff --git a/lib/libc/monetary/strfmon.c b/lib/libc/monetary/strfmon.c deleted file mode 100644 index 8ba0d48d..00000000 --- a/lib/libc/monetary/strfmon.c +++ /dev/null @@ -1,131 +0,0 @@ -// Orginal source: -// https://git.musl-libc.org/cgit/musl/tree/src/monetary/strfmon.c -// -// ---------------------------------------------------------------------- -// Copyright © 2005-2020 Rich Felker, et al. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ---------------------------------------------------------------------- - -#include -#include -#include -#include -#include -#include - -static ssize_t vstrfmon_l(char *s, size_t n, const char *fmt, va_list ap) -{ - size_t l; - double x; - int fill, nogrp, negpar, nosym, left, intl; - int lp, rp, w, fw; - char *s0 = s; - for (; n && *fmt;) { - if (*fmt != '%') { -literal: - *s++ = *fmt++; - n--; - continue; - } - fmt++; - if (*fmt == '%') - goto literal; - - fill = ' '; - nogrp = 0; - negpar = 0; - nosym = 0; - left = 0; - for (;; fmt++) { - switch (*fmt) { - case '=': - fill = *++fmt; - continue; - case '^': - nogrp = 1; - continue; - case '(': - negpar = 1; - case '+': - continue; - case '!': - nosym = 1; - continue; - case '-': - left = 1; - continue; - } - break; - } - - for (fw = 0; isdigit(*fmt); fmt++) - fw = 10 * fw + (*fmt - '0'); - lp = 0; - rp = 2; - if (*fmt == '#') - for (lp = 0, fmt++; isdigit(*fmt); fmt++) - lp = 10 * lp + (*fmt - '0'); - if (*fmt == '.') - for (rp = 0, fmt++; isdigit(*fmt); fmt++) - rp = 10 * rp + (*fmt - '0'); - - intl = *fmt++ == 'i'; - - w = lp + 1 + rp; - if (!left && fw > w) - w = fw; - - x = va_arg(ap, double); - l = snprintf(s, n, "%*.*f", w, rp, x); - if (l >= n) { - errno = E2BIG; - return -1; - } - s += l; - n -= l; - } - return s - s0; -} - -ssize_t strfmon(char *restrict s, size_t n, const char *restrict fmt, ...) -{ - va_list ap; - ssize_t ret; - - va_start(ap, fmt); - ret = vstrfmon_l(s, n, fmt, ap); - va_end(ap); - - return ret; -} - -weak ssize_t strfmon_l(char *restrict s, size_t n, locale_t unused loc, - const char *restrict fmt, ...) -{ - va_list ap; - ssize_t ret; - - va_start(ap, fmt); - ret = vstrfmon_l(s, n, fmt, ap); - va_end(ap); - - return ret; -} diff --git a/lib/libc/msg/Kbuild b/lib/libc/msg/Kbuild new file mode 100644 index 00000000..34479132 --- /dev/null +++ b/lib/libc/msg/Kbuild @@ -0,0 +1 @@ +obj-y += msgctl.o diff --git a/lib/libc/poll/Kbuild b/lib/libc/poll/Kbuild new file mode 100644 index 00000000..638ab428 --- /dev/null +++ b/lib/libc/poll/Kbuild @@ -0,0 +1,2 @@ +obj-y += poll.o +obj-y += ppoll.o diff --git a/lib/libc/pwd/Kbuild b/lib/libc/pwd/Kbuild new file mode 100644 index 00000000..698f244a --- /dev/null +++ b/lib/libc/pwd/Kbuild @@ -0,0 +1,2 @@ +obj-y += getgrgid_r.o +obj-y += getgrgid.o diff --git a/lib/libc/select/Kbuild b/lib/libc/select/Kbuild new file mode 100644 index 00000000..0a4fbb56 --- /dev/null +++ b/lib/libc/select/Kbuild @@ -0,0 +1,2 @@ +obj-y += pselect.o +obj-y += select.o diff --git a/lib/libc/sem/Kbuild b/lib/libc/sem/Kbuild new file mode 100644 index 00000000..c0002aa8 --- /dev/null +++ b/lib/libc/sem/Kbuild @@ -0,0 +1,3 @@ +obj-y += semctl.o +obj-y += semget.o +obj-y += semop.o diff --git a/lib/libc/setjmp/Kbuild b/lib/libc/setjmp/Kbuild new file mode 100644 index 00000000..0e6f1418 --- /dev/null +++ b/lib/libc/setjmp/Kbuild @@ -0,0 +1 @@ +obj-y += siglongjmp.o diff --git a/lib/libc/signal/Kbuild b/lib/libc/signal/Kbuild new file mode 100644 index 00000000..b8881c92 --- /dev/null +++ b/lib/libc/signal/Kbuild @@ -0,0 +1,21 @@ +obj-y += kill.o +obj-y += killpg.o +obj-y += psiginfo.o +obj-y += psignal.o +obj-y += pthread_kill.o +obj-y += pthread_sigmask.o +obj-y += raise.o +obj-y += sig2str.o +obj-y += sigaction.o +obj-y += sigaddset.o +obj-y += sigemptyset.o +obj-y += sigismember.o +obj-y += signal.o +obj-y += sigpending.o +obj-y += sigprocmask.o +obj-y += sigqueue.o +obj-y += sigsuspend.o +obj-y += sigtimedwait.o +obj-y += sigwait.o +obj-y += sigwaitinfo.o +obj-y += str2sig.o diff --git a/lib/libc/signal/pthread_sigmask.c b/lib/libc/signal/pthread_sigmask.c index 1b83e1fe..4fcc278f 100644 --- a/lib/libc/signal/pthread_sigmask.c +++ b/lib/libc/signal/pthread_sigmask.c @@ -1,6 +1,7 @@ #include #include #include +#include int sigdelset(sigset_t *, int); int sigismember(const sigset_t *, int); diff --git a/lib/libc/socket/Kbuild b/lib/libc/socket/Kbuild new file mode 100644 index 00000000..18a25e8a --- /dev/null +++ b/lib/libc/socket/Kbuild @@ -0,0 +1,19 @@ +obj-y += accept.o +obj-y += accept4.o +obj-y += bind.o +obj-y += connect.o +obj-y += getpeername.o +obj-y += getsockname.o +obj-y += getsockopt.o +obj-y += listen.o +obj-y += recv.o +obj-y += recvfrom.o +obj-y += recvmsg.o +obj-y += send.o +obj-y += sendmsg.o +obj-y += sendto.o +obj-y += setsockopt.o +obj-y += shutdown.o +obj-y += sockatmark.o +obj-y += socket.o +obj-y += socketpair.o diff --git a/lib/libc/socket/listen.c b/lib/libc/socket/listen.c index 3b107450..2866fe27 100644 --- a/lib/libc/socket/listen.c +++ b/lib/libc/socket/listen.c @@ -3,5 +3,5 @@ int listen(int socket, int backlog) { - return syscall(listen, backlog); + return syscall(listen, socket, backlog); } diff --git a/lib/libc/stat/Kbuild b/lib/libc/stat/Kbuild new file mode 100644 index 00000000..edb6dbe0 --- /dev/null +++ b/lib/libc/stat/Kbuild @@ -0,0 +1,16 @@ +obj-y += chmod.o +obj-y += fchmod.o +obj-y += fchmodat.o +obj-y += fstat.o +obj-y += fstatat.o +obj-y += futimens.o +obj-y += lstat.o +obj-y += mkdir.o +obj-y += mkdirat.o +obj-y += mkfifo.o +obj-y += mkfifoat.o +obj-y += mknod.o +obj-y += mknodat.o +obj-y += stat.o +obj-y += umask.o +obj-y += utimensat.o diff --git a/lib/libc/stat/fstatat.c b/lib/libc/stat/fstatat.c index 06b00163..d7aecbc5 100644 --- a/lib/libc/stat/fstatat.c +++ b/lib/libc/stat/fstatat.c @@ -1,7 +1,8 @@ -#include -#include - #include +#define __BITS_STAT_H_ +#include +#undef __BITS_STAT_H_ +#include #define makedev(major, minor) \ ((((major) & 0xfffff000ULL) << 32) | \ @@ -37,8 +38,7 @@ int fstatat(int fd, const char *restrict path, struct stat *restrict buf, buf->st_blksize = stx.stx_blksize; buf->st_blocks = stx.stx_blocks; } else { - ret = -1; // Indicate failure if STATX_BASIC_STATS is - // not set + ret = -1; } } diff --git a/lib/libc/statvfs/Kbuild b/lib/libc/statvfs/Kbuild new file mode 100644 index 00000000..e57d3f75 --- /dev/null +++ b/lib/libc/statvfs/Kbuild @@ -0,0 +1,2 @@ +obj-y += fstatvfs.o +obj-y += statvfs.o diff --git a/lib/libc/stdio/Kbuild b/lib/libc/stdio/Kbuild new file mode 100644 index 00000000..36339313 --- /dev/null +++ b/lib/libc/stdio/Kbuild @@ -0,0 +1,48 @@ +obj-y += asprintf.o +obj-y += clearerr.o +obj-y += dprintf.o +obj-y += dtoa.o +obj-y += fclose.o +obj-y += fdopen.o +obj-y += feof.o +obj-y += ferror.o +obj-y += fflush.o +obj-y += fgetc.o +obj-y += fgets.o +obj-y += fileno.o +obj-y += fmemopen.o +obj-y += fopen.o +obj-y += fprintf.o +obj-y += fputc.o +obj-y += fputs.o +obj-y += fread.o +obj-y += fseek.o +obj-y += ftell.o +obj-y += ftello.o +obj-y += fwrite.o +obj-y += getc.o +obj-y += getchar.o +obj-y += pclose.o +obj-y += perror.o +obj-y += popen.o +obj-y += printf.o +obj-y += putc.o +obj-y += putchar.o +obj-y += puts.o +obj-y += remove.o +obj-y += rename.o +obj-y += renameat.o +obj-y += rewind.o +obj-y += setbuf.o +obj-y += setvbuf.o +obj-y += snprintf.o +obj-y += sprintf.o +obj-y += stderr.o +obj-y += stdin.o +obj-y += stdout.o +obj-y += vasprintf.o +obj-y += vdprintf.o +obj-y += vfprintf.o +obj-y += vprintf.o +obj-y += vsnprintf.o +obj-y += vsprintf.o diff --git a/lib/libc/stdio/dtoa.c b/lib/libc/stdio/dtoa.c index 9417fa8e..9b0eea99 100644 --- a/lib/libc/stdio/dtoa.c +++ b/lib/libc/stdio/dtoa.c @@ -1598,7 +1598,9 @@ static Bigint *Balloc(int k MTd) len = (sizeof(Bigint) + (x - 1) * sizeof(ULong) + sizeof(double) - 1) / sizeof(double); - if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem + if (k <= Kmax && + (long)(pmem_next - private_mem) + (long)len <= + (long)PRIVATE_mem #ifdef MULTIPLE_THREADS && TI == TI1 #endif @@ -4891,7 +4893,8 @@ static char *rv_alloc(int i MTd) int j, k, *r; j = sizeof(ULong); - for (k = 0; sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i; + for (k = 0; + sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= (size_t)i; j <<= 1) k++; r = (int *)Balloc(k MTa); @@ -4910,7 +4913,7 @@ static char *nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, if (!s0) s0 = rv_alloc(n MTa); - else if (s0len <= n) { + else if (s0len <= (size_t)n) { rv = 0; t = rv + n; goto rve_chk; @@ -5312,7 +5315,7 @@ char *dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, blen = sizeof(Bigint) + ((1 << ((int *)buf)[-1]) - 1) * sizeof(ULong) - sizeof(int); - } else if (blen <= i) { + } else if (blen <= (size_t)i) { buf = 0; if (rve) *rve = buf + i; diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index f2ce0693..23f94843 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -3,7 +3,7 @@ #include #include -weak void __stdio_cleanup(void) +__weak void __stdio_cleanup(void) { } diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index f9a2004d..9af9ca2d 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -4,6 +4,7 @@ #include #include #include +#include int fflush(FILE *stream) { diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index 1ad86f7b..6830dcbe 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -6,7 +6,7 @@ #include #include -weak void __stdio_cleanup(void) +__weak void __stdio_cleanup(void) { } diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index 7d01fd38..1f15820b 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -7,7 +7,7 @@ #include #include -weak void __stdio_cleanup(void) +__weak void __stdio_cleanup(void) { } diff --git a/lib/libc/stdio/fprintf.c b/lib/libc/stdio/fprintf.c index 4283b424..c0d14a48 100644 --- a/lib/libc/stdio/fprintf.c +++ b/lib/libc/stdio/fprintf.c @@ -6,7 +6,7 @@ int fprintf(FILE *restrict stream, const char *restrict format, ...) int r; va_list ap; va_start(ap, format); - r = vfprintf(stdout, format, ap); + r = vfprintf(stream, format, ap); va_end(ap); return r; } diff --git a/lib/libc/stdio/stdin.c b/lib/libc/stdio/stdin.c index bcc2eca6..329c9528 100644 --- a/lib/libc/stdio/stdin.c +++ b/lib/libc/stdio/stdin.c @@ -6,7 +6,7 @@ #define BUFSIZ 4096 #define _IOLBF 0x1 -weak char __stdin_buffer[0]; +__weak char __stdin_buffer[0]; struct __FILE __stdin = { .fd = STDOUT_FILENO, .flags = O_RDONLY, .buf = __stdin_buffer, diff --git a/lib/libc/stdio/stdout.c b/lib/libc/stdio/stdout.c index 7d55c3e7..3645e07d 100644 --- a/lib/libc/stdio/stdout.c +++ b/lib/libc/stdio/stdout.c @@ -6,7 +6,7 @@ #define BUFSIZ 4096 -weak char __stdout_buffer[0]; +__weak char __stdout_buffer[0]; static atomic_flag __stdio_lock = ATOMIC_FLAG_INIT; struct __FILE __stdout = { .fd = STDOUT_FILENO, .flags = O_WRONLY, diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index fb4c200e..495fb9ea 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -9,7 +9,6 @@ #include #include #include -#include extern char *dtoa(double, int mode, int ndigits, int *decpt, int *sign, char **rve); @@ -752,15 +751,12 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) if ((flags & FLAG_MINUS) == 0) { if (pad_char == '0' && s != NULL) { - int prefix_len = 0; - if (s[0] == '-' || s[0] == '+' || s[0] == ' ') { fwrite(s, 1, 1, stream); total_printed++; s++; l--; - prefix_len++; } if (l >= 2 && s[0] == '0' && @@ -769,7 +765,6 @@ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) total_printed += 2; s += 2; l -= 2; - prefix_len += 2; } for (int i = 0; i < padding; i++) { diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index b7a59064..7afae866 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -3,6 +3,7 @@ #include #include #include +#include int vsnprintf(char *restrict s, size_t n, const char *restrict format, va_list ap) diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 3d29e6a8..555a45bc 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -28,7 +28,7 @@ static __inline uint32_t get_size_class(size_t size) return (uint32_t)((most_significant_bit << 2) + subclass_bits) + 41; } -weak void *malloc(size_t size); +__weak void *malloc(size_t size); void *malloc(size_t size) { diff --git a/lib/libc/string/Kbuild b/lib/libc/string/Kbuild new file mode 100644 index 00000000..6fec9c43 --- /dev/null +++ b/lib/libc/string/Kbuild @@ -0,0 +1,32 @@ +obj-y += memccpy.o +obj-y += memchr.o +obj-y += memcmp.o +obj-y += memcpy.o +obj-y += memmem.o +obj-y += memmove.o +obj-y += memset.o +obj-y += stpcpy.o +obj-y += stpncpy.o +obj-y += strcat.o +obj-y += strchr.o +obj-y += strcmp.o +obj-y += strcoll.o +obj-y += strcpy.o +obj-y += strcspn.o +obj-y += strdup.o +obj-y += strerror.o +obj-y += strlcat.o +obj-y += strlcpy.o +obj-y += strlen.o +obj-y += strncat.o +obj-y += strncmp.o +obj-y += strncpy.o +obj-y += strndup.o +obj-y += strnlen.o +obj-y += strpbrk.o +obj-y += strrchr.o +obj-y += strspn.o +obj-y += strstr.o +obj-y += strtok_r.o +obj-y += strtok.o +obj-y += strxfrm.o diff --git a/lib/libc/string/memcpy.c b/lib/libc/string/memcpy.c index 505cc622..ecdbd602 100644 --- a/lib/libc/string/memcpy.c +++ b/lib/libc/string/memcpy.c @@ -1,7 +1,7 @@ #include #include -weak void *memcpy(void *restrict s1, const void *restrict s2, size_t n); +__weak void *memcpy(void *restrict s1, const void *restrict s2, size_t n); void *memcpy(void *restrict s1, const void *restrict s2, size_t n) { diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c index 6b2e532a..6efaa3d3 100644 --- a/lib/libc/string/strcoll.c +++ b/lib/libc/string/strcoll.c @@ -7,7 +7,7 @@ int strcoll(const char *s1, const char *s2) return strcmp(s1, s2); } -weak int strcoll_l(const char *s1, const char *s2, locale_t unused locale) +__weak int strcoll_l(const char *s1, const char *s2, locale_t __unused locale) { return strcoll(s1, s2); } diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index 1d5903cb..c091ac79 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -119,7 +119,7 @@ int strerror_r(int errnum, char *buf, size_t buflen) return 0; } -weak char *strerror_l(int errnum, locale_t unused locale) +__weak char *strerror_l(int errnum, locale_t __unused locale) { return strerror(errnum); } diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c index d62d0a96..123ebfe8 100644 --- a/lib/libc/string/strxfrm.c +++ b/lib/libc/string/strxfrm.c @@ -11,8 +11,8 @@ size_t strxfrm(char *restrict s1, const char *restrict s2, size_t n) return len; } -weak size_t strxfrm_l(char *restrict s1, const char *restrict s2, size_t n, - locale_t unused locale) +__weak size_t strxfrm_l(char *restrict s1, const char *restrict s2, size_t n, + locale_t __unused locale) { return strxfrm(s1, s2, n); } diff --git a/lib/libc/strings/Kbuild b/lib/libc/strings/Kbuild new file mode 100644 index 00000000..0f22da20 --- /dev/null +++ b/lib/libc/strings/Kbuild @@ -0,0 +1,5 @@ +obj-y += ffs.o +obj-y += ffsl.o +obj-y += ffsll.o +obj-y += strcasecmp.o +obj-y += strncasecmp.o diff --git a/lib/libc/strings/ffs.c b/lib/libc/strings/ffs.c index 3b836021..2c49cf4d 100644 --- a/lib/libc/strings/ffs.c +++ b/lib/libc/strings/ffs.c @@ -1,7 +1,8 @@ int ffs(int i) { - if (i == 0) + if (i == 0) { return 0; + } int pos = 1; unsigned int u = (unsigned int)i; @@ -10,5 +11,6 @@ int ffs(int i) u >>= 1; pos++; } + return pos; } diff --git a/lib/libc/strings/ffsl.c b/lib/libc/strings/ffsl.c index 2f2e7d44..c84a2905 100644 --- a/lib/libc/strings/ffsl.c +++ b/lib/libc/strings/ffsl.c @@ -1,14 +1,18 @@ int ffsl(long i) { - if (i == 0) - return 0; + int pos; + unsigned long u; - int pos = 1; - unsigned long u = (unsigned long)i; + if (i == 0) { + return 0; + } + pos = 1; + u = (unsigned long)i; while ((u & 1UL) == 0UL) { u >>= 1; pos++; } + return pos; } diff --git a/lib/libc/strings/strcasecmp.c b/lib/libc/strings/strcasecmp.c index 90ccc59b..e96f059a 100644 --- a/lib/libc/strings/strcasecmp.c +++ b/lib/libc/strings/strcasecmp.c @@ -18,7 +18,8 @@ int strcasecmp(const char *s1, const char *s2) (unsigned char)tolower((unsigned char)*s2); } -weak int strcasecmp_l(const char *s1, const char *s2, locale_t unused locale) +__weak int strcasecmp_l(const char *s1, const char *s2, + locale_t __unused locale) { return strcasecmp(s1, s2); } diff --git a/lib/libc/strings/strncasecmp.c b/lib/libc/strings/strncasecmp.c index 679cf245..f2f4c22c 100644 --- a/lib/libc/strings/strncasecmp.c +++ b/lib/libc/strings/strncasecmp.c @@ -25,8 +25,8 @@ int strncasecmp(const char *s1, const char *s2, size_t n) (unsigned char)tolower((unsigned char)*s2); } -weak int strncasecmp_l(const char *s1, const char *s2, size_t n, - locale_t unused locale) +__weak int strncasecmp_l(const char *s1, const char *s2, size_t n, + locale_t __unused locale) { return strncasecmp(s1, s2, n); } diff --git a/lib/libc/sys/Kbuild b/lib/libc/sys/Kbuild new file mode 100644 index 00000000..eedb3527 --- /dev/null +++ b/lib/libc/sys/Kbuild @@ -0,0 +1,4 @@ +obj-y += ioctl.o +obj-y += mount.o +obj-y += umount.o +obj-y += umount2.o diff --git a/lib/libc/syslog/Kbuild b/lib/libc/syslog/Kbuild new file mode 100644 index 00000000..23a1ce51 --- /dev/null +++ b/lib/libc/syslog/Kbuild @@ -0,0 +1,4 @@ +obj-y += closelog.o +obj-y += openlog.o +obj-y += setlogmask.o +obj-y += syslog.o diff --git a/lib/libc/syslog/openlog.c b/lib/libc/syslog/openlog.c index 84c4797f..0abf8bb8 100644 --- a/lib/libc/syslog/openlog.c +++ b/lib/libc/syslog/openlog.c @@ -2,6 +2,7 @@ int setlogmask(int maskpri) { + (void)maskpri; // TODO return 0; } diff --git a/lib/libc/syslog/setlogmask.c b/lib/libc/syslog/setlogmask.c index 84c4797f..0abf8bb8 100644 --- a/lib/libc/syslog/setlogmask.c +++ b/lib/libc/syslog/setlogmask.c @@ -2,6 +2,7 @@ int setlogmask(int maskpri) { + (void)maskpri; // TODO return 0; } diff --git a/lib/libc/syslog/syslog.c b/lib/libc/syslog/syslog.c index a9a41fbb..53aec084 100644 --- a/lib/libc/syslog/syslog.c +++ b/lib/libc/syslog/syslog.c @@ -2,6 +2,8 @@ void syslog(int priority, const char *message, ... /* arguments */) { + (void)priority; + (void)message; // TODO return; } diff --git a/lib/libc/time/strftime.c b/lib/libc/time/strftime.c index d359140b..f0881eb1 100644 --- a/lib/libc/time/strftime.c +++ b/lib/libc/time/strftime.c @@ -553,10 +553,10 @@ size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, return s - orig_s; } -weak size_t strftime_l(char *restrict s, size_t maxsize, +__weak size_t strftime_l(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr, - locale_t unused locale) + locale_t __unused locale) { return strftime(s, maxsize, format, timeptr); } diff --git a/lib/libc/uio/Kbuild b/lib/libc/uio/Kbuild new file mode 100644 index 00000000..3b6a16c4 --- /dev/null +++ b/lib/libc/uio/Kbuild @@ -0,0 +1,2 @@ +obj-y += readv.o +obj-y += writev.o diff --git a/lib/libc/unistd/Kbuild b/lib/libc/unistd/Kbuild new file mode 100644 index 00000000..ff3f025a --- /dev/null +++ b/lib/libc/unistd/Kbuild @@ -0,0 +1,77 @@ +obj-y += _exit.o +obj-y += _Fork.o +obj-y += access.o +obj-y += alarm.o +obj-y += chdir.o +obj-y += chown.o +obj-y += close.o +obj-y += dup.o +obj-y += dup2.o +obj-y += dup3.o +obj-y += execl.o +obj-y += execlp.o +obj-y += execv.o +obj-y += execve.o +obj-y += execvp.o +obj-y += faccessat.o +obj-y += fchdir.o +obj-y += fchown.o +obj-y += fchownat.o +obj-y += fdatasync.o +obj-y += fork.o +obj-y += fsync.o +obj-y += ftruncate.o +obj-y += getcwd.o +obj-y += getegid.o +obj-y += getentropy.o +obj-y += geteuid.o +obj-y += getgid.o +obj-y += getgroups.o +obj-y += gethostid.o +obj-y += gethostname.o +obj-y += getlogin_r.o +obj-y += getlogin.o +obj-y += getopt.o +obj-y += getpgid.o +obj-y += getpid.o +obj-y += getppid.o +obj-y += getresgid.o +obj-y += getresuid.o +obj-y += getsid.o +obj-y += getuid.o +obj-y += isatty.o +obj-y += lchown.o +obj-y += link.o +obj-y += linkat.o +obj-y += lockf.o +obj-y += lseek.o +obj-y += nice.o +obj-y += pause.o +obj-y += pipe.o +obj-y += pipe2.o +obj-y += posix_close.o +obj-y += pread.o +obj-y += pwrite.o +obj-y += read.o +obj-y += readlink.o +obj-y += readlinkat.o +obj-y += rmdir.o +obj-y += setegid.o +obj-y += seteuid.o +obj-y += setgid.o +obj-y += setpgid.o +obj-y += setregid.o +obj-y += setresgid.o +obj-y += setresuid.o +obj-y += setreuid.o +obj-y += setsid.o +obj-y += setuid.o +obj-y += sleep.o +obj-y += swab.o +obj-y += symlink.o +obj-y += symlinkat.o +obj-y += sync.o +obj-y += truncate.o +obj-y += unlink.o +obj-y += unlinkat.o +obj-y += write.o diff --git a/lib/libc/unistd/execlp.c b/lib/libc/unistd/execlp.c index 4613a7ee..db044d50 100644 --- a/lib/libc/unistd/execlp.c +++ b/lib/libc/unistd/execlp.c @@ -1,8 +1,6 @@ #include -#include -#include +#include -// TODO: need to find in path and call execl int execlp(const char *path, const char *argv0, ...) { int argc; @@ -23,5 +21,5 @@ int execlp(const char *path, const char *argv0, ...) argv[argc] = NULL; va_end(ap); - return syscall(execve, path, argv, 0); + return execve(path, argv, 0); } diff --git a/lib/libc/unistd/execvp.c b/lib/libc/unistd/execvp.c index 2ce69354..ae8ecdb9 100644 --- a/lib/libc/unistd/execvp.c +++ b/lib/libc/unistd/execvp.c @@ -3,6 +3,7 @@ #include #include #include +#include extern char **environ; @@ -17,7 +18,7 @@ int execvp(const char *file, char *const argv[]) return execv(file, argv); } else { char *ptr; - char *path = NULL; // TODO: getenv + char *path = getenv("PATH"); if (path == NULL || *path == '\0') { path = "/bin"; diff --git a/lib/libc/unistd/getentropy.c b/lib/libc/unistd/getentropy.c index f55fed7a..3a651ba5 100644 --- a/lib/libc/unistd/getentropy.c +++ b/lib/libc/unistd/getentropy.c @@ -3,6 +3,8 @@ int getentropy(void *buffer, size_t length) { + (void)buffer; + (void)length; // TODO return 0; } diff --git a/lib/libc/unistd/gethostname.c b/lib/libc/unistd/gethostname.c index a20808e1..5bd303f5 100644 --- a/lib/libc/unistd/gethostname.c +++ b/lib/libc/unistd/gethostname.c @@ -3,6 +3,8 @@ int gethostname(char *name, size_t namelen) { + (void)name; + (void)namelen; // TODO return 0; } diff --git a/lib/libc/unistd/getlogin_r.c b/lib/libc/unistd/getlogin_r.c index 3dea2dff..70ae5ddd 100644 --- a/lib/libc/unistd/getlogin_r.c +++ b/lib/libc/unistd/getlogin_r.c @@ -3,6 +3,8 @@ int getlogin_r(char *name, size_t namesize) { + (void)name; + (void)namesize; // TODO return 0; } diff --git a/lib/libc/unistd/lockf.c b/lib/libc/unistd/lockf.c index 8b807c34..6f109c55 100644 --- a/lib/libc/unistd/lockf.c +++ b/lib/libc/unistd/lockf.c @@ -3,6 +3,9 @@ int lockf(int fildes, int function, off_t size) { + (void)fildes; + (void)function; + (void)size; // TODO return 0; } diff --git a/lib/libc/unistd/nice.c b/lib/libc/unistd/nice.c index 3b240c93..6da984df 100644 --- a/lib/libc/unistd/nice.c +++ b/lib/libc/unistd/nice.c @@ -3,6 +3,7 @@ int nice(int incr) { + (void)incr; // TODO: needs getpriority and setpriority from sys/resouce.h return 0; } diff --git a/lib/libc/unistd/posix_close.c b/lib/libc/unistd/posix_close.c index fe44a7b9..78ec692e 100644 --- a/lib/libc/unistd/posix_close.c +++ b/lib/libc/unistd/posix_close.c @@ -1,7 +1,7 @@ #include #include -int posix_close(int fildes, int unused flag) +int posix_close(int fildes, int __unused flag) { return syscall(close, fildes); } diff --git a/lib/libc/utsname/Kbuild b/lib/libc/utsname/Kbuild new file mode 100644 index 00000000..43c7392c --- /dev/null +++ b/lib/libc/utsname/Kbuild @@ -0,0 +1 @@ +obj-y += uname.o diff --git a/lib/libc/wait/Kbuild b/lib/libc/wait/Kbuild new file mode 100644 index 00000000..f1dad549 --- /dev/null +++ b/lib/libc/wait/Kbuild @@ -0,0 +1,3 @@ +obj-y += wait.o +obj-y += waitid.o +obj-y += waitpid.o diff --git a/lib/libc/wchar/wctob.c b/lib/libc/wchar/wctob.c deleted file mode 100644 index 702e3f75..00000000 --- a/lib/libc/wchar/wctob.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -#define IS_CODEUNIT(c) ((unsigned)(c) - 0xdf80 < 0x80) - -int wctob(wint_t c) -{ - if (c < 128U) - return (int)c; - - if (MB_CUR_MAX == 1 && IS_CODEUNIT(c)) - return (unsigned char)c; - - return EOF; -} diff --git a/lib/libc/wctype/iswalnum.c b/lib/libc/wctype/iswalnum.c deleted file mode 100644 index 3eb2f14f..00000000 --- a/lib/libc/wctype/iswalnum.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int iswalnum(wint_t wc) -{ - return iswdigit(wc) || iswalpha(wc); -} - -weak int iswalnum_l(wint_t wc, locale_t unused locale) -{ - return iswalnum(wc); -} diff --git a/lib/libc/wctype/iswalpha.c b/lib/libc/wctype/iswalpha.c deleted file mode 100644 index 17c8508c..00000000 --- a/lib/libc/wctype/iswalpha.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -int iswalpha(wint_t wc) -{ - const unsigned char t[] = { -#include <__alpha.h> - }; - - if (wc < 0x20000U) - return (t[t[wc >> 8] * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1; - - if (wc < 0x2fffeU) - return 1; - - return 0; -} - -weak int iswalpha_l(wint_t wc, locale_t unused locale) -{ - return iswalpha(wc); -} diff --git a/lib/libc/wctype/iswblank.c b/lib/libc/wctype/iswblank.c deleted file mode 100644 index 61664162..00000000 --- a/lib/libc/wctype/iswblank.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -int iwsblank(wint_t wc) -{ - return isblank((unsigned char)wc); -} - -weak int iswblank_l(wint_t c, locale_t unused locale) -{ - return iswblank(c); -} diff --git a/lib/libc/wctype/iswdigit.c b/lib/libc/wctype/iswdigit.c deleted file mode 100644 index e775f561..00000000 --- a/lib/libc/wctype/iswdigit.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int iswdigit(wint_t wc) -{ - return (wc >= L'0' && wc <= L'9'); -} - -weak int iswdigit_l(wint_t wc, locale_t unused locale) -{ - return iswdigit(wc); -} diff --git a/lib/libc/wctype/iswgraph.c b/lib/libc/wctype/iswgraph.c deleted file mode 100644 index 00ab6cca..00000000 --- a/lib/libc/wctype/iswgraph.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int iswgraph(wint_t wc) -{ - return iswprint(wc) && !iswspace(wc); -} - -weak int iswgraph_l(wint_t wc, locale_t unused locale) -{ - return iswgraph(wc); -} diff --git a/lib/libc/wctype/iswlower.c b/lib/libc/wctype/iswlower.c deleted file mode 100644 index dea58f3a..00000000 --- a/lib/libc/wctype/iswlower.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int iswlower(wint_t wc) -{ - return towupper(wc) != wc; -} - -weak int islower_l(wint_t wc, locale_t unused locale) -{ - return iswlower(wc); -} diff --git a/lib/libc/wctype/iswprint.c b/lib/libc/wctype/iswprint.c deleted file mode 100644 index f0b26fbf..00000000 --- a/lib/libc/wctype/iswprint.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int iswprint(wint_t wc) -{ - return (wc >= 0x20 && wc <= 0x7E) || - (wc >= 0xA0 && wc <= 0x10FFFF && (wc < 0xFDD0 || wc > 0xFDEF) && - (wc & 0xFFFE) != 0xFFFE); -} - -weak int iswprint_l(wint_t wc, locale_t unused locale) -{ - return iswprint(wc); -} diff --git a/lib/libc/wctype/iswpunct.c b/lib/libc/wctype/iswpunct.c deleted file mode 100644 index d7ed6487..00000000 --- a/lib/libc/wctype/iswpunct.c +++ /dev/null @@ -1,327 +0,0 @@ -#include -#include - -int iswpunct(wint_t wc) -{ - const unsigned char t[] = { - 18, 16, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 16, 16, 34, 35, 16, 36, 37, 38, 39, - 40, 41, 42, 43, 16, 44, 45, 46, 17, 17, 47, 17, 17, - 17, 17, 17, 17, 48, 49, 50, 51, 52, 53, 54, 55, 17, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 56, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 57, 16, 58, 59, 60, - 61, 62, 63, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 64, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 65, 16, 16, 66, 16, 67, 68, 69, 16, 70, 71, 72, - 16, 73, 16, 16, 74, 75, 76, 77, 78, 16, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 16, 92, 93, - 94, 95, 16, 16, 16, 16, 96, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 97, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 98, 99, - 16, 16, 100, 101, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 102, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 103, 104, 105, 106, - 16, 16, 107, 108, 17, 17, 109, 16, 16, 16, 16, 16, 16, - 110, 111, 16, 16, 16, 16, 16, 112, 113, 16, 16, 114, 115, - 116, 16, 117, 118, 119, 17, 17, 17, 120, 121, 122, 123, 124, - 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 0, 0, 0, 0, 254, 255, 0, 252, 1, - 0, 0, 248, 1, 0, 0, 120, 0, 0, 0, 0, 255, 251, - 223, 251, 0, 0, 128, 0, 0, 0, 128, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 252, 255, 224, - 175, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 223, 255, - 255, 255, 255, 255, 32, 64, 176, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252, - 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 252, 0, 0, 0, 0, 0, 230, 254, 255, 255, 255, 0, 64, - 73, 0, 0, 0, 0, 0, 24, 0, 255, 255, 0, 216, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 60, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 16, 224, 1, 30, 0, - 96, 255, 191, 0, 0, 0, 0, 0, 0, 255, 7, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 248, 207, 227, 0, 0, 0, 3, 0, 32, - 255, 127, 0, 0, 0, 78, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 8, 0, 7, 252, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 16, 0, 32, 30, 0, 48, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 32, - 0, 0, 0, 0, 252, 111, 0, 0, 0, 0, 0, 0, 0, - 16, 0, 32, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, - 0, 0, 0, 16, 0, 32, 0, 0, 0, 0, 3, 224, 0, - 0, 0, 0, 0, 0, 0, 16, 0, 32, 0, 0, 0, 0, - 253, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, - 0, 0, 0, 255, 7, 16, 0, 0, 0, 0, 0, 0, 0, - 0, 32, 0, 0, 0, 0, 128, 255, 16, 0, 0, 0, 0, - 0, 0, 16, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 24, 0, 160, 0, 127, 0, 0, 255, - 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, - 0, 0, 16, 0, 0, 0, 0, 0, 0, 128, 0, 128, 192, - 223, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 4, 0, 31, 0, 0, 0, 0, 0, 0, 254, 255, 255, - 255, 0, 252, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, - 252, 0, 0, 0, 0, 0, 0, 192, 255, 223, 255, 7, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 6, 0, 252, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 224, 255, 255, 255, 31, 0, - 0, 255, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 1, 0, - 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 0, - 0, 0, 0, 16, 0, 0, 0, 112, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, - 254, 127, 47, 0, 0, 255, 3, 255, 127, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 14, 49, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 196, 255, 255, 255, 255, 0, 0, 0, 192, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 224, 159, 0, 0, 0, 0, - 127, 63, 255, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 16, 0, 16, 0, 0, 252, 255, 255, - 255, 31, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, - 0, 64, 0, 12, 240, 0, 0, 0, 0, 0, 0, 128, 248, - 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, - 0, 0, 0, 255, 0, 255, 255, 255, 33, 144, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, - 127, 0, 224, 251, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 160, 3, 224, 0, 224, 0, 224, 0, 96, 128, 248, 255, - 255, 255, 252, 255, 255, 255, 255, 255, 127, 223, 255, 241, 127, - 255, 127, 0, 0, 255, 255, 255, 255, 0, 0, 255, 255, 255, - 255, 1, 0, 123, 3, 208, 193, 175, 66, 0, 12, 31, 188, - 255, 255, 0, 0, 0, 0, 0, 14, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 127, 0, 0, 0, 255, 7, 0, 0, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 63, 0, 0, 0, 0, 0, 0, 252, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 207, 255, 255, 255, 63, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 135, 3, - 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 127, - 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 255, 255, - 251, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 15, 0, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 63, 0, 0, 0, 255, 15, 30, 255, 255, 255, 1, 252, 193, - 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 255, 255, 0, 0, 0, 0, 255, 255, 255, - 255, 15, 0, 0, 0, 255, 255, 255, 127, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, - 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, - 255, 255, 127, 0, 0, 0, 0, 0, 0, 192, 0, 224, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 15, 112, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 255, 0, 255, 255, 127, 0, 3, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, - 0, 15, 255, 3, 0, 0, 0, 0, 0, 0, 240, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 16, 192, 0, 0, 255, 255, - 3, 23, 0, 0, 0, 0, 0, 248, 0, 0, 0, 0, 8, - 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, - 255, 63, 0, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 240, 0, 0, 128, 3, 0, 0, - 0, 0, 0, 0, 0, 128, 2, 0, 0, 192, 0, 0, 67, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 56, 0, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 252, 255, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 48, 255, 255, 255, 3, 255, 255, 255, 255, - 255, 255, 247, 255, 127, 15, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 254, 255, - 0, 252, 1, 0, 0, 248, 1, 0, 0, 248, 63, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 127, 127, 0, 48, 135, 255, 255, 255, 255, 255, 143, 255, 0, - 0, 0, 0, 0, 0, 224, 255, 255, 127, 255, 15, 1, 0, - 0, 0, 0, 0, 255, 255, 255, 255, 255, 63, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, - 255, 255, 15, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, - 255, 0, 0, 128, 255, 0, 0, 0, 0, 128, 255, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 248, 0, 0, 192, 143, 0, - 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 48, 255, 255, 252, 255, 255, 255, 255, - 255, 0, 0, 0, 0, 0, 0, 0, 135, 255, 1, 255, 1, - 0, 0, 0, 224, 0, 0, 0, 224, 0, 0, 0, 0, 0, - 1, 0, 0, 96, 248, 127, 0, 0, 0, 0, 0, 0, 0, - 0, 254, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, - 30, 0, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 252, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 255, 255, 255, 127, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 224, 127, 0, 0, 0, 192, 255, 255, 3, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 192, 63, 252, 255, 63, 0, 0, 128, 3, 0, 0, 0, 0, - 0, 0, 254, 3, 32, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 24, 0, 15, 0, 0, 0, 0, 0, 56, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 63, 0, 232, - 254, 255, 31, 0, 0, 0, 0, 0, 0, 0, 96, 63, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 24, 0, 32, 0, 0, 192, 31, 31, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 248, - 0, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 14, 0, 0, - 0, 255, 31, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 8, 0, 252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 252, 7, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 24, 128, 255, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 223, 7, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 128, 62, 0, 0, 252, 255, 31, 3, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, - 255, 255, 3, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0, 0, 0, - 0, 0, 255, 255, 48, 0, 0, 248, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 176, 15, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 0, - 255, 255, 255, 255, 127, 254, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 1, 0, 0, 255, 255, 255, 255, 255, 255, 255, - 255, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 15, 0, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 0, 255, 255, - 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 8, 0, 0, 0, 8, 0, 0, - 32, 0, 0, 0, 32, 0, 0, 128, 0, 0, 0, 128, 0, - 0, 0, 2, 0, 0, 0, 2, 0, 0, 8, 0, 0, 0, - 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 15, 0, 248, 254, 255, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 127, 0, 0, 128, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 240, 0, 128, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 128, 255, 127, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 7, 0, - 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, - 255, 255, 255, 255, 31, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 254, 255, 255, 255, 255, 255, 255, 63, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 255, 255, 255, 255, 255, 15, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 15, 0, 255, 127, 254, 255, 254, 255, - 254, 255, 255, 255, 63, 0, 255, 31, 255, 255, 255, 255, 0, - 0, 0, 252, 0, 0, 0, 28, 0, 0, 0, 252, 255, 255, - 255, 31, 0, 0, 0, 0, 0, 0, 192, 255, 255, 255, 7, - 0, 255, 255, 255, 255, 255, 15, 255, 1, 3, 0, 63, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 63, 0, 255, 31, 255, 7, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 15, - 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, - 255, 15, 0, 0, 255, 15, 255, 255, 255, 255, 255, 255, 255, - 0, 255, 3, 255, 255, 255, 255, 255, 0, 255, 255, 255, 63, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 239, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 123, 252, - 255, 255, 255, 255, 231, 199, 255, 255, 255, 231, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 15, 0, 255, 63, 15, 7, 7, 0, 63, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - - }; - - if (wc < 0x20000U) - return (t[t[wc >> 8] * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1; - - return 0; -} - -weak int iswctype_l(wint_t wc, wctype_t charclass, locale_t unused locale) -{ - return iswctype(wc, charclass); -} diff --git a/lib/libc/wctype/iswspace.c b/lib/libc/wctype/iswspace.c deleted file mode 100644 index 3b6806af..00000000 --- a/lib/libc/wctype/iswspace.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -int iswspace(wint_t wc) -{ - const wchar_t t[] = { L' ', L'\t', L'\n', L'\r', 11, 12, - 0x0085, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, - 0x2005, 0x2006, 0x2008, 0x2009, 0x200a, 0x2028, - 0x2029, 0x205f, 0x3000, 0 - - }; - - return wc && wcschr(t, (wchar_t)wc) != NULL; -} - -weak int iswspace_l(wint_t wc, locale_t unused locale) -{ - return iswspace(wc); -} diff --git a/lib/libc/wctype/iswupper.c b/lib/libc/wctype/iswupper.c deleted file mode 100644 index afe12049..00000000 --- a/lib/libc/wctype/iswupper.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int iswupper(wint_t wc) -{ - return towlower(wc) != wc; -} - -weak int iswupper_l(wint_t wc, locale_t unused locale) -{ - return iswupper(wc); -} diff --git a/lib/libc/wctype/iswxdigit.c b/lib/libc/wctype/iswxdigit.c deleted file mode 100644 index fae88730..00000000 --- a/lib/libc/wctype/iswxdigit.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int iswxdigit(wint_t wc) -{ - return (unsigned)(wc - '0') < 10 || (unsigned)((wc | 32) - 'a') < 6; -} - -weak int iswxdigit_l(wint_t wc, locale_t unused locale) -{ - return iswxdigit(wc); -} diff --git a/lib/libc/wctype/towctrans.c b/lib/libc/wctype/towctrans.c deleted file mode 100644 index 9e7f3b63..00000000 --- a/lib/libc/wctype/towctrans.c +++ /dev/null @@ -1,348 +0,0 @@ -#include -#include -#include -#include -#include - -/* From embeddedartistry/libc */ -#define CASEMAP(u1, u2, l) { (u1), (l) - (u1), (u2) - (u1) + 1 } -#define CASELACE(u1, u2) CASEMAP((u1), (u2), (u1) + 1) - -static const struct { - unsigned short upper; - signed char lower; - unsigned char len; -} casemaps[] = { - CASEMAP(0xc0, 0xde, 0xe0), - - CASELACE(0x0100, 0x012e), CASELACE(0x0132, 0x0136), - CASELACE(0x0139, 0x0147), CASELACE(0x014a, 0x0176), - CASELACE(0x0179, 0x017d), - - CASELACE(0x370, 0x372), CASEMAP(0x391, 0x3a1, 0x3b1), - CASEMAP(0x3a3, 0x3ab, 0x3c3), CASEMAP(0x400, 0x40f, 0x450), - CASEMAP(0x410, 0x42f, 0x430), - - CASELACE(0x460, 0x480), CASELACE(0x48a, 0x4be), - CASELACE(0x4c1, 0x4cd), CASELACE(0x4d0, 0x50e), - - CASELACE(0x514, 0x52e), CASEMAP(0x531, 0x556, 0x561), - - CASELACE(0x01a0, 0x01a4), CASELACE(0x01b3, 0x01b5), - CASELACE(0x01cd, 0x01db), CASELACE(0x01de, 0x01ee), - CASELACE(0x01f8, 0x021e), CASELACE(0x0222, 0x0232), - CASELACE(0x03d8, 0x03ee), - - CASELACE(0x1e00, 0x1e94), CASELACE(0x1ea0, 0x1efe), - - CASEMAP(0x1f08, 0x1f0f, 0x1f00), CASEMAP(0x1f18, 0x1f1d, 0x1f10), - CASEMAP(0x1f28, 0x1f2f, 0x1f20), CASEMAP(0x1f38, 0x1f3f, 0x1f30), - CASEMAP(0x1f48, 0x1f4d, 0x1f40), - - CASEMAP(0x1f68, 0x1f6f, 0x1f60), CASEMAP(0x1f88, 0x1f8f, 0x1f80), - CASEMAP(0x1f98, 0x1f9f, 0x1f90), CASEMAP(0x1fa8, 0x1faf, 0x1fa0), - CASEMAP(0x1fb8, 0x1fb9, 0x1fb0), CASEMAP(0x1fba, 0x1fbb, 0x1f70), - CASEMAP(0x1fc8, 0x1fcb, 0x1f72), CASEMAP(0x1fd8, 0x1fd9, 0x1fd0), - CASEMAP(0x1fda, 0x1fdb, 0x1f76), CASEMAP(0x1fe8, 0x1fe9, 0x1fe0), - CASEMAP(0x1fea, 0x1feb, 0x1f7a), CASEMAP(0x1ff8, 0x1ff9, 0x1f78), - CASEMAP(0x1ffa, 0x1ffb, 0x1f7c), - - CASEMAP(0x13f0, 0x13f5, 0x13f8), CASELACE(0xa698, 0xa69a), - CASELACE(0xa796, 0xa79e), - - CASELACE(0x246, 0x24e), CASELACE(0x510, 0x512), - CASEMAP(0x2160, 0x216f, 0x2170), CASEMAP(0x2c00, 0x2c2e, 0x2c30), - CASELACE(0x2c67, 0x2c6b), CASELACE(0x2c80, 0x2ce2), - CASELACE(0x2ceb, 0x2ced), - - CASELACE(0xa640, 0xa66c), CASELACE(0xa680, 0xa696), - - CASELACE(0xa722, 0xa72e), CASELACE(0xa732, 0xa76e), - CASELACE(0xa779, 0xa77b), CASELACE(0xa77e, 0xa786), - - CASELACE(0xa790, 0xa792), CASELACE(0xa7a0, 0xa7a8), - - CASELACE(0xa7b4, 0xa7b6), - - CASEMAP(0xff21, 0xff3a, 0xff41), { 0, 0, 0 } -}; - -static const unsigned short pairs[][2] = { { 'I', 0x0131 }, - { 'S', 0x017f }, - { 0x0130, 'i' }, - { 0x0178, 0x00ff }, - { 0x0181, 0x0253 }, - { 0x0182, 0x0183 }, - { 0x0184, 0x0185 }, - { 0x0186, 0x0254 }, - { 0x0187, 0x0188 }, - { 0x0189, 0x0256 }, - { 0x018a, 0x0257 }, - { 0x018b, 0x018c }, - { 0x018e, 0x01dd }, - { 0x018f, 0x0259 }, - { 0x0190, 0x025b }, - { 0x0191, 0x0192 }, - { 0x0193, 0x0260 }, - { 0x0194, 0x0263 }, - { 0x0196, 0x0269 }, - { 0x0197, 0x0268 }, - { 0x0198, 0x0199 }, - { 0x019c, 0x026f }, - { 0x019d, 0x0272 }, - { 0x019f, 0x0275 }, - { 0x01a6, 0x0280 }, - { 0x01a7, 0x01a8 }, - { 0x01a9, 0x0283 }, - { 0x01ac, 0x01ad }, - { 0x01ae, 0x0288 }, - { 0x01af, 0x01b0 }, - { 0x01b1, 0x028a }, - { 0x01b2, 0x028b }, - { 0x01b7, 0x0292 }, - { 0x01b8, 0x01b9 }, - { 0x01bc, 0x01bd }, - { 0x01c4, 0x01c6 }, - { 0x01c4, 0x01c5 }, - { 0x01c5, 0x01c6 }, - { 0x01c7, 0x01c9 }, - { 0x01c7, 0x01c8 }, - { 0x01c8, 0x01c9 }, - { 0x01ca, 0x01cc }, - { 0x01ca, 0x01cb }, - { 0x01cb, 0x01cc }, - { 0x01f1, 0x01f3 }, - { 0x01f1, 0x01f2 }, - { 0x01f2, 0x01f3 }, - { 0x01f4, 0x01f5 }, - { 0x01f6, 0x0195 }, - { 0x01f7, 0x01bf }, - { 0x0220, 0x019e }, - { 0x0386, 0x03ac }, - { 0x0388, 0x03ad }, - { 0x0389, 0x03ae }, - { 0x038a, 0x03af }, - { 0x038c, 0x03cc }, - { 0x038e, 0x03cd }, - { 0x038f, 0x03ce }, - { 0x0399, 0x0345 }, - { 0x0399, 0x1fbe }, - { 0x03a3, 0x03c2 }, - { 0x03f7, 0x03f8 }, - { 0x03fa, 0x03fb }, - { 0x1e60, 0x1e9b }, - { 0x1e9e, 0xdf }, - - { 0x1f59, 0x1f51 }, - { 0x1f5b, 0x1f53 }, - { 0x1f5d, 0x1f55 }, - { 0x1f5f, 0x1f57 }, - { 0x1fbc, 0x1fb3 }, - { 0x1fcc, 0x1fc3 }, - { 0x1fec, 0x1fe5 }, - { 0x1ffc, 0x1ff3 }, - - { 0x23a, 0x2c65 }, - { 0x23b, 0x23c }, - { 0x23d, 0x19a }, - { 0x23e, 0x2c66 }, - { 0x241, 0x242 }, - { 0x243, 0x180 }, - { 0x244, 0x289 }, - { 0x245, 0x28c }, - { 0x3f4, 0x3b8 }, - { 0x3f9, 0x3f2 }, - { 0x3fd, 0x37b }, - { 0x3fe, 0x37c }, - { 0x3ff, 0x37d }, - { 0x4c0, 0x4cf }, - - { 0x2126, 0x3c9 }, - { 0x212a, 'k' }, - { 0x212b, 0xe5 }, - { 0x2132, 0x214e }, - { 0x2183, 0x2184 }, - { 0x2c60, 0x2c61 }, - { 0x2c62, 0x26b }, - { 0x2c63, 0x1d7d }, - { 0x2c64, 0x27d }, - { 0x2c6d, 0x251 }, - { 0x2c6e, 0x271 }, - { 0x2c6f, 0x250 }, - { 0x2c70, 0x252 }, - { 0x2c72, 0x2c73 }, - { 0x2c75, 0x2c76 }, - { 0x2c7e, 0x23f }, - { 0x2c7f, 0x240 }, - { 0x2cf2, 0x2cf3 }, - - { 0xa77d, 0x1d79 }, - { 0xa78b, 0xa78c }, - { 0xa78d, 0x265 }, - { 0xa7aa, 0x266 }, - - { 0x10c7, 0x2d27 }, - { 0x10cd, 0x2d2d }, - - /* bogus greek 'symbol' letters */ - { 0x376, 0x377 }, - { 0x39c, 0xb5 }, - { 0x392, 0x3d0 }, - { 0x398, 0x3d1 }, - { 0x3a6, 0x3d5 }, - { 0x3a0, 0x3d6 }, - { 0x39a, 0x3f0 }, - { 0x3a1, 0x3f1 }, - { 0x395, 0x3f5 }, - { 0x3cf, 0x3d7 }, - - { 0xa7ab, 0x25c }, - { 0xa7ac, 0x261 }, - { 0xa7ad, 0x26c }, - { 0xa7ae, 0x26a }, - { 0xa7b0, 0x29e }, - { 0xa7b1, 0x287 }, - { 0xa7b2, 0x29d }, - { 0xa7b3, 0xab53 }, - - /* special cyrillic lowercase forms - */ - { 0x412, 0x1c80 }, - { 0x414, 0x1c81 }, - { 0x41e, 0x1c82 }, - { 0x421, 0x1c83 }, - { 0x422, 0x1c84 }, - { 0x422, 0x1c85 }, - { 0x42a, 0x1c86 }, - { 0x462, 0x1c87 }, - { 0xa64a, 0x1c88 }, - - { 0, 0 } }; - -wchar_t __towcase(wchar_t wc, int lower) -{ - int i; - int lmul = 2 * lower - 1; - int lmask = lower - 1; - /* no letters with case in these large ranges */ - if (!iswalpha((wint_t)wc) || (unsigned)wc - 0x0600 <= 0x0fff - 0x0600 || - (unsigned)wc - 0x2e00 <= 0xa63f - 0x2e00 || - (unsigned)wc - 0xa800 <= 0xab52 - 0xa800 || - (unsigned)wc - 0xabc0 <= 0xfeff - 0xabc0) { - return wc; - } - - /* special case because the diff between upper/lower is too big */ - if (lower && (unsigned)wc - 0x10a0 < 0x2e) { - if (wc > 0x10c5 && wc != 0x10c7 && wc != 0x10cd) { - return wc; - } - - return wc + 0x2d00 - 0x10a0; - } - - if (!lower && (unsigned)wc - 0x2d00 < 0x26) { - if (wc > 0x2d25 && wc != 0x2d27 && wc != 0x2d2d) { - return wc; - } - - return wc + 0x10a0 - 0x2d00; - } - - if (lower && (unsigned)wc - 0x13a0 < 0x50) { - return wc + 0xab70 - 0x13a0; - } - - if (!lower && (unsigned)wc - 0xab70 < 0x50) { - return wc + 0x13a0 - 0xab70; - } - - for (i = 0; casemaps[i].len; i++) { - int base = casemaps[i].upper + (lmask & casemaps[i].lower); - if (wc - (wchar_t)base < casemaps[i].len) { - if (casemaps[i].lower == 1) { - return wc + (wchar_t)lower - - ((wc - casemaps[i].upper) & 1); - } - return wc + (wchar_t)(lmul * casemaps[i].lower); - } - } - - for (i = 0; pairs[i][1 - lower]; i++) { - if (pairs[i][1 - lower] == wc) { - return pairs[i][lower]; - } - } - - if (wc - (wchar_t)(0x10428 - 0x28 * lower) < 0x28) { - return wc - (wchar_t)(0x28 + 0x50 * lower); - } - - if (wc - (wchar_t)(0x104d8 - 0x28 * lower) < 0x24) { - return wc - (wchar_t)(0x28 + 0x50 * lower); - } - - if (wc - (wchar_t)(0x10cc0 - 0x40 * lower) < 0x33) { - return wc - (wchar_t)(0x40 + 0x80 * lower); - } - - if (wc - (wchar_t)(0x118c0 - 0x20 * lower) < 0x20) { - return wc - (wchar_t)(0x20 + 0x40 * lower); - } - - if (wc - (wchar_t)(0x1e922 - 0x22 * lower) < 0x22) { - return wc - (wchar_t)(0x22 + 0x44 * lower); - } - - return wc; -} - -wint_t towlower(wint_t wc) -{ - return (wint_t)(wc < 128 ? (wint_t)tolower((int)wc) : - (wint_t)__towcase((wchar_t)wc, 1)); -} - -weak wint_t towlower_l(wint_t wc, locale_t unused locale) -{ - return towlower(wc); -} - -wint_t towupper(wint_t wc) -{ - return (wint_t)(wc < 128 ? (wint_t)toupper((int)wc) : - (wint_t)__towcase((wchar_t)wc, 0)); -} - -weak wint_t towupper_l(wint_t wc, locale_t unused locale) -{ - return towupper(wc); -} - -wctrans_t wctrans(const char *class) -{ - if (!strcmp(class, "toupper")) - return (wctrans_t)1; - if (!strcmp(class, "tolower")) - return (wctrans_t)2; - return 0; -} - -weak wctrans_t wctrans_l(const char *class, locale_t unused locale) -{ - return wctrans(class); -} - -wint_t towctrans(wint_t wc, wctrans_t desc) -{ - if (desc == (wctrans_t)1) - return towupper(wc); - if (desc == (wctrans_t)2) - return towlower(wc); - return wc; -} - -weak wint_t towctrans_l(wint_t wc, wctrans_t desc, locale_t unused locale) -{ - return towctrans(wc, desc); -} diff --git a/lib/libc/wctype/wctype.c b/lib/libc/wctype/wctype.c deleted file mode 100644 index 0495ba8c..00000000 --- a/lib/libc/wctype/wctype.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -wctype_t wctype(const char *property) -{ - int i; - const char *ptr; - static const char n[] = "alnum\0" - "alpha\0" - "blank\0" - "cntrl\0" - "digit\0" - "graph\0" - "lower\0" - "print\0" - "punct\0" - "space\0" - "upper\0" - "xdigit"; - - for (i = 1, ptr = n; *ptr; i++, ptr += strlen(ptr) + 1) - if (!strcmp(property, ptr)) - return i; - - return 0; -} - -weak wctype_t wctype_l(const char *property, locale_t unused locale) -{ - return wctype(property); -} diff --git a/lib/libjson/Kbuild b/lib/libjson/Kbuild deleted file mode 100644 index 561d858b..00000000 --- a/lib/libjson/Kbuild +++ /dev/null @@ -1,3 +0,0 @@ -lib-y := libjson.a - -obj-y += json.o diff --git a/lib/libjson/json.c b/lib/libjson/json.c deleted file mode 100644 index a50a6275..00000000 --- a/lib/libjson/json.c +++ /dev/null @@ -1,1607 +0,0 @@ -#include "json.h" - -#include -#include -#include - -inline struct json_value *json_array_get(struct json_value *array, int index) -{ - return index < array->array.length ? array->array.items[index] : NULL; -} - -/** - * @brief Represents a JSON parser for decoding JSON strings. - * - * This structure is used internally by the JSON library to parse - * JSON-encoded strings into structured `json_value` objects. - * - * @note This structure is private and should not be accessed directly - * outside of the JSON library's internal implementation. - */ -struct json_parser { - /** - * @brief The input JSON string to be parsed. - * - * This is a pointer to the null-terminated JSON string that the parser - * operates on. - */ - const char *input; - - /** - * @brief The length of the input JSON string. - * - * This value represents the total number of characters in the input - * JSON string, excluding the null terminator. - */ - int length; - - /** - * @brief The current position in the input JSON string. - * - * This value indicates the index of the character currently being - * processed by the parser. - */ - int position; - -#if defined(JSON_ERROR) - /** - * @brief Represents error information for the JSON parser. - * - * This structure is used to store details about any errors encountered - * during the parsing process. - */ - struct { - /** - * @brief Enum representing the type of error encountered. - * - * - `JSON_ERROR_NONE`: No error occurred. - * - `JSON_ERROR_SYNTAX`: A syntax error was encountered. - * - `JSON_ERROR_MEMORY`: A memory allocation error occurred. - * - `JSON_ERROR_EOF`: Unexpected end of input was encountered. - */ - enum { - JSON_ERROR_NONE, /**< No error occurred. */ - JSON_ERROR_SYNTAX, /**< A syntax error was encountered. - */ - JSON_ERROR_MEMORY, /**< A memory allocation error - occurred. */ - JSON_ERROR_EOF, /**< Unexpected end of input was - encountered. */ - JSON_ERROR_INVALID_NUMBER, /**< Failed to parse number - */ - } code; - - /** - * @brief The line number where the error occurred. - * - * This value is used for debugging purposes to identify the - * location of the error in the source code. - */ - int line; - - /** - * @brief The name of the function where the error occurred. - * - * This is a pointer to a string containing the name of the - * function in which the error was detected. - */ - const char *func; - - /** - * @brief A descriptive message about the error. - * - * This is a pointer to a string containing a human-readable - * description of the error. - */ - const char *message; - } error; -#endif -}; - -/** - * Initializes a JSON object. - * - * This function is responsible for setting up the internal structure - * of a JSON object, ensuring it is ready for use. It is invoked by - * both json_object_new() and json_object_free() to manage the lifecycle - * of JSON objects. - * - * @param object A pointer to the JSON object to be initialized. - * - * @note This function is marked as privative and should not be used - * directly outside of the JSON library's internal implementation. - */ -void json_object_init(struct json_value *object); - -#if defined(JSON_ERROR) -/** - * @brief Sets an error in the JSON parser. - * - * This macro assigns error details to the JSON parser's error structure. - * It captures the error code, the line number, the function name, and - * a descriptive error message. - * - * @param PARSER The JSON parser where the error occurred. - * @param CODE The error code to set. - * @param MESSAGE A descriptive message about the error. - */ -#define JSON_PARSER_ERROR(PARSER, CODE, MESSAGE) \ - (PARSER)->error.code = (CODE); \ - (PARSER)->error.line = __LINE__; \ - (PARSER)->error.func = __func__; \ - (PARSER)->error.message = (MESSAGE) -#else -/** - * @brief No-op macro for JSON parser errors. - * - * When JSON_ERROR is not defined, this macro does nothing. - * - * @param PARSER The JSON parser (unused). - * @param CODE The error code (unused). - * @param MESSAGE The error message (unused). - */ -#define JSON_PARSER_ERROR(PARSER, CODE, MESSAGE) -#endif - -static int json__decode_value(struct json_parser *parser, - struct json_value *value); - -static int json__strlen(const char *str) -{ - int len = 0; - while (*str++) - len++; - return len; -} - -static int json__streq(const char *s1, const char *s2) -{ - if (json__strlen(s1) != json__strlen(s2)) - return 0; - - while (*s1 && *s1 == *s2) { - s1++; - s2++; - } - - if (*s1 == 0 && *s2 == 0) - return 1; - - return 0; -} - -static int json__streqn(const char *s1, const char *s2, int limit) -{ - while (*s1 && *s2 && *s1 == *s2 && limit-- > 1) { - s1++; - s2++; - } - - return *s1 == *s2 ? 1 : 0; -} - -static void json__parse_whitespace(struct json_parser *parser) -{ - const char *ptr = parser->input; - int pos = parser->position; - int len = parser->length; - - while (pos < len && (ptr[pos] == ' ' || ptr[pos] == '\t' || - ptr[pos] == '\n' || ptr[pos] == '\r')) - pos++; - - parser->position = pos; -} - -static int json__decode_string(struct json_parser *parser, - struct json_value *value) -{ - int start = parser->position + 1; - int end = start; - int buffer_size = 16; - int buffer_length = 0; - char *buffer = malloc(buffer_size); - - if (buffer == NULL) { - JSON_PARSER_ERROR(parser, JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - - while (end < parser->length && parser->input[end] != '"') { - if (parser->input[end] == '\\') { - end++; - if (end >= parser->length) { - free(buffer); - JSON_PARSER_ERROR( - parser, JSON_ERROR_SYNTAX, - "Unterminated escape sequence"); - return -1; - } - - if (parser->input[end] == 'u') { - // Handle \uXXXX Unicode escape sequences - end++; - if (end + 3 >= parser->length) { - free(buffer); - JSON_PARSER_ERROR( - parser, JSON_ERROR_SYNTAX, - "Incomplete Unicode escape sequence"); - return -1; - } - - // Parse 4 hex digits - unsigned int code_point = 0; - for (int i = 0; i < 4; i++) { - char c = parser->input[end + i]; - code_point <<= 4; - - if (c >= '0' && c <= '9') { - code_point |= (c - '0'); - } else if (c >= 'a' && c <= 'f') { - code_point |= (c - 'a' + 10); - } else if (c >= 'A' && c <= 'F') { - code_point |= (c - 'A' + 10); - } else { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_SYNTAX, - "Invalid hex digit in Unicode escape"); - return -1; - } - } - - // Check for surrogate pair - if (code_point >= 0xD800 && - code_point <= 0xDBFF) { - // High surrogate - need to get the low - // surrogate - end += 4; // Move past the first \uXXXX - - // Check for the sequence \uYYYY where - // YYYY is the low surrogate - if (end + 1 >= parser->length || - parser->input[end] != '\\' || - parser->input[end + 1] != 'u') { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_SYNTAX, - "Expected low surrogate after high surrogate"); - return -1; - } - - end += 2; // Move past \u - if (end + 3 >= parser->length) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_SYNTAX, - "Incomplete Unicode escape sequence for low surrogate"); - return -1; - } - - // Parse 4 hex digits for low surrogate - unsigned int low_surrogate = 0; - for (int i = 0; i < 4; i++) { - char c = parser->input[end + i]; - low_surrogate <<= 4; - - if (c >= '0' && c <= '9') { - low_surrogate |= - (c - '0'); - } else if (c >= 'a' && - c <= 'f') { - low_surrogate |= - (c - 'a' + 10); - } else if (c >= 'A' && - c <= 'F') { - low_surrogate |= - (c - 'A' + 10); - } else { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_SYNTAX, - "Invalid hex digit in low surrogate"); - return -1; - } - } - - // Validate low surrogate range - if (low_surrogate < 0xDC00 || - low_surrogate > 0xDFFF) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_SYNTAX, - "Invalid low surrogate value"); - return -1; - } - - // Combine surrogate pair to get actual - // code point - code_point = - 0x10000 + - ((code_point - 0xD800) << 10) + - (low_surrogate - 0xDC00); - end += 4; // Move past the second \uXXXX - } else { - end += 4; // Move past \uXXXX for - // non-surrogate case - } - - // Encode code point as UTF-8 - if (code_point < 0x80) { - // 1-byte character - if (buffer_length + 1 >= buffer_size) { - buffer_size *= 2; - char *new_buffer = realloc( - buffer, buffer_size); - if (new_buffer == NULL) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - buffer = new_buffer; - } - buffer[buffer_length++] = - (char)code_point; - } else if (code_point < 0x800) { - // 2-byte character - if (buffer_length + 2 >= buffer_size) { - buffer_size *= 2; - char *new_buffer = realloc( - buffer, buffer_size); - if (new_buffer == NULL) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - buffer = new_buffer; - } - buffer[buffer_length++] = - (char)(0xC0 | - (code_point >> 6)); - buffer[buffer_length++] = - (char)(0x80 | - (code_point & 0x3F)); - } else if (code_point < 0x10000) { - // 3-byte character - if (buffer_length + 3 >= buffer_size) { - buffer_size *= 2; - char *new_buffer = realloc( - buffer, buffer_size); - if (new_buffer == NULL) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - buffer = new_buffer; - } - buffer[buffer_length++] = - (char)(0xE0 | - (code_point >> 12)); - buffer[buffer_length++] = - (char)(0x80 | - ((code_point >> 6) & - 0x3F)); - buffer[buffer_length++] = - (char)(0x80 | - (code_point & 0x3F)); - } else { - // 4-byte character - if (buffer_length + 4 >= buffer_size) { - buffer_size *= 2; - char *new_buffer = realloc( - buffer, buffer_size); - if (new_buffer == NULL) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - buffer = new_buffer; - } - buffer[buffer_length++] = - (char)(0xF0 | - (code_point >> 18)); - buffer[buffer_length++] = - (char)(0x80 | - ((code_point >> 12) & - 0x3F)); - buffer[buffer_length++] = - (char)(0x80 | - ((code_point >> 6) & - 0x3F)); - buffer[buffer_length++] = - (char)(0x80 | - (code_point & 0x3F)); - } - - continue; // Skip the increment at the end of - // the loop - } else { - // Handle standard escape sequences - char escaped_char; - switch (parser->input[end]) { - case '"': - escaped_char = '"'; - break; - case '\\': - escaped_char = '\\'; - break; - case '/': - escaped_char = '/'; - break; - case 'b': - escaped_char = '\b'; - break; - case 'f': - escaped_char = '\f'; - break; - case 'n': - escaped_char = '\n'; - break; - case 'r': - escaped_char = '\r'; - break; - case 't': - escaped_char = '\t'; - break; - default: - free(buffer); - JSON_PARSER_ERROR( - parser, JSON_ERROR_SYNTAX, - "Invalid escape character"); - return -1; - } - - if (buffer_length + 1 >= buffer_size) { - buffer_size *= 2; - char *new_buffer = - realloc(buffer, buffer_size); - if (new_buffer == NULL) { - free(buffer); - JSON_PARSER_ERROR( - parser, - JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - buffer = new_buffer; - } - - buffer[buffer_length++] = escaped_char; - } - } else { - if (buffer_length + 1 >= buffer_size) { - buffer_size *= 2; - char *new_buffer = realloc(buffer, buffer_size); - if (new_buffer == NULL) { - free(buffer); - JSON_PARSER_ERROR( - parser, JSON_ERROR_MEMORY, - "Memory allocation failed"); - return -1; - } - buffer = new_buffer; - } - - buffer[buffer_length++] = parser->input[end]; - } - end++; - } - - if (end == parser->length) { - free(buffer); - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Unterminated string"); - return -1; - } - - buffer[buffer_length] = 0; - - value->type = JSON_TYPE_STRING; - value->string.value = buffer; - value->string.length = buffer_length; - - parser->position = end + 1; - return 0; -} - -static void json__parser_consume_digits(struct json_parser *parser) -{ - while (parser->position < parser->length && - parser->input[parser->position] >= '0' && - parser->input[parser->position] <= '9') { - parser->position++; - } -} - -static int json__decode_number(struct json_parser *parser, - struct json_value *value) -{ - int start = parser->position; - char *endptr; - - if (parser->position < parser->length && - parser->input[parser->position] == '-') - parser->position++; - - if (parser->position < parser->length && - parser->input[parser->position] == '0') { - parser->position++; - } else if (parser->position < parser->length && - parser->input[parser->position] >= '1' && - parser->input[parser->position] <= '9') { - json__parser_consume_digits(parser); - } else { - JSON_PARSER_ERROR(parser, JSON_ERROR_INVALID_NUMBER, - "Invalid number"); - return -1; - } - - if (parser->position < parser->length && - parser->input[parser->position] == '.') { - parser->position++; - if (parser->position < parser->length && - parser->input[parser->position] >= '0' && - parser->input[parser->position] <= '9') { - json__parser_consume_digits(parser); - } else { - JSON_PARSER_ERROR(parser, JSON_ERROR_INVALID_NUMBER, - "Invalid number"); - return -1; - } - } - - if (parser->position < parser->length && - (parser->input[parser->position] == 'e' || - parser->input[parser->position] == 'E')) { - parser->position++; - if (parser->position < parser->length && - (parser->input[parser->position] == '-' || - parser->input[parser->position] == '+')) { - parser->position++; - } - if (parser->position < parser->length && - parser->input[parser->position] >= '0' && - parser->input[parser->position] <= '9') { - json__parser_consume_digits(parser); - } else { - JSON_PARSER_ERROR(parser, JSON_ERROR_INVALID_NUMBER, - "Invalid number"); - return -1; - } - } - - if (start == parser->position) { - JSON_PARSER_ERROR(parser, JSON_ERROR_INVALID_NUMBER, - "Invalid number"); - return -1; - } - - value->type = JSON_TYPE_NUMBER; - endptr = NULL; - value->number = strtod(parser->input + start, &endptr); - - if (endptr != parser->input + parser->position) { - JSON_PARSER_ERROR(parser, JSON_ERROR_INVALID_NUMBER, - "Invalid number"); - return -1; - } - - return 0; -} - -static int json__decode_array(struct json_parser *parser, - struct json_value *array) -{ - if (parser->length - parser->position < 1) { - JSON_PARSER_ERROR(parser, JSON_ERROR_EOF, - "Unexpected end of input"); - return -1; - } - - if (parser->input[parser->position] != '[') { - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, "Expected '['"); - return -1; - } - - array->type = JSON_TYPE_ARRAY; - json_array_init(array); - - if (parser->position + 1 < parser->length && - parser->input[parser->position + 1] == ']') { - parser->position += 2; - return 0; - } - - parser->position += 1; // Skip '[' - while (parser->position < parser->length && - parser->input[parser->position] != ']') { - json__parse_whitespace(parser); - - struct json_value *item; - if ((item = malloc(sizeof(struct json_value))) == NULL) { - JSON_PARSER_ERROR(parser, JSON_ERROR_MEMORY, - "Memory allocation failed"); - json_array_free(array); - return -1; - } - - if (json__decode_value(parser, item) != 0) { - free(item); - json_array_free(array); - return -1; - } - - json_array_push(array, item); - json__parse_whitespace(parser); - - if (parser->position < parser->length && - parser->input[parser->position] == ',') // Skip ',' - parser->position++; - } - - if (parser->position >= parser->length || - parser->input[parser->position] != ']') { - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Expected closing ']' for array"); - json_array_free(array); - return -1; - } - - if (parser->position < parser->length) // Skip ']' - parser->position++; - return 0; -} - -static int json__decode_object(struct json_parser *parser, - struct json_value *object) -{ - object->type = JSON_TYPE_OBJECT; - json_object_init(object); - - parser->position++; - json__parse_whitespace(parser); - - while (parser->position < parser->length && - parser->input[parser->position] != '}') { - struct json_value key, *value; - json__parse_whitespace(parser); - - if (parser->input[parser->position] != '"') { - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Expected string key"); - return -1; - } - - if (json__decode_string(parser, &key) != 0) { - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Failed to parse string key"); - return -1; - } - - json__parse_whitespace(parser); - if (parser->position >= parser->length || - parser->input[parser->position] != ':') { - free(key.string.value); - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Expected ':' after string key"); - return -1; - } - parser->position++; // Skip the colon - - value = malloc(sizeof(struct json_value)); - if (value == NULL) { - free(key.string.value); - JSON_PARSER_ERROR( - parser, JSON_ERROR_MEMORY, - "Failed to allocate memory for JSON item"); - return -1; - } - - json__parse_whitespace(parser); - if (json__decode_value(parser, value) != 0) { - free(value); - free(key.string.value); - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Failed to parse JSON value"); - return -1; - } - - if (json_object_set(object, key.string.value, value) != 0) { - free(value); - free(key.string.value); - JSON_PARSER_ERROR( - parser, JSON_ERROR_MEMORY, - "Failed to set key-value pair in object"); - return -1; - } - - free(key.string.value); - json__parse_whitespace(parser); - if (parser->position < parser->length && - parser->input[parser->position] == ',') - parser->position++; // Skip comma or closing brace - } - - if (parser->position >= parser->length || - parser->input[parser->position] != '}') { - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, - "Expected '}' after JSON object"); - return -1; - } - - parser->position++; // Skip the closing brace - - return 0; -} - -static int json__decode_value(struct json_parser *parser, - struct json_value *value) -{ - int rc; - char c = parser->input[parser->position]; - - if (c == '"') { - rc = json__decode_string(parser, value); - } else if (c == '[') { - rc = json__decode_array(parser, value); - } else if (c == '{') { - rc = json__decode_object(parser, value); - } else if (json__streqn(parser->input + parser->position, "true", 4)) { - value->type = JSON_TYPE_BOOLEAN; - value->number = 1; - parser->position += 4; - return 0; - } else if (json__streqn(parser->input + parser->position, "false", 4)) { - value->type = JSON_TYPE_BOOLEAN; - value->number = 0; - parser->position += 5; - return 0; - } else if (json__streqn(parser->input + parser->position, "null", 4)) { - value->type = JSON_TYPE_NULL; - parser->position += 4; - return 0; - } else { - rc = json__decode_number(parser, value); - } - -#if defined(JSON_ERROR) - if (rc != 0 && parser->error.code == JSON_ERROR_NONE) { - JSON_PARSER_ERROR(parser, JSON_ERROR_SYNTAX, "Expected value"); - } -#endif - - return rc; -} - -struct json_value *json_decode_with_length(const char *json, int length) -{ - struct json_parser parser; - struct json_value *value = NULL; - - parser.input = json; - parser.length = length; - parser.position = 0; - -#if defined(JSON_ERROR) - parser.error.code = JSON_ERROR_NONE; - parser.error.message = NULL; -#endif - - if ((value = malloc(sizeof(struct json_value))) == NULL) - return NULL; - - if (json__decode_value(&parser, value) != 0) { -#if defined(JSON_ERROR) && !defined(JSON_ERROR_HANDLER) - if (parser.error.code != JSON_ERROR_NONE) { - fprintf(stderr, - "JSON(\033[1merror\033[m): %s:%d %s at\n", - parser.error.func, parser.error.line, - parser.error.message); - } -#elif defined(JSON_ERROR) && defined(JSON_ERROR_HANDLER) - if (parser.error.code != JSON_ERROR_NONE) { - JSON_ERROR_HANDLER(parser.error.code, - parser.error.message); - } -#endif - free(value); - return NULL; - } - - return value; -} - -struct json_value *json_decode(const char *json) -{ - return json_decode_with_length(json, json__strlen(json)); -} - -static char *json__encode_array(struct json_value *value) -{ - int length; - int buffer_size; - char *encoded_array; - if (value == NULL) { - return NULL; - } - - buffer_size = 512; - encoded_array = malloc(buffer_size); - if (encoded_array == NULL) { - return NULL; - } - - length = 1; - encoded_array[0] = '['; - - for (int i = 0; i < value->array.length; i++) { - int needed; - int encoded_item_len; - char *encoded_item = json_encode(value->array.items[i]); - if (encoded_item == NULL) { - free(encoded_array); - return NULL; - } - - encoded_item_len = json__strlen(encoded_item); - if (encoded_item_len < 0) { - free(encoded_array); - free(encoded_item); - return NULL; - } - - needed = length + encoded_item_len + (i > 0 ? 1 : 0) + 1; - if (needed > buffer_size) { - char *new_encoded_array = realloc( - encoded_array, (buffer_size = needed * 2)); - if (new_encoded_array == NULL) { - free(encoded_array); - free(encoded_item); - return NULL; - } - encoded_array = new_encoded_array; - } - - if (i > 0) { - encoded_array[length++] = ','; - } - - for (int i = 0; i < encoded_item_len; i++) { - if (encoded_item[i] == '\0') - break; - encoded_array[length + i] = encoded_item[i]; - } - - length += encoded_item_len; - - free(encoded_item); - } - - encoded_array[length++] = ']'; - encoded_array[length] = '\0'; - - return encoded_array; -} - -static char *json__encode_object(struct json_value *object) -{ - int length; - int buffer_size = 256; - char *encoded_object = malloc(buffer_size); - if (encoded_object == NULL) { - return NULL; - } - - encoded_object[0] = '{'; - length = 1; - - for (int i = 0; i < object->object.n_items; i++) { - char *new_buffer; - char *key = object->object.items[i]->key; - char *value = json_encode(object->object.items[i]->value); - if (value == NULL) { - free(encoded_object); - return NULL; - } - - int key_length = json__strlen(key); - int value_length = json__strlen(value); - if (value_length < 0) { - free(encoded_object); - free(value); - return NULL; - } - - int needed = length + key_length + value_length + 4 + - (i < object->object.n_items - 1 ? 1 : 0); - - if (needed > buffer_size) { - buffer_size = needed * 2; - new_buffer = realloc(encoded_object, buffer_size); - if (new_buffer == NULL) { - free(encoded_object); - free(value); - return NULL; - } - encoded_object = new_buffer; - } - - encoded_object[length++] = '"'; - for (int j = 0; j < key_length; j++) - encoded_object[length++] = key[j]; - - encoded_object[length++] = '"'; - encoded_object[length++] = ':'; - for (int j = 0; j < value_length; j++) { - if (value[j] == '\0') - break; - encoded_object[length++] = value[j]; - } - - free(value); - - if (i < object->object.n_items - 1) { - encoded_object[length++] = ','; - } - } - - encoded_object[length++] = '}'; - encoded_object[length] = '\0'; - - return encoded_object; -} - -static char *json__encode_string(struct json_value *value) -{ - const char *str = value->string.value; - int length = value->string.length; - int buffer_size = length * 6 + 3; // Maximum possible size (all chars - // escaped + quotes) - char *buffer = malloc(buffer_size); - int pos = 0; - - if (!buffer) - return NULL; - - buffer[pos++] = '"'; - - for (int i = 0; i < length; i++) { - unsigned char c = (unsigned char)str[i]; - - if (c == '"' || c == '\\' || c == '/') { - buffer[pos++] = '\\'; - buffer[pos++] = c; - } else if (c == '\b') { - buffer[pos++] = '\\'; - buffer[pos++] = 'b'; - } else if (c == '\f') { - buffer[pos++] = '\\'; - buffer[pos++] = 'f'; - } else if (c == '\n') { - buffer[pos++] = '\\'; - buffer[pos++] = 'n'; - } else if (c == '\r') { - buffer[pos++] = '\\'; - buffer[pos++] = 'r'; - } else if (c == '\t') { - buffer[pos++] = '\\'; - buffer[pos++] = 't'; - } else if (c < 32) { - // Control characters must be escaped as \uXXXX - buffer[pos++] = '\\'; - buffer[pos++] = 'u'; - buffer[pos++] = '0'; - buffer[pos++] = '0'; - buffer[pos++] = "0123456789ABCDEF"[(c >> 4) & 0xF]; - buffer[pos++] = "0123456789ABCDEF"[c & 0xF]; - } else if (c < 128) { - // ASCII characters - buffer[pos++] = c; - } else { - // UTF-8 encoded characters - // Check if this is a multi-byte sequence - const unsigned char *bytes = - (const unsigned char *)&str[i]; - if ((c & 0xE0) == 0xC0) { - // Two-byte sequence - if (i + 1 >= length || - (bytes[i + 1] & 0xC0) != 0x80) { - // Invalid UTF-8 sequence, escape as - // replacement character - buffer[pos++] = '\\'; - buffer[pos++] = 'u'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'D'; - } else { - // Valid two-byte sequence, keep as is - buffer[pos++] = c; - buffer[pos++] = str[++i]; - } - } else if ((c & 0xF0) == 0xE0) { - // Three-byte sequence - if (i + 2 >= length || - (bytes[i + 1] & 0xC0) != 0x80 || - (bytes[i + 2] & 0xC0) != 0x80) { - // Invalid UTF-8 sequence - buffer[pos++] = '\\'; - buffer[pos++] = 'u'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'D'; - } else { - // Valid three-byte sequence, keep as is - buffer[pos++] = c; - buffer[pos++] = str[++i]; - buffer[pos++] = str[++i]; - } - } else if ((c & 0xF8) == 0xF0) { - // Four-byte sequence - if (i + 3 >= length || - (bytes[i + 1] & 0xC0) != 0x80 || - (bytes[i + 2] & 0xC0) != 0x80 || - (bytes[i + 3] & 0xC0) != 0x80) { - // Invalid UTF-8 sequence - buffer[pos++] = '\\'; - buffer[pos++] = 'u'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'D'; - } else { - // Valid four-byte sequence, keep as is - buffer[pos++] = c; - buffer[pos++] = str[++i]; - buffer[pos++] = str[++i]; - buffer[pos++] = str[++i]; - } - } else { - // Invalid UTF-8 start byte - buffer[pos++] = '\\'; - buffer[pos++] = 'u'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'F'; - buffer[pos++] = 'D'; - } - } - } - - buffer[pos++] = '"'; - buffer[pos] = '\0'; - - // Reallocate to actual size - char *result = realloc(buffer, pos + 1); - return result ? result : buffer; -} - -char *json_encode(struct json_value *value) -{ - switch (value->type) { - case JSON_TYPE_STRING: - return json__encode_string(value); - case JSON_TYPE_NUMBER: { - char *ptr; - char buffer[32]; - int length = snprintf(buffer, sizeof(buffer), "%.17g", - value->number); - - if ((ptr = malloc(length + 1)) == NULL) - return NULL; - - for (int i = 0; i < length; i++) - ptr[i] = buffer[i]; - - ptr[length] = 0; - return ptr; - } - case JSON_TYPE_BOOLEAN: { - char *ptr; - const char *boolean_str = value->number != 0.0 ? "true" : - "false"; - int length = json__strlen(boolean_str); - - if ((ptr = malloc(length + 1)) == NULL) - return NULL; - - for (int i = 0; i < length; i++) - ptr[i] = boolean_str[i]; - - ptr[length] = 0; - return ptr; - } - case JSON_TYPE_NULL: { - char *ptr; - const char *null_str = "null"; - int length = json__strlen(null_str); - - if ((ptr = malloc(length + 1)) == NULL) - return NULL; - - for (int i = 0; i < length; i++) - ptr[i] = null_str[i]; - - ptr[length] = 0; - return ptr; - } - case JSON_TYPE_ARRAY: - return json__encode_array(value); - case JSON_TYPE_OBJECT: - return json__encode_object(value); - default: - return NULL; - } -} - -void json_object_init(struct json_value *object) -{ - object->object.n_items = 0; - object->object.capacity = 0; - object->object.items = NULL; -} - -struct json_value *json_object_new(void) -{ - struct json_value *object = malloc(sizeof(struct json_value)); - if (!object) { - return NULL; - } - - object->type = JSON_TYPE_OBJECT; - json_object_init(object); - - return object; -} - -void json_object_free(struct json_value *object) -{ - for (int i = 0; i < object->object.n_items; i++) { - json_free(object->object.items[i]->value); - free(object->object.items[i]->key); - free(object->object.items[i]); - } - - free(object->object.items); - free(object); -} - -int json_object_set(struct json_value *object, const char *key, - struct json_value *value) -{ - if (object->object.n_items >= - object->object.capacity * JSON_OBJECT_CAPACITY_THRESHOLD) { - void *items; - int capacity; - - if (object->object.capacity) - capacity = object->object.capacity * - JSON_OBJECT_CAPACITY_MULTIPLIER; - else - capacity = JSON_OBJECT_INITIAL_CAPACITY; - - if ((items = realloc( - object->object.items, - capacity * sizeof(*object->object.items))) == NULL) - return -1; - - object->object.items = items; - object->object.capacity = capacity; - } - - for (int i = 0; i < object->object.n_items; i++) { - if (json__streq(object->object.items[i]->key, key)) { - json_free(object->object.items[i]->value); - object->object.items[i]->value = value; - return 0; - } - } - - int idx = object->object.n_items++; - object->object.items[idx] = malloc(sizeof(*object->object.items[idx])); - - if (object->object.items[idx] == NULL) - return -1; - - int key_len = json__strlen(key); - object->object.items[idx]->key = malloc(key_len + 1); - strncpy(object->object.items[idx]->key, key, key_len); - object->object.items[idx]->key[key_len] = '\0'; - object->object.items[idx]->value = value; - - return 0; -} - -int json_object_has(struct json_value *object, const char *key) -{ - for (int i = 0; i < object->object.n_items; i++) - if (json__streq(object->object.items[i]->key, key)) - return 1; - - return 0; -} - -struct json_value *json_object_get(struct json_value *object, const char *key) -{ - if (object == NULL || object->object.items == NULL) - return NULL; - - for (int i = 0; i < object->object.n_items; i++) - if (object->object.items[i] != NULL && - object->object.items[i]->key != NULL && - json__streq(object->object.items[i]->key, key)) - return object->object.items[i]->value; - - return NULL; -} - -void json_object_remove(struct json_value *object, const char *key) -{ - for (int i = 0; i < object->object.n_items; i++) { - if (json__streq(object->object.items[i]->key, key)) { - switch (object->object.items[i]->value->type) { - case JSON_TYPE_ARRAY: - json_array_free(object->object.items[i]->value); - break; - case JSON_TYPE_OBJECT: - json_object_free( - object->object.items[i]->value); - break; - case JSON_TYPE_STRING: - json_string_free( - object->object.items[i]->value); - break; - default: - free(object->object.items[i]->value); - break; - } - - free(object->object.items[i]->key); - free(object->object.items[i]); - - if (i < object->object.n_items - 1) { - object->object.items[i] = - object->object - .items[object->object.n_items - - 1]; - } - - object->object.n_items--; - } - } -} - -int json_object_iter(const struct json_value *object, int *iter, char **key, - struct json_value **value) -{ - if (*iter >= object->object.n_items) - return 0; - - *key = object->object.items[*iter]->key; - *value = object->object.items[(*iter)++]->value; - - return 1; -} - -void json_object_clear(struct json_value *object) -{ - char *key; - int iter = 0; - struct json_value *value; - - while (json_object_iter(object, &iter, &key, &value)) { - json_object_remove(object, key); - iter--; - } -} - -void json_array_init(struct json_value *array) -{ - array->array.length = 0; - array->array.capacity = 0; - array->array.items = NULL; -} - -struct json_value *json_array_new(void) -{ - struct json_value *value; - if ((value = malloc(sizeof(struct json_value))) == NULL) - return NULL; - - value->type = JSON_TYPE_ARRAY; - json_array_init(value); - - return value; -} - -void json_array_free(struct json_value *value) -{ - for (int i = 0; i < value->array.length; i++) { - switch (value->array.items[i]->type) { - case JSON_TYPE_OBJECT: - json_object_free(value->array.items[i]); - break; - case JSON_TYPE_ARRAY: - json_array_free(value->array.items[i]); - break; - case JSON_TYPE_STRING: - json_string_free(value->array.items[i]); - break; - default: - free(value->array.items[i]); - break; - } - } - free(value->array.items); - free(value); -} - -void json_free(struct json_value *value) -{ - switch (value->type) { - case JSON_TYPE_OBJECT: - json_object_free(value); - break; - case JSON_TYPE_ARRAY: - json_array_free(value); - break; - case JSON_TYPE_STRING: - json_string_free(value); - break; - default: - free(value); - } -} - -struct json_value *json_deep_copy(struct json_value *value) -{ - struct json_value *new_value; - struct json_value *element; - char *key; - int iter; - - iter = 0; - - switch (value->type) { - case JSON_TYPE_OBJECT: - new_value = json_object_new(); - while (json_object_iter(value, &iter, &key, &element)) - json_object_set(new_value, key, - json_deep_copy(element)); - return new_value; - - case JSON_TYPE_ARRAY: - new_value = json_array_new(); - while (json_array_iter(value, &iter, &element)) - json_array_push(new_value, json_deep_copy(element)); - return new_value; - - case JSON_TYPE_STRING: - return json_string_new(value->string.value); - - default: - new_value = malloc(sizeof(struct json_value)); - memcpy(new_value, value, sizeof(*value)); - return new_value; - } - - return NULL; -} - -void json_array_remove(struct json_value *array, int index) -{ - switch (array->array.items[index]->type) { - case JSON_TYPE_OBJECT: - json_object_free(array->array.items[index]); - break; - case JSON_TYPE_ARRAY: - json_array_free(array->array.items[index]); - break; - case JSON_TYPE_STRING: - json_string_free(array->array.items[index]); - break; - default: - break; - } - - for (int i = index; i < array->array.length - 1; i++) - array->array.items[i] = array->array.items[i + 1]; - array->array.length--; -} - -inline int json_array_length(struct json_value *array) -{ - return array->array.length; -} - -int json_array_push(struct json_value *array, struct json_value *value) -{ - if (array == NULL) { - return -1; - } - - int index = array->array.length; - int capacity = array->array.capacity; - int capacity_threshold = capacity * JSON_ARRAY_CAPACITY_THRESHOLD; - - if (index >= capacity_threshold) { - int capacity; - if (array->array.capacity > 0) - capacity = array->array.capacity * - JSON_ARRAY_CAPACITY_MULTIPLIER; - else - capacity = JSON_ARRAY_INITIAL_CAPACITY; - - struct json_value **items; - int size = capacity * sizeof(struct json_value *); - if ((items = realloc(array->array.items, size)) == NULL) - return -1; - - array->array.items = items; - array->array.capacity = capacity; - } - - array->array.items[array->array.length++] = value; - return 0; -} - -int json_array_iter(struct json_value *array, int *index, - struct json_value **value) -{ - if (*index >= array->array.length) - return 0; - - *value = array->array.items[(*index)++]; - return 1; -} - -void json_array_clear(struct json_value *array) -{ - int iter = 0; - struct json_value *value; - - while (json_array_iter(array, &iter, &value)) - json_array_remove(array, iter--); -} - -struct json_value *json_string_new(const char *string) -{ - struct json_value *value; - if ((value = malloc(sizeof(struct json_value))) == NULL) - return NULL; - - value->type = JSON_TYPE_STRING; - value->string.length = json__strlen(string); - if ((value->string.value = malloc(value->string.length + 1)) == NULL) { - free(value); - return NULL; - } - - for (int i = 0; i < value->string.length; i++) - value->string.value[i] = string[i]; - - value->string.value[value->string.length] = 0; - return value; -} - -struct json_value *json_number_new(double value) -{ - struct json_value *number; - if ((number = malloc(sizeof(struct json_value))) == NULL) - return NULL; - - number->type = JSON_TYPE_NUMBER; - number->number = value; - - return number; -} - -struct json_value *json_boolean_new(int value) -{ - struct json_value *boolean; - if ((boolean = malloc(sizeof(struct json_value))) == NULL) - return NULL; - - boolean->type = JSON_TYPE_BOOLEAN; - boolean->number = value; - - return boolean; -} - -void json_string_free(struct json_value *string) -{ - free(string->string.value); - free(string); -} - -static inline void json__print_indent(int indent) -{ - for (int i = 0; i < indent; i++) { - putchar(' '); - } -} - -static void json__print_internal(struct json_value *value, int indent) -{ - if (value == NULL) { - printf("null"); - return; - } - - switch (value->type) { - case JSON_TYPE_STRING: - printf("\"%s\"", value->string.value); - break; - case JSON_TYPE_NUMBER: - printf("%.17g", value->number); - break; - case JSON_TYPE_BOOLEAN: - printf("%s", value->number == 0.0 ? "false" : "true"); - break; - case JSON_TYPE_NULL: - printf("null"); - break; - case JSON_TYPE_ARRAY: - printf("[\n"); - for (int i = 0; i < value->array.length; i++) { - json__print_indent(indent + 2); - json__print_internal(value->array.items[i], indent + 2); - if (i < value->array.length - 1) { - printf(",\n"); - } else { - printf("\n"); - } - } - json__print_indent(indent); - printf("]"); - break; - case JSON_TYPE_OBJECT: - printf("{\n"); - for (int i = 0; i < value->object.n_items; i++) { - json__print_indent(indent + 2); - printf("\"%s\": ", value->object.items[i]->key); - json__print_internal(value->object.items[i]->value, - indent + 2); - if (i < value->object.n_items - 1) { - printf(",\n"); - } else { - printf("\n"); - } - } - json__print_indent(indent); - printf("}"); - break; - default: - break; - } -} - -void json_print(struct json_value *value) -{ - json__print_internal(value, 0); -} - -void json_println(struct json_value *value) -{ - json_print(value); - putchar('\n'); -} diff --git a/lib/libjson/json.h b/lib/libjson/json.h deleted file mode 100644 index a406df04..00000000 --- a/lib/libjson/json.h +++ /dev/null @@ -1,602 +0,0 @@ -#ifndef JSON_H -#define JSON_H - -#ifndef JSON_ARRAY_INITIAL_CAPACITY -/** - * @brief Defines the initial capacity for JSON arrays. - * - * This value determines the number of elements a JSON array - * can hold before requiring a reallocation. Adjust this value - * to optimize memory usage and performance for your specific use case. - */ -#define JSON_ARRAY_INITIAL_CAPACITY 1 -#endif - -#ifndef JSON_ARRAY_CAPACITY_MULTIPLIER -/** - * @brief Defines the capacity multiplier for JSON arrays. - * - * When a JSON array exceeds its current capacity, its capacity is - * multiplied by this value to allocate additional space. A higher - * multiplier reduces the frequency of reallocations but increases - * memory usage. - */ -#define JSON_ARRAY_CAPACITY_MULTIPLIER 2 -#endif - -#ifndef JSON_ARRAY_CAPACITY_THRESHOLD -/** - * @brief Threshold for triggering reallocation in JSON arrays. - * - * Defines how full the array must be (relative to capacity) - * before reallocating. Typically set to 1 (100% full). - */ -#define JSON_ARRAY_CAPACITY_THRESHOLD 1 -#endif - -#ifndef JSON_OBJECT_INITIAL_CAPACITY -/** - * @brief Defines the initial capacity for JSON objects. - * - * Determines how many key-value pairs a JSON object can store - * before requiring reallocation. Increase this value to reduce - * early reallocations for large objects. - */ -#define JSON_OBJECT_INITIAL_CAPACITY 1 -#endif - -#ifndef JSON_OBJECT_CAPACITY_MULTIPLIER -/** - * @brief Growth multiplier for JSON object capacity. - * - * When the object exceeds its current capacity, the capacity - * is multiplied by this factor. A larger multiplier reduces - * the frequency of reallocations but may waste memory. - */ -#define JSON_OBJECT_CAPACITY_MULTIPLIER 2 -#endif - -#ifndef JSON_OBJECT_CAPACITY_THRESHOLD -/** - * @brief Threshold for triggering reallocation in JSON objects. - * - * Defines how full the object must be (relative to capacity) - * before reallocating. Typically set to 1 (100% full). - */ -#define JSON_OBJECT_CAPACITY_THRESHOLD 1 -#endif - -/** - * @brief Represents a JSON value. - * - * This structure encapsulates a JSON value, which can be one of several types - * including null, boolean, number, string, array, or object. The type of the - * value is determined by the `type` field, and the actual data is stored in - * the corresponding member of the union. - */ -struct json_value { - /** - * @brief Enum representing the type of the JSON value. - * - * The type determines which member of the union is valid. - * - * - `JSON_TYPE_NULL`: Represents a null value. - * - `JSON_TYPE_BOOLEAN`: Represents a boolean value (true/false). - * - `JSON_TYPE_NUMBER`: Represents a numeric value. - * - `JSON_TYPE_STRING`: Represents a string value. - * - `JSON_TYPE_ARRAY`: Represents an array of JSON values. - * - `JSON_TYPE_OBJECT`: Represents an object with key-value pairs. - */ - enum { - JSON_TYPE_NULL, /**< Null value. */ - JSON_TYPE_BOOLEAN, /**< Boolean value (true/false). */ - JSON_TYPE_NUMBER, /**< Numeric value. */ - JSON_TYPE_STRING, /**< String value. */ - JSON_TYPE_ARRAY, /**< Array of JSON values. */ - JSON_TYPE_OBJECT /**< Object with key-value pairs. */ - } type; - - /** - * @brief Union holding the actual data of the JSON value. - * - * The type of data stored depends on the `type` field. - */ - union { - /** - * @brief Holds a numeric value when `type` is - * `JSON_TYPE_NUMBER`. - */ - double number; - - /** - * @brief Holds an array of JSON values when `type` is - * `JSON_TYPE_ARRAY`. - * - * - `capacity`: The total allocated capacity of the array. - * - `length`: The current number of elements in the array. - * - `items`: A pointer to an array of pointers to `json_value` - * elements. - */ - struct { - int capacity; /**< Total allocated capacity of the - array. */ - int length; /**< Current number of elements in the - array. */ - struct json_value **items; /**< Pointer to an array of - pointers to `json_value` - elements. */ - } array; - - /** - * @brief Holds a string value when `type` is - * `JSON_TYPE_STRING`. - * - * - `capacity`: The total allocated capacity of the string. - * - `length`: The current length of the string (excluding null - * terminator). - * - `value`: A pointer to the null-terminated string. - */ - struct { - int capacity; /**< Total allocated capacity of the - string. */ - int length; /**< Current length of the string (excluding - null terminator). */ - char *value; /**< Pointer to the null-terminated string. - */ - } string; - - /** - * @brief Holds an object with key-value pairs when `type` is - * `JSON_TYPE_OBJECT`. - * - * - `capacity`: The total allocated capacity for key-value - * pairs. - * - `n_items`: The current number of key-value pairs in the - * object. - * - `items`: A pointer to an array of pointers to key-value - * pair structures. Each key-value pair consists of: - * - `key`: A pointer to a null-terminated string - * representing the key. - * - `value`: A pointer to a `json_value` representing the - * associated value. - */ - struct { - int capacity; /**< Total allocated capacity for - key-value pairs. */ - int n_items; /**< Current number of key-value pairs in - * the object. - */ - struct { - char *key; /**< Pointer to a null-terminated - string representing the key. */ - struct json_value *value; /**< Pointer to a - `json_value` - representing the - associated value. */ - } **items; /**< Pointer to an array of pointers to - key-value pair structures. */ - } object; - }; -}; - -/** - * @brief Checks if a JSON value is an array. - * - * This macro determines whether a given JSON value is of type array. - * - * @param VALUE The JSON value to check. - * @return Non-zero if the value is an array, 0 otherwise. - */ -#define json_is_array(VALUE) ((VALUE) && (VALUE)->type == JSON_TYPE_ARRAY) - -/** - * @brief Checks if a JSON value is a boolean. - * - * This macro determines whether a given JSON value is of type boolean. - * - * @param VALUE The JSON value to check. - * @return Non-zero if the value is a boolean, 0 otherwise. - */ -#define json_is_boolean(VALUE) ((VALUE) && (VALUE)->type == JSON_TYPE_BOOLEAN) - -/** - * @brief Checks if a JSON value is null. - * - * This macro determines whether a given JSON value is of type null. - * - * @param VALUE The JSON value to check. - * @return Non-zero if the value is null, 0 otherwise. - */ -#define json_is_null(VALUE) ((VALUE) && (VALUE)->type == JSON_TYPE_NULL) - -/** - * @brief Checks if a JSON value is a number. - * - * This macro determines whether a given JSON value is of type number. - * - * @param VALUE The JSON value to check. - * @return Non-zero if the value is a number, 0 otherwise. - */ -#define json_is_number(VALUE) ((VALUE) && (VALUE)->type == JSON_TYPE_NUMBER) - -/** - * @brief Checks if a JSON value is an object. - * - * This macro determines whether a given JSON value is of type object. - * - * @param VALUE The JSON value to check. - * @return Non-zero if the value is an object, 0 otherwise. - */ -#define json_is_object(VALUE) ((VALUE) && (VALUE)->type == JSON_TYPE_OBJECT) - -/** - * @brief Checks if a JSON value is a string. - * - * This macro determines whether a given JSON value is of type string. - * - * @param VALUE The JSON value to check. - * @return Non-zero if the value is a string, 0 otherwise. - */ -#define json_is_string(VALUE) ((VALUE) && (VALUE)->type == JSON_TYPE_STRING) - -/** - * @brief Retrieves the boolean value from a JSON boolean. - * - * This macro extracts the boolean value from a JSON boolean type. - * - * @param VALUE The JSON boolean value to retrieve. - * @return Non-zero if the boolean is true, 0 if false. - */ -#define json_boolean_get(VALUE) ((VALUE)->number != 0.0) - -/** - * @brief Sets the boolean value of a JSON boolean. - * - * This macro modifies the boolean value of a JSON boolean type. - * - * @param VALUE The JSON boolean value to modify. - * @param STATE The new boolean value to set (non-zero for true, 0 for false). - */ -#define json_boolean_set(VALUE, STATE) ((VALUE)->number = STATE) - -/** - * @brief Retrieves the numeric value from a JSON number. - * - * This macro extracts the numeric value from a JSON number type. - * - * @param VALUE The JSON number value to retrieve. - * @return The numeric value. - */ -#define json_number_get(VALUE) ((VALUE)->number) - -/** - * @brief Sets the numeric value of a JSON number. - * - * This macro modifies the numeric value of a JSON number type. - * - * @param JSON The JSON number value to modify. - * @param VALUE The new numeric value to set. - */ -#define json_number_set(JSON, VALUE) ((JSON)->number = VALUE) - -/** - * @brief Retrieves the string value from a JSON string. - * - * This macro extracts the string value from a JSON string type. - * - * @param JSON The JSON string value to retrieve. - * @return A pointer to the string value. - */ -#define json_string_get(JSON) ((JSON) ? (JSON)->string.value : NULL) - -/** - * @brief Sets the string value of a JSON string. - * - * This macro modifies the string value of a JSON string type. - * - * @param JSON The JSON string value to modify. - * @param VALUE The new string value to set. - */ -#define json_string_set(JSON, VALUE) ((JSON)->string.value = VALUE) - -/** - * @brief Retrieves an element from a JSON array. - * - * This function retrieves an element from a JSON array at the specified index. - * - * @param array The JSON array to retrieve from. - * @param index The index of the element to retrieve. - * @return A pointer to the element at the specified index, or NULL if out of - * bounds. - */ -struct json_value *json_array_get(struct json_value *array, int index); - -/** - * @brief Sets an element in a JSON array. - * - * This macro sets an element in a JSON array at the specified index. - * - * @param array The JSON array to modify. - * @param index The index of the element to set. - * @param value The new value to set. - */ -#define json_array_set(ARRAY, INDEX, VALUE) \ - ((ARRAY)->array.items[(INDEX)] = (VALUE)) - -/** - * @brief Retrieves the number of key-value pairs in a JSON object. - * - * This macro returns the total count of key-value pairs in a JSON object. - * - * @param OBJECT A pointer to the JSON object to query. - * @return The total count of key-value pairs in the object. - */ -#define json_object_count(OBJECT) ((OBJECT)->object.n_items) - -/** - * @brief Retrieves the number of elements in a JSON array. - * - * This macro returns the total count of elements in a JSON array. - * - * @param ARRAY A pointer to the JSON array to query. - * @return The total count of elements in the array. - */ -#define json_array_count(ARRAY) ((ARRAY)->array.length) - -/** - * @brief Encodes a JSON value into a JSON string. - * - * This function takes a structured `json_value` and converts it into - * a JSON-encoded string representation. The caller is responsible for - * freeing the returned string using `free()`. - * - * @param value The JSON value to encode. Must not be NULL. - * @return A pointer to the JSON-encoded string, or NULL if encoding fails. - */ -char *json_encode(struct json_value *value); - -/** - * @brief Decodes a JSON string into a JSON value. - * - * This function parses a JSON-encoded string and converts it into a - * structured representation using the `json_value` type. The caller - * is responsible for freeing the returned `json_value` using `json_free()`. - * - * @param json The JSON-encoded string to decode. Must be null-terminated. - * @return A pointer to the decoded `json_value`, or NULL if decoding fails. - */ -struct json_value *json_decode(const char *json); - -/** - * @brief Decodes a JSON string into a JSON value. - * - * Decodes up to `length` bytes, see `json_decode` for more. - * - * @param json The JSON-encoded string to decode. - * @param length The length of the string to decode. - * @return A pointer to the decoded `json_value`, or NULL if decoding fails. - */ -struct json_value *json_decode_with_length(const char *json, int length); - -/** - * @brief Creates a new JSON object. - * - * This function allocates and initializes a new JSON object. - * - * @return A pointer to the newly created JSON object, or NULL on failure. - */ -struct json_value *json_object_new(void); - -/** - * @brief Frees the memory associated with a JSON object. - * - * This function releases all memory used by the JSON object, including - * its key-value pairs and their associated values. - * - * @param object The JSON object to free. - */ -void json_object_free(struct json_value *object); - -/** - * @brief Retrieves the value associated with a key in a JSON object. - * - * This function searches for a key in the JSON object and returns the - * associated value if the key exists. - * - * @param object The JSON object to query. - * @param key The key to look up. - * @return A pointer to the associated value, or NULL if the key does not exist. - */ -struct json_value *json_object_get(struct json_value *object, const char *key); - -/** - * @brief Sets a key-value pair in a JSON object. - * - * This function adds or updates a key-value pair in the JSON object. - * If the key already exists, its value is updated. - * - * @param object The JSON object to modify. - * @param key The key to set in the object. - * @param value The value to associate with the key. - * @return 0 on success, or -1 on failure. - */ -int json_object_set(struct json_value *object, const char *key, - struct json_value *value); - -/** - * @brief Checks if a key exists in a JSON object. - * - * This function determines whether a specific key exists in the JSON object. - * - * @param object The JSON object to query. - * @param key The key to check for. - * @return 1 if the key exists, 0 otherwise. - */ -int json_object_has(struct json_value *object, const char *key); - -/** - * @brief Removes a key-value pair from a JSON object. - * - * This function deletes a key-value pair from the JSON object. If the key - * does not exist, the function does nothing. - * - * @param object The JSON object to modify. - * @param key The key to remove. - */ -void json_object_remove(struct json_value *object, const char *key); - -/** - * @brief Iterates over the key-value pairs in a JSON object. - * - * This function provides a way to iterate through all key-value pairs - * in a JSON object. The iteration index should be initialized to 0 - * before the first call. - * - * @param object The JSON object to iterate over. - * @param iter A pointer to the iteration index (should be initialized to 0). - * @param key A pointer to store the current key. - * @param value A pointer to store the current value. - * @return 1 if there are more items to iterate, 0 otherwise. - */ -int json_object_iter(const struct json_value *object, int *iter, char **key, - struct json_value **value); - -/** - * @brief Appends a value to the end of a JSON array. - * - * This function adds a new value to the end of the JSON array. - * - * @param array The JSON array to modify. - * @param value The value to append. - * @return 0 on success, or -1 on failure. - */ -int json_array_push(struct json_value *array, struct json_value *value); - -/** - * @brief Creates a new JSON array. - * - * This function allocates and initializes a new JSON array. - * - * @return A pointer to the newly created JSON array, or NULL on failure. - */ -struct json_value *json_array_new(void); - -/** - * @brief Frees the memory associated with a JSON array. - * - * This function releases all memory used by the JSON array, including - * its elements. - * - * @param array The JSON array to free. - */ -void json_array_free(struct json_value *array); - -/** - * @brief Initializes a JSON array. - * - * This function sets up the internal structure of a JSON array, - * preparing it for use. - * - * @param array The JSON array to initialize. - */ -void json_array_init(struct json_value *array); - -/** - * @brief Frees the memory associated with a JSON string. - * - * This function releases all memory used by the JSON string. - * - * @param string The JSON string to free. - */ -void json_string_free(struct json_value *string); - -/** - * @brief Removes a value at a specific index in a JSON array. - * - * This function deletes the value at the specified index in the JSON array. - * If the index is out of bounds, the function fails. - * - * @param array The JSON array to modify. - * @param index The index to remove the value from. - */ -void json_array_remove(struct json_value *array, int index); - -/** - * @brief Retrieves the length of a JSON array. - * - * This function returns the number of elements in the JSON array. - * - * @param array The JSON array to query. - * @return The number of elements in the array. - */ -int json_array_length(struct json_value *array); - -/** - * @brief Iterates over the elements in a JSON array. - * - * This function provides a way to iterate through all elements in a JSON array. - * The iteration index should be initialized to 0 before the first call. - * - * @param array The JSON array to iterate over. - * @param index A pointer to the iteration index (should be initialized to 0). - * @param value A pointer to store the current value. - * @return 1 on success, or 0 if the iteration is complete. - */ -int json_array_iter(struct json_value *array, int *index, - struct json_value **value); - -/** - * @brief Creates a new JSON string with the specified value. - * - * This function allocates and initializes a new JSON string with the - * provided string value. - * - * @param value The string value to initialize the JSON string with. - * @return A pointer to the newly created JSON string, or NULL on failure. - */ -struct json_value *json_string_new(const char *value); - -/** - * @brief Creates a new JSON number with the specified value. - * - * This function allocates and initializes a new JSON number with the - * provided numeric value. - * - * @param value The numeric value to initialize the JSON number with. - * @return A pointer to the newly created JSON number, or NULL on failure. - */ -struct json_value *json_number_new(double value); - -/** - * @brief Creates a new JSON boolean with the specified value. - * - * This function allocates and initializes a new JSON boolean with the - * provided boolean value. - * - * @param value The boolean value to initialize the JSON boolean with. - * @return A pointer to the newly created JSON boolean, or NULL on failure. - */ -struct json_value *json_boolean_new(int value); - -/** - * @brief Deallocates memory associated with a JSON value and its descendants. - * - * This function performs a comprehensive cleanup of the specified JSON value, - * including recursively freeing all child elements, whether they are objects, - * arrays, or strings. It ensures that all allocated memory is properly - * released. - * - * @param value A pointer to the JSON value to be deallocated. - */ -void json_free(struct json_value *value); - -/** - * @brief Copy the whole value and all its children into a new json_value. - * - * In theory, no memory should be shared with the previous value. - * - * @param value The JSON value to deep-copy. - */ -struct json_value *json_deep_copy(struct json_value *value); - -#endif diff --git a/lib/main.c b/lib/main.c deleted file mode 100644 index 1ac7b0f7..00000000 --- a/lib/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(void) -{ - printf("Hello, World!\n"); - return 0; -} diff --git a/lib/other.c b/lib/other.c deleted file mode 100644 index d47b7b33..00000000 --- a/lib/other.c +++ /dev/null @@ -1,6 +0,0 @@ - - -int add(int a, int b) -{ - return a + b; -} diff --git a/makefile b/makefile index 7e530f28..73085be7 100644 --- a/makefile +++ b/makefile @@ -103,12 +103,12 @@ all: $(srctree)/include/config/auto.conf $(srctree)/include/generated/autoconf.h clean: $(Q)$(MAKE) -f scripts/makefile.build obj=$(obj) clean - rm -f $(srctree)/include/config/auto.conf - rm -f $(srctree)/include/generated/autoconf.h - rm -f compile_commands.json + $(Q)rm -f $(srctree)/include/config/auto.conf + $(Q)rm -f $(srctree)/include/generated/autoconf.h distclean: clean $(Q)$(MAKE) -C scripts/kconfig clean + $(Q)rm -f compile_commands.json $(KCONFIG_CONFIG): @echo >&2 '***' -- cgit v1.2.3