summaryrefslogtreecommitdiff
path: root/lume-legacy/include/ulib/stdlib.h
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
commite90b72ec3082588b296956730bd2930cf8d5d671 (patch)
tree36ff6916af9b4176ea5a9662219d11e721f0b691 /lume-legacy/include/ulib/stdlib.h
parent1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (diff)
downloadlume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.gz
lume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.xz
refactor: promote new architecture to repository root
Archive the deprecated implementation under lume-legacy, make the new kernel the default root-level build, and update repository entry points without changing kernel behavior.
Diffstat (limited to 'lume-legacy/include/ulib/stdlib.h')
-rw-r--r--lume-legacy/include/ulib/stdlib.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/lume-legacy/include/ulib/stdlib.h b/lume-legacy/include/ulib/stdlib.h
new file mode 100644
index 0000000..6d8f75d
--- /dev/null
+++ b/lume-legacy/include/ulib/stdlib.h
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Richard QIn
+ */
+
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+#include "ulib/types.h"
+#include "ulib/limits.h"
+#include "ulib/errno.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#define ERANGE 34 /* Math result not representable */
+#define ENOMEM 12 /* Out of memory */
+
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+#define RAND_MAX 32767
+#define MB_CUR_MAX 1
+
+typedef struct
+{
+ int quot;
+ int rem;
+} div_t;
+typedef struct
+{
+ long quot;
+ long rem;
+} ldiv_t;
+typedef struct
+{
+ long long quot;
+ long long rem;
+} lldiv_t;
+
+typedef int (*__compar_fn_t)(const void *, const void *);
+
+/* Memory Management */
+void *malloc(size_t size);
+void free(void *ptr);
+void *calloc(size_t nmemb, size_t size);
+void *realloc(void *ptr, size_t size);
+
+/* Process Control */
+int exit(int status);
+void abort(void);
+int atexit(void (*function)(void));
+char *getenv(const char *name);
+int system(const char *command);
+
+/* String Conversion */
+int atoi(const char *nptr);
+long atol(const char *nptr);
+long long atoll(const char *nptr);
+double atof(const char *nptr);
+
+long strtol(const char *nptr, char **endptr, int base);
+unsigned long strtoul(const char *nptr, char **endptr, int base);
+long long strtoll(const char *nptr, char **endptr, int base);
+unsigned long long strtoull(const char *nptr, char **endptr, int base);
+
+double strtod(const char *nptr, char **endptr);
+float strtof(const char *nptr, char **endptr);
+
+/* Search & Sort*/
+void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
+void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
+
+/* Math & Mics */
+int abs(int j);
+long labs(long j);
+long long llabs(long long j);
+div_t div(int numer, int denom);
+ldiv_t ldiv(long numer, long denom);
+lldiv_t lldiv(long long numer, long long denom);
+
+int rand(void);
+void srand(unsigned int seed);
+
+int mblen(const char *s, size_t n);
+int mbtowc(wchar_t *pwc, const char *s, size_t n);
+int wctomb(char *s, wchar_t wchar);
+size_t mbstowcs(wchar_t *dest, const char *src, size_t n);
+size_t wcstombs(char *dest, const wchar_t *src, size_t n);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _STDLIB_H */ \ No newline at end of file