New repo setup

This commit is contained in:
2024-05-28 14:50:00 -05:00
commit f68c320396
51 changed files with 4612 additions and 0 deletions

58
include/dirent.h Normal file
View File

@@ -0,0 +1,58 @@
#ifndef _DIRENT_H
#define _DIRENT_H
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long ino_t;
typedef signed int off_t;
typedef struct dirent {
ino_t d_ino;
off_t d_off;
unsigned short d_reclen;
unsigned char d_type;
char d_name[];
} DIR;
enum
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
# define DT_FIFO DT_FIFO
DT_CHR = 2,
# define DT_CHR DT_CHR
DT_DIR = 4,
# define DT_DIR DT_DIR
DT_BLK = 6,
# define DT_BLK DT_BLK
DT_REG = 8,
# define DT_REG DT_REG
DT_LNK = 10,
# define DT_LNK DT_LNK
DT_SOCK = 12,
# define DT_SOCK DT_SOCK
DT_WHT = 14
# define DT_WHT DT_WHT
};
int alphasort(const struct dirent **, const struct dirent **);
int closedir(DIR *);
int dirfd(DIR *);
DIR *fdopendir(int);
DIR *opendir(const char *);
struct dirent *readdir(DIR *);
int readdir_r(DIR *restrict, struct dirent *restrictis, struct dirent **restricts);
void rewinddir(DIR *);
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
void seekdir(DIR *, long);
long telldir(DIR *);
#ifdef __cplusplus
}
#endif
#endif

0
include/dup.h Normal file
View File

0
include/fork.h Normal file
View File

257
include/math.h Normal file
View File

