summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-09 19:20:15 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-09 19:20:15 +0100
commit885f5974cdf65b59415837ae97f5a14ef1350670 (patch)
tree66ac13de29c7f4932c5fcae11773df574e4e256a /lib/libc/stdlib
parent8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 (diff)
feat: add gzip and new headers
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/Kbuild34
-rw-r--r--lib/libc/stdlib/__mb_cur_max.c6
-rw-r--r--lib/libc/stdlib/qsort_r.c31
-rw-r--r--lib/libc/stdlib/strtox.c1
-rw-r--r--lib/libc/stdlib/system.c1
5 files changed, 54 insertions, 19 deletions
diff --git a/lib/libc/stdlib/Kbuild b/lib/libc/stdlib/Kbuild
new file mode 100644
index 00000000..6d7efef7
--- /dev/null
+++ b/lib/libc/stdlib/Kbuild
@@ -0,0 +1,34 @@
+obj-y += _Exit.o
+obj-y += abort.o
+obj-y += abs.o
+obj-y += aligned_alloc.o
+obj-y += atexit.o
+obj-y += atof.o
+obj-y += atoi.o
+obj-y += atol.o
+obj-y += atoll.o
+obj-y += bsearch.o
+obj-y += calloc.o
+obj-y += div.o
+obj-y += exit.o
+obj-y += free.o
+obj-y += getenv.o
+obj-y += heapsort_r.o
+obj-y += heapsort.o
+obj-y += labs.o
+obj-y += ldiv.o
+obj-y += llabs.o
+obj-y += lldiv.o
+obj-y += malloc.o
+obj-y += posix_memalign.o
+obj-y += putenv.o
+obj-y += qsort_r.o
+obj-y += qsort.o
+obj-y += quick_exit.o
+obj-y += rand.o
+obj-y += realloc.o
+obj-y += reallocarray.o
+obj-y += setenv.o
+obj-y += strtox.o
+obj-y += system.o
+obj-y += unsetenv.o
diff --git a/lib/libc/stdlib/__mb_cur_max.c b/lib/libc/stdlib/__mb_cur_max.c
deleted file mode 100644
index 2f8affa2..00000000
--- a/lib/libc/stdlib/__mb_cur_max.c
+++ /dev/null
@@ -1,6 +0,0 @@
-int __mb_cur_max(void)
-{
- // TODO: if locale (c/utf8) will be implemented
- // then return the correct value here if c then 1 else if utf8 then 4
- return 1;
-}
diff --git a/lib/libc/stdlib/qsort_r.c b/lib/libc/stdlib/qsort_r.c
index 2fc39a6f..646eeaff 100644
--- a/lib/libc/stdlib/qsort_r.c
+++ b/lib/libc/stdlib/qsort_r.c
@@ -22,7 +22,8 @@
/* Minor changes by Rich Felker for integration in musl, 2011-04-27. */
/* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1).
- Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */
+ Run time: Worst case O(n log n), close to O(n) in the
+ mostly-sorted case. */
#define _BSD_SOURCE
#include <stdlib.h>
@@ -68,13 +69,15 @@ static void cycle(size_t width, unsigned char *ar[], int n)
/* shl() and shr() need n > 0 */
static inline void shl(size_t p[2], int n)
{
- if (n >= 8 * sizeof(size_t)) {
- n -= 8 * sizeof(size_t);
+ size_t bits = sizeof(size_t) * 8;
+
+ if (n >= (int)bits) {
+ n -= (int)bits;
p[1] = p[0];
p[0] = 0;
}
p[1] <<= n;
- p[1] |= (n < sizeof(size_t) * 8) ? p[0] >> (sizeof(size_t) * 8 - n) : 0;
+ p[1] |= (n < (int)bits) ? p[0] >> (bits - n) : 0;
p[0] <<= n;
}
@@ -82,19 +85,19 @@ static inline void shr(size_t p[2], int n)
{
size_t bits = sizeof(size_t) * 8;
- if (n >= 8 * sizeof(size_t)) {
- n -= 8 * sizeof(size_t);
+ if (n >= (int)bits) {
+ n -= (int)bits;
p[0] = p[1];
p[1] = 0;
}
p[0] >>= n;
- p[0] |= (n > 0 && n < bits) ? p[1] << (bits - n) : 0;
+ p[0] |= (n > 0 && n < (int)bits) ? p[1] << (bits - n) : 0;
p[1] >>= n;
}
static void sift(unsigned char *head, size_t width, cmpfun cmp, void *arg,
- int pshift, size_t lp[])
+ int pshift, size_t lp[], int max_lp_index)
{
unsigned char *rt, *lf;
unsigned char *ar[14 * sizeof(size_t) + 1];
@@ -102,6 +105,9 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, void *arg,
ar[0] = head;
while (pshift > 1) {
+ if (pshift - 2 < 0 || pshift - 2 > max_lp_index)
+ break;
+
rt = head - width;
lf = head - width - lp[pshift - 2];
@@ -162,7 +168,7 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, void *arg,
}
if (!trusty) {
cycle(width, ar, i);
- sift(head, width, cmp, arg, pshift, lp);
+ sift(head, width, cmp, arg, pshift, lp, max_lp_index);
}
}
@@ -190,16 +196,17 @@ void qsort_r(void *base, size_t nel, size_t width, cmpfun cmp, void *arg)
while (head < high) {
if ((p[0] & 3) == 3) {
- sift(head, width, cmp, arg, pshift, lp);
+ sift(head, width, cmp, arg, pshift, lp, max_lp_index);
shr(p, 2);
pshift += 2;
} else {
if (pshift - 1 >= 0 && pshift - 1 <= max_lp_index &&
- lp[pshift - 1] >= high - head) {
+ lp[pshift - 1] >= (size_t)(high - head)) {
trinkle(head, width, cmp, arg, p, pshift, 0, lp,
max_lp_index);
} else {
- sift(head, width, cmp, arg, pshift, lp);
+ sift(head, width, cmp, arg, pshift, lp,
+ max_lp_index);
}
if (pshift == 1) {
diff --git a/lib/libc/stdlib/strtox.c b/lib/libc/stdlib/strtox.c
index 9d72954a..e924e5e6 100644
--- a/lib/libc/stdlib/strtox.c
+++ b/lib/libc/stdlib/strtox.c
@@ -66,7 +66,6 @@ __scanint(const char *s, int base, unsigned long long lim, int *neg, char **end)
static long double __scanfloat(const char *s, char **end)
{
long double value = 0.0;
- long double frac = 0.0;
long double sign = 1.0;
long double scale = 1.0;
int exp_sign = 1;
diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c
index 4f560ce1..95f8d732 100644
--- a/lib/libc/stdlib/system.c
+++ b/lib/libc/stdlib/system.c
@@ -2,6 +2,7 @@
int system(const char *command)
{
+ (void)command;
// TODO
return 0;
}