Skip to content

Commit 2c1f0e9

Browse files
implement stdlib.h stubs. This allows things to be pulled in that arent completely freestanding.
1 parent 914dcec commit 2c1f0e9

File tree

7 files changed

+359
-78
lines changed

7 files changed

+359
-78
lines changed

include/kernel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "kmalloc.h"
2929
#include "pci.h"
3030
#include "maths.h"
31-
#include "pngle.h"
31+
#include "stdlib.h"
3232
#include "devicename.h"
3333
#include "interrupt.h"
3434
#include "ahci.h"

include/pngle.h

-74
This file was deleted.

include/stb_image.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ enum
381381
STBI_rgb_alpha = 4
382382
};
383383

384-
//#include <stdlib.h>
384+
#include <stdlib.h>
385385
typedef unsigned char stbi_uc;
386386
typedef unsigned short stbi_us;
387387

@@ -584,8 +584,8 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
584584

585585
#include <stdarg.h>
586586
#include <stddef.h> // ptrdiff_t on osx
587-
//#include <stdlib.h>
588-
//#include <string.h>
587+
#include <stdlib.h>
588+
#include <string.h>
589589
#include <limits.h>
590590

591591
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)

include/stdlib.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @file stdlib.h
3+
* @author Craig Edwards
4+
* @brief Standard library stubs
5+
* @date 2023-05-27
6+
* @copyright Copyright (c) 2023
7+
*/
8+
#include <stddef.h>
9+
#include <stdint.h>
10+
11+
#pragma once
12+
13+
typedef struct div_t {
14+
int quot;
15+
int rem;
16+
} div_t;
17+
18+
typedef struct ldiv_t {
19+
long int quot;
20+
long int rem;
21+
} ldiv_t;
22+
23+
typedef char schar_t;
24+
25+
double strtod(const char *str, char **endptr);
26+
27+
long int strtol(const char *str, char **endptr, int base);
28+
29+
unsigned long int strtoul(const char *str, char **endptr, int base);
30+
31+
void abort(void);
32+
33+
int atexit(void (*func)(void));
34+
35+
void exit(int status);
36+
37+
char *getenv(const char *name);
38+
39+
int system(const char *string);
40+
41+
void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *));
42+
43+
void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*));
44+
45+
div_t div(int numer, int denom);
46+
47+
ldiv_t ldiv(long int numer, long int denom);
48+
49+
int rand(void);
50+
51+
void srand(unsigned int seed);
52+
53+
int mblen(const char *str, size_t n);
54+
55+
size_t mbstowcs(schar_t *pwcs, const char *str, size_t n);
56+
57+
int mbtowc(wchar_t *pwc, const char *str, size_t n);
58+
59+
size_t wcstombs(char *str, const wchar_t *pwcs, size_t n);
60+
61+
int wctomb(char *str, wchar_t wchar);
62+

include/string.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ int strnicmp(const char* s1, const char* s2, uint32_t n);
2525

2626
char toupper(char low);
2727

28+
int isupper(const char x);
29+
2830
char tolower(char low);
2931

3032
int isalnum(const char x);

0 commit comments

Comments
 (0)