@@ -0,0 +1,257 @@
#ifndef _MATH_H_
#define _MATH_H_
#define HUGE_VAL (__builtin_huge_val())
#ifdef __cplusplus
extern "C"
{
#endif
// trig stuff
double cos(double x);
float cosf(float x);
long double cosl(long double x);
double sin(double x);
float sinf(float x);
long double sinl(long double x);
double tan(double x);
float tanf(float x);
long double tanl(long double x);
double acos(double x);
float acosf(float x);
long double acosl(long double x);
double asin(double x);
float asinf(float x);
long double asinl(long double x);
double atan(double x);
float atanf(float x);
long double atanl(long double x);
double cosh(double x);
float coshf(float x);
long double coshl(long double x);
double sinh(double x);
float sinhf(float x);
long double sinhl(long double x);
double tanh(double x);
float tanhf(float x);
long double tanhl(long double x);
double acosh(double x);
float acoshf(float x);
long double coshl(long double x);
double asinh(double x);
float asinhf(float x);
long double asinhl(long double x);
double atanh(double x);
float atanhf(float x);
long double atanhl(long double x);
// exp stuff
double fac(double x);
float facf(float x);
long double facl(long double x);
double exp(double x);
float expf(float x);
long double expl(long double x);
double frexp(double x, int *exp);
float frexpf(float x, int *exp);
long double frexpl(long double x, int *exp);
double ldexp(double x, int exp);
float ldexpf(float x, int exp);
long double ldexpl(long double x, int exp);
double log(double x);
float logf(float x);
long double logl(long double x);
double log10(double x);
float log10f(float x);
long double log10l(long double x);
double modf(double x, double *intpart);
float modff(float x, float *intpart);
long double modfl(long double x, long double *intpart);
double exp2(double x);
float exp2f(float x);
long double exp2l(long double x);
double expm1(double x);
float expm1f(float x);
long double expm1l(long double x);
int ilogb(double x);
int ilogbf(float x);
int ilogbl(long double x);
double log1p(double x);
float log1pf(float x);
long double log1pl(long double x);
double log2(double x);
float log2f(float x);
long double log2l(long double x);
double logb(double x);
float logbf(float x);
long double logbl(long double x);
double scalbn(double x, int n);
float scalbnf(float x, int n);
long double scalbnl(long double x, int n);
double scalbln(double x, long int n);
float scalblnf(float x, long int n);
long double scalblnl(long double x, long int n);
// pow stuff
double pow(double base, double exponent);
float powf(float base, float exponent);
long double powl(long double base, long double exponent);
double sqrt(double x);
float sqrtf(float x);
long double sqrtl(long double x);
double cbrt(double x);
float cbrtf(float x);
long double cbrtl(long double x);
double hypot(double x, double y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);
// gamma stuff
double erf(double x);
float erff(float x);
long double erfl(long double x);
double erfc(double x);
float erfcf(float x);
long double erfcl(long double x);
double tgamma(double x);
float tgammaf(float x);
long double tgammal(long double x);
double lgamma(double x);
float lgammaf(float x);
long double lgammal(long double x);
// rounding stuff
double ceil(double x);
float ceilf(float x);
long double ceill(long double x);
double floor(double x);
float floorf(float x);
long double floorl(long double x);
double fmod(double numer, double denom);
float fmodf(float numer, float denom);
long double fmodl(long double numer, long double denom);
double trunc(double x);
float truncf(float x);
long double truncl(long double x);
double round(double x);
float roundf(float x);
long double roundl(long double x);
long int lround(double x);
long int lroundf(float x);
long int lroundl(long double x);
long long int llround(double x);
long long int llroundf(float x);
long long int llroundl(long double x);
double rint(double x);
float rintf(float x);
long double rintl(long double x);
long int lrint(double x);
long int lrintf(float x);
long int lrintl(long double x);
long long int llrint(double x);
long long int llrintf(float x);
long long int llrintl(long double x);
double nearbyint(double x);
float nearbyintf(float x);
long double nearbyintl(long double x);
double remainder(double numer, double denom);
float remainderf(float numer, float denom);
long double remainderl(long double numer, long double denom);
double remquo(double numer, double denom, int *quot);
float remquof(float numer, float denom, int *quot);
long double remquol(long double numer, long double denom, int *quot);
// float stuff
double copysign(double x, double y);
float copysignf(float x, float y);
long double copysignl(long double x, long double y);
double nan(const char *tagp);
double nextafter(double x, double y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y);
double nexttoward(double x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y);
// min stuff
double fdim(double x, double y);
float fdimf(float x, float y);
long double fdiml(long double x, long double y);
double fmax(double x, double y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
double fmin(double x, double y);
float fminf(float x, float y);
long double fminl(long double x, long double y);
// other stuff
double fabs(double x);
float fabsf(float x);
long double fabsl(long double x);
double fma(double x, double y, double z);
float fmaf(float x, float y, float z);
long double fmal(long double x, long double y, long double z);
#ifdef __cplusplus
}
#endif
#endif

63
include/stdio.h Normal file
View File

@@ -0,0 +1,63 @@
#ifndef _STDIO_H_
#define _STDIO_H_
#define _IOFBF 1
#define _IOLBF 2
#define _IONBF 4
#define BUFSIZ 4096
#ifdef __cplusplus
extern "C"
{
#endif
#define __need_size_t
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#define SEEK_SET 0 /*unspecified*/
#define SEEK_CUR 1 /*unspecified*/
#define SEEK_END 2 /*unspecified*/
typedef int FILE;
extern const int fd_stdin;
extern const int fd_stdout;
extern const int fd_stderr;
#define stdin &fd_stdin
#define stdout &fd_stdout
#define stderr &fd_stderr
static const int EOF = -1; // MACRO???
int getchar();
int printf(const char *format, ...);
int scanf(const char *format, ...);
char *fgets(char *str, int n, FILE *stream);
int fgetc(FILE *stream);
static inline int getc(FILE *stream) { return fgetc(stream); };
int fputc(int ch, FILE *stream); // TODO
static inline int putc(int ch, FILE *stream) { return fputc(ch, stream); };
long ftell(FILE *stream);
int fseek(FILE *stream, long offset, int origin);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *dest, const char *format, ...);
int vfprintf(FILE *stream, const char *format, va_list arg);
int vprintf(const char *format, va_list arg);
int vsprintf(char *s, const char *format, va_list arg);
int vsnprintf(char *s, size_t n, const char *format, va_list arg);
int snprintf(char *s, size_t n, const char *format, ...);
int sscanf(const char *ibuf, const char *fmt, ...);
int vsscanf(const char *inp, char const *fmt0, va_list ap);
int fscanf(FILE *stream, const char *format, ...);
int vfscanf(FILE *stream, const char *format, va_list arg);
int mkdir(const char *pathname);
#ifdef __cplusplus
}
#endif
#endif

