Skip to content

Commit

Permalink
implement stdlib.h stubs. This allows things to be pulled in that are…
Browse files Browse the repository at this point in the history
…nt completely freestanding.
  • Loading branch information
braindigitalis committed May 27, 2023
1 parent 914dcec commit 2c1f0e9
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 78 deletions.
2 changes: 1 addition & 1 deletion include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "kmalloc.h"
#include "pci.h"
#include "maths.h"
#include "pngle.h"
#include "stdlib.h"
#include "devicename.h"
#include "interrupt.h"
#include "ahci.h"
Expand Down
74 changes: 0 additions & 74 deletions include/pngle.h

This file was deleted.

6 changes: 3 additions & 3 deletions include/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ enum
STBI_rgb_alpha = 4
};

//#include <stdlib.h>
#include <stdlib.h>
typedef unsigned char stbi_uc;
typedef unsigned short stbi_us;

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

#include <stdarg.h>
#include <stddef.h> // ptrdiff_t on osx
//#include <stdlib.h>
//#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
Expand Down
62 changes: 62 additions & 0 deletions include/stdlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @file stdlib.h
* @author Craig Edwards
* @brief Standard library stubs
* @date 2023-05-27
* @copyright Copyright (c) 2023
*/
#include <stddef.h>
#include <stdint.h>

#pragma once

typedef struct div_t {
int quot;
int rem;
} div_t;

typedef struct ldiv_t {
long int quot;
long int rem;
} ldiv_t;

typedef char schar_t;

double strtod(const char *str, char **endptr);

long int strtol(const char *str, char **endptr, int base);

unsigned long int strtoul(const char *str, char **endptr, int base);

void abort(void);

int atexit(void (*func)(void));

void exit(int status);

char *getenv(const char *name);

int system(const char *string);

void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *));

void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*));

div_t div(int numer, int denom);

ldiv_t ldiv(long int numer, long int denom);

int rand(void);

void srand(unsigned int seed);

int mblen(const char *str, size_t n);

size_t mbstowcs(schar_t *pwcs, const char *str, size_t n);

int mbtowc(wchar_t *pwc, const char *str, size_t n);

size_t wcstombs(char *str, const wchar_t *pwcs, size_t n);

int wctomb(char *str, wchar_t wchar);

2 changes: 2 additions & 0 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ int strnicmp(const char* s1, const char* s2, uint32_t n);

char toupper(char low);

int isupper(const char x);

char tolower(char low);

int isalnum(const char x);
Expand Down
Loading

0 comments on commit 2c1f0e9

Please sign in to comment.