45
include/stdlib.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef CROS_STDLIB_H
#define CROS_STDLIB_H
#include <stddef.h>
#include "stdio.h"
#ifdef __cplusplus
extern "C" {
#endif
int dup(int fd);
int dup2(int oldfd, int newfd); // I NEED dup2() FOR THE SHELL -connor
int fork(); // TODO:
int wait(int *addr); // TODO:
void exit(int status); // TODO:
FILE *fopen(const char *filename, const char *mode); // TODO:
int *fclose(FILE *stream); // TODO:
void* malloc(size_t size);
void* realloc(void* ptr, size_t size);
void free(void* ptr);
int rand(void);
void srand(unsigned int seed);
//conversions
double atof (const char* str);
long int atol (const char* str);
long long atoll (const char * str);
int atoi (const char * str);
double strtod (const char* str, char** endptr);
float strtof (const char* str, char** endptr);
long double strtold (const char* str, char** endptr);
long int strtol (const char* str, char** endptr, int base);
long long int strtoll (const char* str, char** endptr, int base);
unsigned long int strtoul (const char* str, char** endptr, int base);
unsigned long long int strtoull (const char* str, char** endptr, int base);
#ifdef __cplusplus
}
#endif
#endif

54
include/string Normal file
View File

@@ -0,0 +1,54 @@
#ifndef STRING_H
#define STRING_H
#include <stddef.h>
namespace std {
class string {
public:
string();
string(const char* other);
string(const string& other);
~string();
int size() const;
size_t find(const string& str, size_t pos = 0) const;
string& erase(size_t pos, size_t len);
bool operator==(const string& other) const;
bool operator!=(const string& other) const;
string& operator=(char c);
string& operator=(const char* other);
string& operator=(const string& other);
string operator+(char other) const;
string operator+(const char* other) const;
string operator+(const string& other) const;
string& operator+=(char c);
string& operator+=(const char* other);
string& operator+=(const string& other);
const char& operator[](int index) const;
const char* c_str() const;
string substr(int start_index) const;
string substr(int start_index, int end_index) const;
static bool strcmp(const char* first, const char* second); // differs from standard implemtation
static char* substr(const char* str, int start_index);
static char* substr(const char* str, int start_index, int end_index);
static char* strdup(const char* s);
static void strcpy(char*& dest, const char* src); // differs from standard implemtation, allocates more memory in destination string if its not big enough
static void strncpy(char*& dest, const char* src, int len); // ^
static void strcat(char*& dest, const char* src); // ^
static int strlen(const char* s); // doesn't include the null-terminator
static const size_t npos = -1;
private:
char* s;
};
} // namespace std
#endif

41
include/string.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef _STRING_H
#define _STRING_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
int memcmp(const void *ptr1, const void *ptr2, size_t n);
void *memset(void *ptr, int value, size_t num);
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
int strcmp(const char *str1, const char *str2);
int strncmp(const char *str1, const char *str2, size_t n);
char *strcat(char *dest, const char *src);
char *strncat(char *dest, const char *src, size_t n);
size_t strlen(const char *str);
// useless stuff
int strcoll(const char *str1, const char *str2);
size_t strxfrm(char *dest, const char *src, size_t n);
const void *memchr(const void *ptr, int val, size_t n);
const char *strchr(const char *str, int c);
size_t strcspn(const char *str1, const char *str2);
const char *strpbrk(const char *str1, const char *str2);
const char *strrchr(const char *str, int c);
size_t strspn(const char *str1, const char *str2);
const char *strstr(const char *str1, const char *str2);
char *strtok(char *str, const char *delims);
char *strerror(int errnum);
#ifdef __cplusplus
}
#endif
#endif

27
include/time.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef _TIME_H
#define _TIME_H
/*#ifdef __cplusplus
extern "C"{
#endif
#include <stddef.h>
typedef unsigned long time_t;
struct Time_Structure {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
} typedef tm;
time_t time (time_t* timer);
}*/
#endif

25
include/unistd.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef _UNISTD_H
#define _UNISTD_H
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include <types/pid.h>
int execve(const char *path, char *argv[],
char const *envp[]);
int execvp(const char *file, char const *argv[]);
int *getcwd(char *, size_t);
int close(int fd);
int open(int fd);
int chdir(const char *path);
int pipe(int fildes[2]);
#ifdef __cplusplus
}
#endif
#endif

191
include/vector Normal file
View File

@@ -0,0 +1,191 @@
#ifndef VECTOR_H
#define VECTOR_H
#include <stdlib.h>
#include <string.h>
inline void *operator new(size_t, void *p) throw()
{
return p;
}
inline void *operator new[](size_t, void *p) throw()
{
return p;
}
inline void operator delete(void *, void *) throw()
{
}
inline void operator delete[](void *, void *) throw()
{
}
namespace std
{
template <typename T>
class vector
{
public:
vector();
vector(int capacity);
vector(const vector<T> &other);
~vector();
bool empty() const;
int size() const;
int capacity() const;
void push_back(const T &data);
void pop_back();
T &back();
T &front();
void remove(int index);
void clear();
void resize(int new_capacity);
T &operator[](int index) const;
private:
T *array;
int _capacity;
int _size;
};
template <typename T>
vector<T>::vector()
{
_size = 0;
_capacity = 8;
array = malloc(sizeof(T) * _capacity);
memset((void *)array, 0, sizeof(T) * _capacity);
// array = new T[_capacity];
}
template <typename T>
vector<T>::vector(int capacity)
{
_size = 0;
_capacity = capacity;
array = malloc(sizeof(T) * _capacity);
memset((void *)array, 0, sizeof(T) * _capacity);
// array = new T[_capacity];
}
template <typename T>
vector<T>::vector(const vector<T> &other)
{
_size = other.size();
_capacity = other.capacity();
array = malloc(sizeof(T) * _capacity);
memset((void *)array, 0, sizeof(T) * _capacity);
// array = new T[_capacity];
for (int i = 0; i < _size; i++)
array[i] = other[i];
}
template <typename T>
vector<T>::~vector()
{
for (int i = 0; i < _size; i++)
{
array[i].~T();
}
free(array);
// if (array != nullptr)
// delete[] array;
}
template <typename T>
bool vector<T>::empty() const
{
return _size == 0;
}
template <typename T>
int vector<T>::size() const
{
return _size;
}
template <typename T>
int vector<T>::capacity() const
{
return _capacity;
}
template <typename T>
T &vector<T>::operator[](int index) const
{
return array[index];
}
template <typename T>
void vector<T>::push_back(const T &data)
{
if (_size == _capacity)
resize(_capacity * 2);
new (&array[_size]) T(data);
// array[_size] = data;
_size++;
}
template <typename T>
void vector<T>::pop_back()
{
array[_size - 1].~T();
_size--;
}
template <typename T>
T &vector<T>::back()
{
return array[_size - 1];
}
template <typename T>
T &vector<T>::front()
{
return array[0];
}
template <typename T>
void vector<T>::remove(int index)
{
while (index < _size - 1)
{
array[index] = array[index + 1];
index++;
}
pop_back();
}
template <typename T>
void vector<T>::clear()
{
for (int i = 0; i < _size; i++)
array[i].~T();
_size = 0;
}
template <typename T>
void vector<T>::resize(int new_capacity)
{
_capacity = new_capacity;
// T *temp = new T[_capacity];
T *temp = malloc(sizeof(T) * _capacity);
memset((void *)temp, 0, sizeof(T) * _capacity);
for (int i = 0; i < _size; i++)
{
new (&temp[i]) T(array[i]);
// temp[i] = array[i];
}
// delete[] array;
free(array);
array = temp;
}
}
#endif

0
include/wait.h Normal file
View File