From 77c2abd2472457c9e936ecc0e41bc896b37b1afd Mon Sep 17 00:00:00 2001 From: Gitea Date: Tue, 1 Dec 2020 17:40:03 -0600 Subject: [PATCH] Added a bunch of stuff --- Some libc slash libk todos | 120 +++++++++++++ arch/i386/crt0.s | 29 ++++ arch/i386/inb.s | 8 + include/assert.h | 12 ++ include/cpio.h | 34 ++++ include/ctype.h | 47 +++++ include/float.h | 24 +++ include/netinet/in.h | 55 ++++++ include/sys/io.h | 6 + include/sys/socket.h | 24 +++ include/sys/un.h | 22 +++ include/sys/utsname.h | 14 ++ include/sys/wait.h | 34 ++++ include/syslog.h | 48 ++++++ include/tar.h | 32 ++++ include/time.h | 30 ++++ include/types/clock_t.h | 6 + include/types/clockid_t.h | 6 + include/types/dev_t.h | 6 + include/types/gid_t.h | 8 + include/types/id_t.h | 6 + include/types/locale_t.h | 4 + include/types/mode_t.h | 6 + include/types/off_t.h | 6 + include/types/pid_t.h | 8 + include/types/ptrdiff_t.h | 6 + include/types/sa_family_t.h | 6 + include/types/size_t.h | 6 + include/types/ssize_t.h | 6 + include/types/suseconds_t.h | 6 + include/types/time_t.h | 6 + include/types/timer_t.h | 6 + include/types/uid_t.h | 8 + include/types/wchar_t.h | 6 + include/ulimit.h | 20 +++ libgen/basename.c | 71 ++++++++ libgen/dirname.c | 42 +++++ math/cos.c | 91 ++++++++++ math/cosf.c | 32 ++++ math/cosl.c | 32 ++++ math/fabs.c | 10 ++ math/fabsf.c | 10 ++ math/fabsl.c | 10 ++ projects/fenix/sysroot/usr/include/errno.h | 99 +++++++++++ projects/fenix/sysroot/usr/include/iso646.h | 33 ++++ projects/fenix/sysroot/usr/include/limits.h | 161 ++++++++++++++++++ projects/fenix/sysroot/usr/include/math.h | 102 +++++++++++ projects/fenix/sysroot/usr/include/stddef.h | 24 +++ projects/fenix/sysroot/usr/include/stdio.h | 14 ++ projects/fenix/sysroot/usr/include/stdlib.h | 64 +++++++ projects/fenix/sysroot/usr/include/string.h | 15 ++ .../fenix/sysroot/usr/include/sys/cdefs.h | 6 + .../fenix/sysroot/usr/include/sys/types.h | 69 ++++++++ stdio/perror.c | 7 + stdlib/abs.c | 6 + stdlib/div.c | 8 + stdlib/labs.c | 6 + stdlib/ldiv.c | 8 + stdlib/llabs.c | 6 + stdlib/lldiv.c | 8 + stdlib/rand.c | 64 +++++++ string/strcat.c | 36 ++++ string/strcmp.c | 12 ++ string/strcspn.c | 22 +++ string/strtok.c | 30 ++++ time/time.c | 39 +++++ 66 files changed, 1808 insertions(+) create mode 100644 Some libc slash libk todos create mode 100644 arch/i386/crt0.s create mode 100644 arch/i386/inb.s create mode 100644 include/assert.h create mode 100644 include/cpio.h create mode 100644 include/ctype.h create mode 100644 include/float.h create mode 100644 include/netinet/in.h create mode 100644 include/sys/io.h create mode 100644 include/sys/socket.h create mode 100644 include/sys/un.h create mode 100644 include/sys/utsname.h create mode 100644 include/sys/wait.h create mode 100644 include/syslog.h create mode 100644 include/tar.h create mode 100644 include/time.h create mode 100644 include/types/clock_t.h create mode 100644 include/types/clockid_t.h create mode 100644 include/types/dev_t.h create mode 100644 include/types/gid_t.h create mode 100644 include/types/id_t.h create mode 100644 include/types/locale_t.h create mode 100644 include/types/mode_t.h create mode 100644 include/types/off_t.h create mode 100644 include/types/pid_t.h create mode 100644 include/types/ptrdiff_t.h create mode 100644 include/types/sa_family_t.h create mode 100644 include/types/size_t.h create mode 100644 include/types/ssize_t.h create mode 100644 include/types/suseconds_t.h create mode 100644 include/types/time_t.h create mode 100644 include/types/timer_t.h create mode 100644 include/types/uid_t.h create mode 100644 include/types/wchar_t.h create mode 100644 include/ulimit.h create mode 100644 libgen/basename.c create mode 100644 libgen/dirname.c create mode 100644 math/cos.c create mode 100644 math/cosf.c create mode 100644 math/cosl.c create mode 100644 math/fabs.c create mode 100644 math/fabsf.c create mode 100644 math/fabsl.c create mode 100755 projects/fenix/sysroot/usr/include/errno.h create mode 100755 projects/fenix/sysroot/usr/include/iso646.h create mode 100755 projects/fenix/sysroot/usr/include/limits.h create mode 100755 projects/fenix/sysroot/usr/include/math.h create mode 100755 projects/fenix/sysroot/usr/include/stddef.h create mode 100755 projects/fenix/sysroot/usr/include/stdio.h create mode 100755 projects/fenix/sysroot/usr/include/stdlib.h create mode 100755 projects/fenix/sysroot/usr/include/string.h create mode 100755 projects/fenix/sysroot/usr/include/sys/cdefs.h create mode 100755 projects/fenix/sysroot/usr/include/sys/types.h create mode 100644 stdio/perror.c create mode 100644 stdlib/abs.c create mode 100644 stdlib/div.c create mode 100644 stdlib/labs.c create mode 100644 stdlib/ldiv.c create mode 100644 stdlib/llabs.c create mode 100644 stdlib/lldiv.c create mode 100644 stdlib/rand.c create mode 100644 string/strcat.c create mode 100644 string/strcmp.c create mode 100644 string/strcspn.c create mode 100644 string/strtok.c create mode 100644 time/time.c diff --git a/Some libc slash libk todos b/Some libc slash libk todos new file mode 100644 index 0000000..a815e3f --- /dev/null +++ b/Some libc slash libk todos @@ -0,0 +1,120 @@ +/* NB: This list is ordered. i.e. cat needs stuff from asa to work! */ + +For sh +====== + +stdio.h +******* +fgets() + +stdlib.h +******** +exit() +free() +calloc() + +unistd.h +******** +chdir() +fork() +execvp() +getcwd() + +sys/wait.h +********** +waitpid() + +signal.h +******** +signal() +SIG_DFL +SIG_IGN + +For asa +======= + +stdio.h +******* +fprintf() +fgetc() +fopen() +fclose() + +For cal +======= + +stdio.h +******* +fileno() + +unistd.h +******** +isatty() + +For cat +======= + +unistd.h +******** +write() + +For cksum +========= + +stdio.h +******* +fseek() +SEEK_SET + +For expand +========== + +stdlib.h +******** +malloc() (if not already implemented for calloc) + +For link +======== + +unistd.h +******** +link() + +For ln +====== + +unistd.h +******** +access() +unlink() +symlink() + +fcntl.h +******* +AT_SYMLINK_FOLLOW +linkat() +AT_FDCWD + +sys/stat.h +********** +struct stat +lstat() +S_ISLNK + +string.h +******** +strcpy() + +For pwd +======= + +stdlib.h +******** +getenv(); + +For tty +======= + +unistd.h +******** +ttyname() \ No newline at end of file diff --git a/arch/i386/crt0.s b/arch/i386/crt0.s new file mode 100644 index 0000000..d6eb67d --- /dev/null +++ b/arch/i386/crt0.s @@ -0,0 +1,29 @@ + .section .text + .global _start +_start: + # Set up end of stack frame linked list + movl $0, %ebp + pushl %ebp # rip = 0 + pushl %ebp # ebp = 0 + movl %esp, %ebp + + pushl %esi + pushl %edi + + # Prepare signals, memory alloc, stdio, etc. + call initialize_standard_library + + # Run global constructors + call _init + + # restore argc/argv + popl %edi + popl %esi + + # Run main + call main + + # Terminate with exit code + movl %eax, %edi + call exit + .size _start, . - _start diff --git a/arch/i386/inb.s b/arch/i386/inb.s new file mode 100644 index 0000000..482fa9a --- /dev/null +++ b/arch/i386/inb.s @@ -0,0 +1,8 @@ + .globl inb + .p2align 2 + .type inb,%function + +inb: + .fnstart + + .fnend diff --git a/include/assert.h b/include/assert.h new file mode 100644 index 0000000..8d5b7f0 --- /dev/null +++ b/include/assert.h @@ -0,0 +1,12 @@ +#ifndef _ASSERT_H +#define _ASSERT_H + +#include + +#ifdef NDEBUG +#define assert(ignore) ((void) 0) +#else +#define assert(expression) (expression || (fprintf(stderr, "%s: %d: %s", __FILE__, __LINE__, __func__) && abort())) +#endif + +#endif diff --git a/include/cpio.h b/include/cpio.h new file mode 100644 index 0000000..f15c5f4 --- /dev/null +++ b/include/cpio.h @@ -0,0 +1,34 @@ +#ifndef _CPIO_H +#define _CPIO_H + +/* Constants needed by the c_mode field of the cpio archive format */ +/* User permissions */ +#define C_IRUSR 0000400 +#define C_IWUSR 0000200 +#define C_IXUSR 0000100 + +/* Group permissions */ +#define C_IRGRP 0000040 +#define C_IWGRP 0000020 +#define C_IXGRP 0000010 + +/* Other folx permission */ +#define C_IROTH 0000004 +#define C_IWOTH 0000002 +#define C_IXOTH 0000001 + +#define C_ISUID 0004000 /* Set UID */ +#define C_ISGID 0002000 /* Set GID */ +#define C_ISVTX 0001000 /* Restricted deletion flag for directories */ + +#define C_ISFIFO 0010000 /* FIFO/Pipe */ +#define C_ISREG 0100000 /* Regular file */ +#define C_ISBLK 0060000 /* Block device */ +#define C_ISCHR 0020000 /* Character special */ +#define C_ISCTG 0110000 /* Reserved */ +#define C_ISLNK 0120000 /* Symbolic link */ +#define C_ISSOCK 0140000 /* Socket */ + +#define MAGIC "070707" + +#endif diff --git a/include/ctype.h b/include/ctype.h new file mode 100644 index 0000000..6c47c31 --- /dev/null +++ b/include/ctype.h @@ -0,0 +1,47 @@ +#ifndef _CTYPE_H +#define _CTYPE_H + +#include + +/* C standard functions */ +int isalnum(int); +int isalpha(int); +int isblank(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); + +/* POSIX extensions */ +int isalnum_l(int, locale_t); +int isalpha_l(int, locale_t); +int isblank_l(int, locale_t); +int iscntrl_l(int, locale_t); +int isdigit_l(int, locale_t); +int isgraph_l(int, locale_t); +int islower_l(int, locale_t); +int isprint_l(int, locale_t); +int ispunct_l(int, locale_t); +int isspace_l(int, locale_t); +int isupper_l(int, locale_t); +int isxdigit_l(int, locale_t); + +/* C standard stuff */ +int toascii(int); +int tolower(int); +int toupper(int); + +/* POSIX extensions */ +int tolower_l(int, locale_t); +int toupper_l(int, locale_t); + +/* Obsolete XSI macros */ +#define _toupper(x) toupper(x) +#define _tolower(x) tolower(x) + +#endif diff --git a/include/float.h b/include/float.h new file mode 100644 index 0000000..a6b4d6c --- /dev/null +++ b/include/float.h @@ -0,0 +1,24 @@ +#ifndef _FLOAT_H +#define _FLOAT_H + +#define FLT_ROUNDS 1 + +#define FLT_EVAL_METHOD 0 + +#define FLT_RADIX 2 + +#define FLT_MANT_DIG 24 +#define DBL_MANT_DIG 53 +#define LDBL_MANT_DIG 113 + +#define DECIMAL_DIG 10 + +#define FLT_DIG 6 +#define DBL_DIG 10 +#define LDBL_DIG 10 + +#define FLT_MIN_10_EXP -37 +#define DBL_MIN_10_EXP -37 +#define LDBL_MIN_10_EXP -37 + +#endif diff --git a/include/netinet/in.h b/include/netinet/in.h new file mode 100644 index 0000000..3876959 --- /dev/null +++ b/include/netinet/in.h @@ -0,0 +1,55 @@ +#ifndef _NETINET_IN_H +#define _NETINET_IN_H + +#include +#include + +#ifndef __have_in_port_t +#define __have_in_port_t +typedef uint16_t in_port_t; +#endif + +#ifndef __have_in_addr_t +#define __have_in_addr_t +typedef uint32_t in_addr_t; +#endif + +typedef struct _ipv4_in_addr { + in_addr_t s_addr; +} in_addr; + +typedef struct _ipv4_sockaddr_in { + sa_family_t sin_family; + in_port_t sin_port; + in_addr sin_addr; +} sockaddr_in; + +typedef struct _ipv6_in_addr { + uint8_t s6_addr[16]; +} in6_addr; + +typedef struct _ipv6_sockaddr_in { + sa_family_t sin6_family; + in_port_t sin6_port; + uint32_t sin6_flowinfo; + in6_addr sin6_addr; + uint32_t sin6_scope_id; +} sockaddr_in6; + +extern const in6_addr in6addr_any; +extern const in6_addr in6addr_loopback; +/* Need INIT macros for the above */ + +typedef struct _ipv6_mreq { + int6_addr ipv6mr_multiaddr; + unsigned ipv6mr_interface; +} ipv6_mreq; + +#define IPPROTO_IP 4 +#define IPPROTO_IPV6 6 +#define IPPROTO_ICMP 1 +#define IPPROTO_RAW 2 +#define IPPROTO_TCP 5 +#define IPPROTO_UDP 7 + +#endif diff --git a/include/sys/io.h b/include/sys/io.h new file mode 100644 index 0000000..6afa261 --- /dev/null +++ b/include/sys/io.h @@ -0,0 +1,6 @@ +#ifndef _SYS_IO_H +#define _SYS_IO_H + +extern unsigned char inb(unsigned short int port); + +#endif diff --git a/include/sys/socket.h b/include/sys/socket.h new file mode 100644 index 0000000..ab31532 --- /dev/null +++ b/include/sys/socket.h @@ -0,0 +1,24 @@ +/* + * - main sockets header + * + * This header is a part of the FENIX C Library and is free software. + * You can redistribute and/or modify it subject to the terms of the + * Clumsy Wolf Public License v4. For more details, see the file COPYING. + * + * The FENIX C Library is distributed WITH NO WARRANTY WHATSOEVER. See + * The CWPL for more details. + */ + +#ifndef _SYS_SOCKET_H +#define _SYS_SOCKET_H + +typedef long int socklen_t; +#include + +typedef struct _socket_address { + sa_family_t sa_family; + char sa_data[]; +} sockaddr; + + +#endif diff --git a/include/sys/un.h b/include/sys/un.h new file mode 100644 index 0000000..307f735 --- /dev/null +++ b/include/sys/un.h @@ -0,0 +1,22 @@ +/* + * - definitions for UNIX domain sockets + * + * This header is a part of the FENIX C Library and is free software. + * You can redistribute and/or modify it subject to the terms of the + * Clumsy Wolf Public License v4. For more details, see the file COPYING. + * + * The FENIX C Library is distributed WITH NO WARRANTY WHATSOEVER. See + * The CWPL for more details. + */ + +#ifndef _SYS_UN_H +#define _SYS_UN_H + +#include + +typedef struct _un_sockaddr { + sa_family_t sun_family + char sun_path[108]; +} sockaddr_un; + +#endif diff --git a/include/sys/utsname.h b/include/sys/utsname.h new file mode 100644 index 0000000..f50d16c --- /dev/null +++ b/include/sys/utsname.h @@ -0,0 +1,14 @@ +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H + +typedef struct _uname { + char sysname[70]; + char nodename[70]; + char release[70]; + char version[70]; + char machine[70]; +} utsname; + +int uname(utsname *); + +#endif diff --git a/include/sys/wait.h b/include/sys/wait.h new file mode 100644 index 0000000..dafe7fb --- /dev/null +++ b/include/sys/wait.h @@ -0,0 +1,34 @@ +/* + * - declarations for waiting + * + * This header is a part of the FENIX C Library and is free software. + * You can redistribute and/or modify it subject to the terms of the + * Clumsy Wolf Public License v4. For more details, see the file COPYING. + * + * The FENIX C Library is distributed WITH NO WARRANTY WHATSOEVER. See + * The CWPL for more details. + */ + +#ifndef _SYS_WAIT_H +#define _SYS_WAIT_H + +/* Constants for waitpid() */ +#define WCONTINUED 1 +#define WNOHANG 2 +#define WUNTRACED 3 + +/* Options for waitid() */ +#define WEXITED 1 +#define WNOWAIT 2 +#define WSTOPPED 3 + +enum idtype_t {P_ALL, P_PGID, P_PID}; + +#include +#include + +pid_t wait(int *); +int waitid(idtype_t, id_t, siginfo_t *, int); +pid_t waitpid(pid_t, int *, int); + +#endif diff --git a/include/syslog.h b/include/syslog.h new file mode 100644 index 0000000..a6b07ed --- /dev/null +++ b/include/syslog.h @@ -0,0 +1,48 @@ +#ifndef _SYSLOG_H +#define _SYSLOG_H + +/* logopt option for openlog() */ +#define LOG_PID 001 +#define LOG_CONS 002 +#define LOG_NDELAY 004 +#define LOG_ODELAY 010 +#define LOG_NOWAIT 020 + +/* facility argument for openlog() */ +#define LOG_KERN 1 +#define LOG_USER 2 +#define LOG_MAIL 3 +#define LOG_NEWS 4 +#define LOG_UUCP 5 +#define LOG_DAEMON 6 +#define LOG_AUTH 7 +#define LOG_CRON 8 +#define LOG_LPR 9 +#define LOG_LOCAL0 10 +#define LOG_LOCAL1 11 +#define LOG_LOCAL2 12 +#define LOG_LOCAL3 13 +#define LOG_LOCAL4 14 +#define LOG_LOCAL5 15 +#define LOG_LOCAL6 16 +#define LOG_LOCAL7 17 + +/* priority argument for syslog() */ +#define LOG_EMERG 1 +#define LOG_CRIT 2 +#define LOG_ALERT 3 +#define LOG_ERROR 4 +#define LOG_WARNING 5 +#define LOG_NOTICE 6 +#define LOG_INFO 7 +#define LOG_DEBUG 8 + +/* I'm not 100% sure how this is supposed to work -Kat */ +#define LOG_MASK(pri) (pri) + +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...); + +#endif diff --git a/include/tar.h b/include/tar.h new file mode 100644 index 0000000..d96b159 --- /dev/null +++ b/include/tar.h @@ -0,0 +1,32 @@ +#ifndef _TAR_H +#define _TAR_H + +#define TMAGIC "ustar" +#define TMAGLEN 6 +#define TVERSION "00" +#define TVERSLEN 2 + +#define REGTYPE '0' /* Regular file */ +#define AREGTYPE '\0' /* Regular file */ +#define LNKTYPE '1' /* Link */ +#define SYMTYPE '2' /* Symbolic link */ +#define CHRTYPE '3' /* Character special */ +#define BLKTYPE '4' /* Block special */ +#define DIRTYPE '5' /* Directory */ +#define FIFOTYPE '6' /* FIFO */ +#define CONTTYPE '7' /* Reserved */ + +#define TSUID 04000 /* Set UID on exec. */ +#define TSGID 02000 /* Set GID on exec. */ +#define TSVTX 01000 /* On dirs, restricted deletion flag */ +#define TUREAD 00400 /* Read by owner */ +#define TUWRITE 00200 /* Write by owner */ +#define TUEXEC 00100 /* Exec./search by owner */ +#define TGREAD 00040 /* Read by group */ +#define TGWRITE 00020 /* Write by group */ +#define TGEXEC 00010 /* Exec./search by group */ +#define TOREAD 00004 /* Read by others */ +#define TOWRITE 00002 /* Write by others */ +#define TOEXEC 00001 /* Exec./search by others */ + +#endif diff --git a/include/time.h b/include/time.h new file mode 100644 index 0000000..1cc00f8 --- /dev/null +++ b/include/time.h @@ -0,0 +1,30 @@ +#ifndef _TIME_H +#define _TIME_H + +#ifndef NULL +#define NULL (void *) 0 +#endif + +#include +#include +#include +#include +#include +#include +#include + +typedef struct _time { + unsigned int tm_sec : 6; + unsigned int tm_min : 6; + unsigned int tm_hour : 5; + unsigned int tm_mday : 5; + unsigned int tm_mon : 4; + unsigned int tm_year; + unsigned int tm_wday : 3; + unsigned int tm_yday : 9; + int tm_isdst : 2; +} tm; + +time_t time(time_t *); + +#endif /* not _HEADER */ diff --git a/include/types/clock_t.h b/include/types/clock_t.h new file mode 100644 index 0000000..1d4cbc7 --- /dev/null +++ b/include/types/clock_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_CLOCK_T_H +#define _TYPES_CLOCK_T_H + +typedef unsigned long long int clock_t; + +#endif diff --git a/include/types/clockid_t.h b/include/types/clockid_t.h new file mode 100644 index 0000000..52ef0b2 --- /dev/null +++ b/include/types/clockid_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_CLOCKID_T_H +#define _TYPES_CLOCKID_T_H + +typedef int clockid_t; + +#endif diff --git a/include/types/dev_t.h b/include/types/dev_t.h new file mode 100644 index 0000000..cca8285 --- /dev/null +++ b/include/types/dev_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_DEV_T_H +#define _TYPES_DEV_T_H + +typedef int dev_t; + +#endif diff --git a/include/types/gid_t.h b/include/types/gid_t.h new file mode 100644 index 0000000..26645a8 --- /dev/null +++ b/include/types/gid_t.h @@ -0,0 +1,8 @@ +#ifndef _TYPES_GID_T_H +#define _TYPES_GID_T_H + +#include + +typedef unsigned id_t gid_t; + +#endif diff --git a/include/types/id_t.h b/include/types/id_t.h new file mode 100644 index 0000000..9a5d5f5 --- /dev/null +++ b/include/types/id_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_ID_T_H +#define _TYPES_ID_T_H + +typedef long int id_t; + +#endif diff --git a/include/types/locale_t.h b/include/types/locale_t.h new file mode 100644 index 0000000..5dc2ad2 --- /dev/null +++ b/include/types/locale_t.h @@ -0,0 +1,4 @@ +#ifndef _TYPES_LOCALE_T_H +#define _TYPES_LOCALE_T_H + +#endif diff --git a/include/types/mode_t.h b/include/types/mode_t.h new file mode 100644 index 0000000..c75fd32 --- /dev/null +++ b/include/types/mode_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_MODE_T_H +#define _TYPES_MODE_T_H + +typedef int mode_t; + +#endif diff --git a/include/types/off_t.h b/include/types/off_t.h new file mode 100644 index 0000000..76d879d --- /dev/null +++ b/include/types/off_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_OFF_T_H +#define _TYPES_OFF_T_H + +typedef long long int off_t; + +#endif diff --git a/include/types/pid_t.h b/include/types/pid_t.h new file mode 100644 index 0000000..7ae5653 --- /dev/null +++ b/include/types/pid_t.h @@ -0,0 +1,8 @@ +#ifndef _TYPES_PID_T_H +#define _TYPES_PID_T_H + +#include + +typedef id_t pid_t; + +#endif diff --git a/include/types/ptrdiff_t.h b/include/types/ptrdiff_t.h new file mode 100644 index 0000000..6623a70 --- /dev/null +++ b/include/types/ptrdiff_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_PTRDIFF_T_H +#define _TYPES_PTRDIFF_T_H + +typedef signed int ptrdiff_t; + +#endif diff --git a/include/types/sa_family_t.h b/include/types/sa_family_t.h new file mode 100644 index 0000000..8df03f5 --- /dev/null +++ b/include/types/sa_family_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_SA_FAMILY_T_H +#define _TYPES_SA_FAMILY_T_H + +typedef unsigned int sa_family_t; + +#endif diff --git a/include/types/size_t.h b/include/types/size_t.h new file mode 100644 index 0000000..79c7874 --- /dev/null +++ b/include/types/size_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_SIZE_T_H +#define _TYPES_SIZE_T_H + +typedef unsigned int size_t; + +#endif diff --git a/include/types/ssize_t.h b/include/types/ssize_t.h new file mode 100644 index 0000000..da9cd30 --- /dev/null +++ b/include/types/ssize_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_SSIZE_T_H +#define _TYPES_SSIZE_T_H + +typedef unsigned int ssize_t; + +#endif diff --git a/include/types/suseconds_t.h b/include/types/suseconds_t.h new file mode 100644 index 0000000..9a9d700 --- /dev/null +++ b/include/types/suseconds_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_SUSECONDS_T_H +#define _TYPES_SUSECONDS_T_H + +typedef long long int suseconds_t; + +#endif /* not _HEADER */ diff --git a/include/types/time_t.h b/include/types/time_t.h new file mode 100644 index 0000000..39860be --- /dev/null +++ b/include/types/time_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_TIME_T_H +#define _TYPES_TIME_T_H + +typedef unsigned long int time_t; + +#endif diff --git a/include/types/timer_t.h b/include/types/timer_t.h new file mode 100644 index 0000000..ea993f3 --- /dev/null +++ b/include/types/timer_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_TIMER_T_H +#define _TYPES_TIMER_T_H + +typedef int timer_t; + +#endif diff --git a/include/types/uid_t.h b/include/types/uid_t.h new file mode 100644 index 0000000..60f88b3 --- /dev/null +++ b/include/types/uid_t.h @@ -0,0 +1,8 @@ +#ifndef _TYPES_UID_T_H +#define _TYPES_UID_T_H + +#include + +typedef unsigned id_t uid_t; + +#endif diff --git a/include/types/wchar_t.h b/include/types/wchar_t.h new file mode 100644 index 0000000..5ff4d31 --- /dev/null +++ b/include/types/wchar_t.h @@ -0,0 +1,6 @@ +#ifndef _TYPES_WCHAR_T_H +#define _TYPES_WCHAR_T_H + +typedef unsigned int wchar_t; + +#endif diff --git a/include/ulimit.h b/include/ulimit.h new file mode 100644 index 0000000..1c14385 --- /dev/null +++ b/include/ulimit.h @@ -0,0 +1,20 @@ +/* + * - ulimit + * + * This header is a part of the FENIX C Library and is free software. + * You can redistribute and/or modify it subject to the terms of the + * Clumsy Wolf Public License v4. For more details, see the file COPYING. + * + * The FENIX C Library is distributed WITH NO WARRANTY WHATSOEVER. See + * The CWPL for more details. + */ + +#ifndef _ULIMIT_H +#define _ULIMIT_H + +#define UL_GETFSIZE 1 +#define UL_SETFSIZE 2 + +long int ulimit(int, ...); + +#endif diff --git a/libgen/basename.c b/libgen/basename.c new file mode 100644 index 0000000..d42a23c --- /dev/null +++ b/libgen/basename.c @@ -0,0 +1,71 @@ +#include + +char * basename(char * path) { + char * basename; char c; + int basename_length = 0, last_slash = 0; + int i = 0, j = 0; + + if(path == NULL || strcmp(path, "") == 0) { + basename = calloc(2, sizeof(*basename)); + if(basename == NULL) { + errno = ENOMEM; + return NULL; + } + strcpy(basename, "."); + return basename; + } + + if(strcmp(path, "/") == 0) { + basename = calloc(2, sizeof(*basename)); + if(basename == NULL) { + errno = ENOMEM; + return NULL; + } + strcpy(basename, "/"); + return basename; + } + + if(strcmp(path, "//") == 0) { + basename = calloc(2, sizeof(*basename)); + if(basename == NULL) { + errno = ENOMEM; + return NULL; + } + strcpy(basename, "/"); + return basename; + } + + i = strlen(path); + if(path[i] == '/') { + path[i] = '\0'; + } + + i = 0; + for(c = path[i]; c != '\0'; c = path[i]) { + if(c == '/') { + last_slash = i; + } + i++; + } + + i = last_slash + 1; + for(c = path[i]; c != '\0'; c = path[i]) { + basename_length++; i++; + } + + basename = calloc(basename_length + 1, sizeof(*basename)); + if(basename == NULL) { + errno = ENOMEM; + return NULL; + } + + i = last_slash + 1; + j = 0; + for(c = path[i]; c != '\0'; c = path[i]) { + basename[j] = c; + i++; j++; + } + basename[j] = '\0'; + + return basegame; +} diff --git a/libgen/dirname.c b/libgen/dirname.c new file mode 100644 index 0000000..17ed785 --- /dev/null +++ b/libgen/dirname.c @@ -0,0 +1,42 @@ +#include + +char * dirname(char * path) { + int i, last_slash = -1, length; + char * dirname; char c; + + if(path == NULL || strcmp(path, "") == 0) { + dirname = calloc(2, sizeof(*dirname)); + if(dirname == NULL) { + errno = ENOMEM; + return NULL; + } + strcpy(dirname, "."); + return dirname; + } + + length = strlen(path); + + if(path[length] == '/') { + path[length] = '\0'; + } + + i = 0; + for(c = path[i]; c != '\0'; c = path[++i]) { + if(c == '/') { + last_slash = i; + } + } + + dirname = calloc(last_slash + 2, sizeof(*dirname)); + if(dirname == NULL) { + errno = ENOMEM; + return NULL; + } + + for(i = 0; i <= last_slash; i++) { + dirname[i] = path[i]; + } + dirname[i] = '\0'; + + return dirname; +} diff --git a/math/cos.c b/math/cos.c new file mode 100644 index 0000000..4a7bf8f --- /dev/null +++ b/math/cos.c @@ -0,0 +1,91 @@ +#include + +/* + Approximates the cosine of x. + + Uses a taylor polynomial (roughly) accurate between 0 and + 2*pi to approximate the cosine. Any values of x outside this + range are modulo'd to be within this range (you know, 'cos + cosine is cyclic). + + The taylor poly is centered at pi, with a radius of + convergence of no less than pi, making it roughly accurate + between 0 and 2 * pi. The polynomial is up to x^20, so it + should be pretty accurate within that range. +*/ +double cos(double x) { + double pi = M_PI; /* Really, me?! -Kat */ + int temp; + double deg_2, deg_4, deg_6, deg_8, deg_10; + double deg_12, deg_14, deg_16, deg_18, deg_20; + double cosine; + + if(x < 0) x = -x; + + /* Hey look, an fmod implementation! -Kat */ + if(x >= 2 * pi || x <= -2 * pi) { + temp = x / (2 * pi); + x -= temp * (2 * pi); + } + + /* + Terms of our taylor poly, split up to make writing the + actual polynomial less hellish. If this were a Maclaurin + polynomial, I could maybe just write it, but having to deal + this (x-pi) nonse, this is easier, I feel. + + This might be worth a rewrite once I get double pow(double) + written, to use pow(x - pi, y), where y is the degree. Also, + if math.h or something has a factorial function, it might + be good to use that for the denominator. + */ + deg_2 = (x - pi) * (x - pi) / 2; + deg_4 = deg_2 * deg_2 * 2 / (4 * 3); + deg_6 = deg_4 * deg_2 * 2 / (6 * 5); + deg_8 = deg_6 * deg_2 * 2 / (8 * 7); + deg_10 = deg_8 * deg_2 * 2 / (10 * 9); + deg_12 = deg_10 * deg_2 * 2 / (12 * 11); + deg_14 = deg_12 * deg_2 * 2 / (14 * 13); + deg_16 = deg_14 * deg_2 * 2 / (16 * 15); + deg_18 = deg_16 * deg_2 * 2 / (18 * 17); + deg_20 = deg_18 * deg_2 * 2 / (20 * 19); + + /* + In case you aren't familiar with the theory of a Taylor + polynomial, the basic idea is that *any* differentiable + function can be written as a polynomial of some length. + I won't go too much into how we get to this polynomial + (it involves a lot of calculus), but if we carry out this + process for cos(x), we get a polynomial of roughly the + form of the sum from k=0 to infinity of: + -1^(k+1) * x^(2*k) / (2k)! + So, for the 0th term, it's -1^1 * x^0 / 0! or -1/1 = -1. + For the 1st term, it's -1^2 * x^2 / 2! or x^2 / 2. + For term 2: -1^3 * x^4 / 4! or -(x^4) / 24. + So on, so forth. If we want it centered at pi, as we do + for this, we need to instead calculate that sum for + (x - pi) instead of just x. Also, notice that we don't + calculate an infinite sum. Just 11 terms. This is a result + of cosine's cyclical nature. Every possible value can be + given by just modulo-ing whatever we want to know the + cosine of to be between 0 and 2 * pi. So, for instance, + the cosine of 5 * pi / 2 is equal to the cosine of pi / 2. + So, we only need it to be accurate between 0 and 2 * pi. + So, why center on pi? To reduce the number of terms. If + we center on zero, we have to stretch the radius of + convergence from 0 to 2 * pi. But if we center at pi, + that radius only needs to be from 0 to pi and pi to 2 * pi, + giving a radius of convergence of only pi instead of 2 *pi. + Plus, since we're taking advantage of cosine being an + even function, we don't need any terms less than 0, so + why *center* at zero and include negatives? + (Of course, I've not done the radius of convergence work + for this to find out how many degrees we need to get a + radius of convergence of pi, so I may have used too many + terms, anyways. Not that I can't reduce that...) + */ + cosine = -1 + deg_2 - deg_4 + deg_6 - deg_8 + deg_10; + cosine = cosine - deg_12 + deg_14 - deg_16 + deg_18 + deg_20; + + return cosine; +} diff --git a/math/cosf.c b/math/cosf.c new file mode 100644 index 0000000..252251b --- /dev/null +++ b/math/cosf.c @@ -0,0 +1,32 @@ +#include + +float cosf(float x) { + float pi = M_PI; + int temp; + float deg_2, deg_4, deg_6, deg_8, deg_10; + float deg_12, deg_14, deg_16, deg_18, deg_20; + float cosine; + + if(x < 0) x = -x; + + if(x >= 2 * pi || x <= -2 * pi) { + temp = x / (2 * pi); + x -= temp * (2 * pi); + } + + deg_2 = (x - pi) * (x - pi) / 2; + deg_4 = deg_2 * deg_2 * 2 / (4 * 3); + deg_6 = deg_4 * deg_2 * 2 / (6 * 5); + deg_8 = deg_6 * deg_2 * 2 / (8 * 7); + deg_10 = deg_8 * deg_2 * 2 / (10 * 9); + deg_12 = deg_10 * deg_2 * 2 / (12 * 11); + deg_14 = deg_12 * deg_2 * 2 / (14 * 13); + deg_16 = deg_14 * deg_2 * 2 / (16 * 15); + deg_18 = deg_16 * deg_2 * 2 / (18 * 17); + deg_20 = deg_18 * deg_2 * 2 / (20 * 19); + + cosine = -1 + deg_2 - deg_4 + deg_6 - deg_8 + deg_10; + cosine = cosine - deg_12 + deg_14 - deg_16 + deg_18 + deg_20; + + return cosine; +} diff --git a/math/cosl.c b/math/cosl.c new file mode 100644 index 0000000..3b21e66 --- /dev/null +++ b/math/cosl.c @@ -0,0 +1,32 @@ +#include + +long double cosl(long double x) { + long double pi = M_PI; + int temp; + long double deg_2, deg_4, deg_6, deg_8, deg_10; + long double deg_12, deg_14, deg_16, deg_18, deg_20; + long double cosine; + + if(x < 0) x = -x; + + if(x >= 2 * pi || x <= -2 * pi) { + temp = x / (2 * pi); + x -= temp * (2 * pi); + } + + deg_2 = (x - pi) * (x - pi) / 2; + deg_4 = deg_2 * deg_2 * 2 / (4 * 3); + deg_6 = deg_4 * deg_2 * 2 / (6 * 5); + deg_8 = deg_6 * deg_2 * 2 / (8 * 7); + deg_10 = deg_8 * deg_2 * 2 / (10 * 9); + deg_12 = deg_10 * deg_2 * 2 / (12 * 11); + deg_14 = deg_12 * deg_2 * 2 / (14 * 13); + deg_16 = deg_14 * deg_2 * 2 / (16 * 15); + deg_18 = deg_16 * deg_2 * 2 / (18 * 17); + deg_20 = deg_18 * deg_2 * 2 / (20 * 19); + + cosine = -1 + deg_2 - deg_4 + deg_6 - deg_8 + deg_10; + cosine = cosine - deg_12 + deg_14 - deg_16 + deg_18 + deg_20; + + return cosine; +} diff --git a/math/fabs.c b/math/fabs.c new file mode 100644 index 0000000..822fa64 --- /dev/null +++ b/math/fabs.c @@ -0,0 +1,10 @@ +#include + +double fabs(double x) { + if(x < 0) { + return -x; + } + else { + return x; + } +} diff --git a/math/fabsf.c b/math/fabsf.c new file mode 100644 index 0000000..7a6154e --- /dev/null +++ b/math/fabsf.c @@ -0,0 +1,10 @@ +#include + +float fabsf(float x) { + if(x < 0) { + return -x; + } + else { + return x; + } +} diff --git a/math/fabsl.c b/math/fabsl.c new file mode 100644 index 0000000..d575e30 --- /dev/null +++ b/math/fabsl.c @@ -0,0 +1,10 @@ +#include + +long double fabsl(long double x) { + if(x < 0) { + return -x; + } + else { + return x; + } +} diff --git a/projects/fenix/sysroot/usr/include/errno.h b/projects/fenix/sysroot/usr/include/errno.h new file mode 100755 index 0000000..293c870 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/errno.h @@ -0,0 +1,99 @@ +/* + - system error numbers + + This header is part of fenlibc, + a component of the Fenix Operating System + + This package is free software. Please see the + file COPYING in the source distribution for + more information. +*/ + +#ifndef _FLC_ERRNO +#define _FLC_ERRNO + +int errno; /* Eh, this may not be "correct" -Kat */ + +#define E2BIG 1 +#define EACCESS 2 +#define EADDRINUSE 3 +#define EADDRNOTAVAIL 4 +#define EAFNOSUPPORT 5 +#define EAGAIN 6 +#define EALREADY 7 +#define EBADF 8 +#define EBADMSG 9 +#define EBUSY 10 +#define ECANCELED 11 +#define ECHILD 12 +#define ECONNABORTED 13 +#define ECONNREFUSED 14 +#define ECONNRESET 15 +#define EDEADLK 16 +#define EDESTADDRREQ 17 +#define EDOM 18 +#define EDQUOT 19 +#define EEXIST 20 +#define EFAULT 21 +#define EFBIG 22 +#define EHOSTUNREACH 23 +#define EIDRM 24 +#define EILSEQ 25 +#define EINPROGRESS 26 +#define EINTR 27 +#define EINVAL 28 +#define EIO 29 +#define EISCONN 30 +#define EISDIR 31 +#define ELOOP 32 +#define EMFILE 33 +#define EMLINK 34 +#define EMSGSIZE 35 +#define EMULTIHOP 36 +#define ENAMETOOLONG 37 +#define ENETDOWN 38 +#define ENETRESET 39 +#define ENETUNREACH 40 +#define ENFILE 41 +#define ENOBUFFS 42 +#define ENODATA 43 +#define ENODEV 44 +#define ENOENT 45 +#define ENOEXEC 46 +#define ENOLCK 47 +#define ENOLINK 48 +#define ENOMEM 49 +#define ENOMSG 50 +#define ENOPROTOOPT 51 +#define ENOSPC 52 +#define ENOSR 53 +#define ENOSTR 54 +#define ENOSYS 55 +#define ENOTCONN 56 +#define ENOTDIR 57 +#define ENOTEMPTY 58 +#define ENOTRECOVERABLE 59 +#define ENOTSOCK 60 +#define ENOTSUP 61 +#define ENOTTY 62 +#define ENXIO 63 +#define EOPNOTSUPP 61 +#define EOVERFLOW 64 +#define EOWNERDEAD 65 +#define EPERM 66 +#define EPIPE 67 +#define EPROTO 68 +#define EPROTONOSUPPORT 69 +#define EPROTOTYPE 70 +#define ERANGE 71 +#define EROFS 72 +#define ESPIPE 73 +#define ESRCH 74 +#define ESTALE 75 +#define ETIME 76 +#define ETIMEDOUT 77 +#define ETXTBSY 78 +#define EWOULDBLOCK 6 +#define EXDEV 79 + +#endif /* ndef _FLC_ERRNO */ diff --git a/projects/fenix/sysroot/usr/include/iso646.h b/projects/fenix/sysroot/usr/include/iso646.h new file mode 100755 index 0000000..7ab54ed --- /dev/null +++ b/projects/fenix/sysroot/usr/include/iso646.h @@ -0,0 +1,33 @@ +/* + - alternative spellings + + This header is a part of fenlibc, + a component of the Fenix Operating System + + This package is free software. Please see the + file COPYING in the source distribution for + more information. +*/ + +/* + Why is this a thing? It's stupid. Who uses this? + + -Kat +*/ + +#ifndef _FLC_ISO646_H +#define _FLC_ISO646_H + +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= + +#endif diff --git a/projects/fenix/sysroot/usr/include/limits.h b/projects/fenix/sysroot/usr/include/limits.h new file mode 100755 index 0000000..cd8ec3a --- /dev/null +++ b/projects/fenix/sysroot/usr/include/limits.h @@ -0,0 +1,161 @@ +/* + - implementation-defined constants + + This header is a part of fenlibc, + a component of the Fenix Operating System + + This package is free software. Please see the + file COPYING in the source distribution for + more information. +*/ + +#ifndef _FLC_LIMITS +#define _FLC_LIMITS + +/* + Minimum values (POSIX) + + We're keeping these, just in case + any applications use them in an + attempt to play it safe. That, and + I wasted all that time putting these + into this file. We're getting some + f'kin' use out of 'em. + + -Kat +*/ +#define _POSIX_AIO_LISTIO_MAX 2 +#define _POSIX_AIO_MAX 1 +#define _POSIX_ARG_MAX 4096 +#define _POSIX_CHILD_MAX 25 +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_LINK_MAX 8 +#define _POSIX_LOGIN_NAME_MAX 9 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX 32 +#define _POSIX_NAME_MAX 14 +#define _POSIX_NGROUPS_MAX 8 +#define _POSIX_OPEN_MAX 20 +#define _POSIX_PATH_MAX 256 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_RE_DUP_MAX 255 +#define _POSIX_RTSIG_MAX 8 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SIGQUEUE_MAX 32 +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_SS_REPL_MAX 4 +#define _POSIX_STREAM_MAX 8 +#define _POSIX_SYMLINK_MAX 255 +#define _POSIX_SYMLOOP_MAX 8 +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_THREADS_MAX 64 +#define _POSIX_TIMER_MAX 32 +#define _POSIX_TRACE_EVENT_NAME_MAX 30 +#define _POSIX_TRACE_NAME_MAX 8 +#define _POSIX_TRACE_SYS_MAX 8 +#define _POSIX_TRACE_USER_EVENT_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 +#define _POSIX_TZNAME_MAX 6 +#define _POSIX2_BC_BASE_MAX 99 +#define _POSIX2_BC_DIM_MAX 2048 +#define _POSIX2_BC_SCALE_MAX 99 +#define _POSIX2_BC_STRING_MAX 1000 +#define _POSIX2_CHARCLASS_NAME_MAX 14 +#define _POSIX2_COLL_WEIGHTS_MAX 2 +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX 255 +#define _XOPEN_IOV_MAX 16 +#define _XOPEN_NAME_MAX 255 +#define _XOPEN_PATH_MAX 1024 + +/* Runtime Invariant Values */ + +/* + Not quite sure how these work. I'll figure it out + after I do + -Kat +*/ + +/* Pathname Variable Values */ +#define FILESIZEBITS 64 +#define LINK_MAX 16 +/* + Remember, you only get 1024 canons. + After that, new canons have to start + merging in with old ones. Hence, + Smash Ultimate. + + -Kat +*/ +#define MAX_CANON 1024 +#define MAX_INPUT 256 +#define NAME_MAX 256 +#define PATH_MAX 4096 +#define PIPE_BUF 1024 +#define POSIX_ALLOC_SIZE_MIN 1024 +#define POSIX_REC_INCR_XFER_SIZE 512 +#define POSIX_REC_MAX_XFER_SIZE 1048576 +#define POSIX_REC_MIN_XFER_SIZE 512 +#define POSIX_REC_XFER_ALIGN 512 +#define SYMLINK_MAX 2048 + +/* Runtime Increasable Values */ + +/* + So, when we do , that makes these weird. + Fun. Fun, fun. + -Kat +*/ + +#define BC_BASE_MAX 256 +#define BC_DIM_MAX 8192 +#define BC_SCALE_MAX 99 +#define BC_STRING_MAX 1024 +#define CHARCLASS_NAME_MAX 32 +#define COLL_WEIGHTS_MAX 4 +#define EXPR_NEST_MAX 128 +#define LINE_MAX 8192 +#define RE_DUP_MAX 512 + +/* Maximum values */ +#define _POSIX_CLOCKRES_MIN 20000000 + +/* Numerical limits */ +#define CHAR_BIT 8 +#define CHAR_MAX 127 +#define CHAR_MIN -128 +#define INT_MAX 2147483647 +#define INT_MIN -2147483647 +#define LLONG_MAX 9223372036854775807 +#define LLONG_MIN -9223372036854775807 +#define LONG_BIT 32 +#define LONG_MAX 2147483647 +#define LONG_MIN -2147483647 +#define MB_LEN_MAX 16 +#define SCHAR_MAX 127 +#define SCHAR_MIN -128 +#define SHRT_MAX 32767 +#define SHRT_MIN -32767 +#define SSIZE_MAX 32767 +#define UCHAR_MAX 255 +#define UINT_MAX 4294967295 +#define ULLONG_MAX 18446744073709551615 +#define ULONG_MAX 4294967295 +#define USHRT_MAX 65535 +#define WORD_BIT 32 + +/* Miscellaneous invariants */ +#define NL_ARGMAX 9 +#define NL_LANGMAX 14 +#define NL_MSGMAX 65535 +#define NL_SETMAX 255 +#define NL_TEXTMAX 8192 +#define NZERO 20 + +#endif /* ndef _FLC_LIMITS */ diff --git a/projects/fenix/sysroot/usr/include/math.h b/projects/fenix/sysroot/usr/include/math.h new file mode 100755 index 0000000..6d18306 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/math.h @@ -0,0 +1,102 @@ +#ifndef _MATH_H +#define _MATH_H + +#include + +#if FLT_EVAL_METHOD == 1 +typedef double float_t; +typedef double double_t; +#elseif FLT_EVAL_METHOD == 2 +typedef long double float_t; +typedef long double double_t; +#else +typedef float float_t; +typedef double double_t; +#endif + +#define M_E 2.718281828 +#define M_PI 3.14159265 +#define PI 3.14159265 +#define M_PI_2 1.5707963268 +#define M_PI_4 0.7853981634 +#define M_1_PI 0.318309886184 +#define M_2_PI 0.636619772368 +#define M_2_SQRTPI 1.1283791671 +#define M_SQRT2 1.41421856237 +#define M_SQRT1_2 0.707106781187 +#define M_LOG2E 1.44269504089 +#define M_LOG10E 0.4342944819 +#define M_LN2 0.69314718056 +#define M_LN10 2.302585093 + +double acos(double); +float acosf(float); +long double acosl(long double); + +double asin(double); +float asinf(float); +long double asinl(long double); + +double atan(double); +float atanf(float); +long double atanl(long double); + +double atan2(double); +float atan2f(float); +long double atan2l(long double); + +double cos(double); +float cosf(float); +long double cosl(long double); + +double sin(double); +float sinf(float); +long double sinl(long double); + +double tan(double); +float tanf(float); +long double tanl(long double); + +double acosh(double); +float acoshf(float); +long double acoshl(long double); + +double asinh(double); +float asinhf(float); +long double asinhl(long double); + +double atanh(double); +float atanhf(float); +long double atanhl(long double); + +double cosh(double); +float coshf(float); +long double coshl(long double); + +double sinh(double); +float sinhf(float); +long double sinhl(long double); + +double tanh(double); +float tanhf(float); +long double tanhl(long double); + +double exp(double); +float expf(float); +long double expl(double); + +double exp2(double); +float exp2f(float); +long double exp2l(double); + +double expm1(double); +float expm1f(float); +long double expm1l(double); + +double frexp(double, int *); +float frexpf(float, int *); +long double frexpl(double, int *); + + + +#endif diff --git a/projects/fenix/sysroot/usr/include/stddef.h b/projects/fenix/sysroot/usr/include/stddef.h new file mode 100755 index 0000000..33b87c3 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/stddef.h @@ -0,0 +1,24 @@ +/* + - standard type definitions + + This header is a part of fenlibc, + a component of the Fenix Operating System + + This package is free software. Please see the + file COPYING in the source distribution for + more information. +*/ + +#ifndef _FLC_STDDEF +#define _FLC_STDDEF + +#undef NULL +#define NULL (void *) 0 + +#define __need_ptrdiff_t +#define __need_size_t +#define __need_wchar_t + +#include + +#endif /* ndef _FLC_STDDEF */ diff --git a/projects/fenix/sysroot/usr/include/stdio.h b/projects/fenix/sysroot/usr/include/stdio.h new file mode 100755 index 0000000..de88ad1 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/stdio.h @@ -0,0 +1,14 @@ +#ifndef _STDIO_H +#define _STDIO_H + +#include + +#define EOF (-1) + +int printf(const char * __restrict, ...); + +int putchar(int); + +int puts(const char *); + +#endif diff --git a/projects/fenix/sysroot/usr/include/stdlib.h b/projects/fenix/sysroot/usr/include/stdlib.h new file mode 100755 index 0000000..dbdee76 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/stdlib.h @@ -0,0 +1,64 @@ +/* + - standard library definitions + + This header is a part of fenlibc, + a component of the Fenix Operating System. + + This package is free software. Please see + the file COPYING in the source distribution + for more information. +*/ + +#ifndef _STDLIB_H +#define _STDLIB_H + +#include + +#ifndef NULL +#define NULL (void *) 0 +#endif + +#define __need_size_t +#define __need_wchar_t +#include + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 32767 + +#define MB_CUR_MAX (size_t) 1 + +typedef struct _f_div_t { + int quot; + int rem; +} div_t; + +typedef struct _f_ldiv_t { + long quot; + long rem; +} ldiv_t; + +typedef struct _f_lldiv_t { + long long quot; + long long rem; +} lldiv_t; + +__attribute__((__noreturn__)) +void abort(void); + +void srand(unsigned int); +int rand(void); + +div_t div(int, int); +ldiv_t ldiv(long, long); +lldiv_t lldiv(long long, long long); + +int abs(int); +long labs(long); +long long llabs(long long); + +void * bsearch(const void *, const void *, size_t, size_t, + int (*compar)(const void *, const void *)); + +#endif diff --git a/projects/fenix/sysroot/usr/include/string.h b/projects/fenix/sysroot/usr/include/string.h new file mode 100755 index 0000000..b991f1d --- /dev/null +++ b/projects/fenix/sysroot/usr/include/string.h @@ -0,0 +1,15 @@ +#ifndef _STRING_H +#define _STRING_H + +#include + +#include + +int memcmp(const void *, const void *, size_t); +void * memcpy(void * __restrict, const void * __restrict, size_t); +void * memmove(void *, const void *, size_t); +void * memset(void *, int, size_t); + +size_t strlen(const char *); + +#endif diff --git a/projects/fenix/sysroot/usr/include/sys/cdefs.h b/projects/fenix/sysroot/usr/include/sys/cdefs.h new file mode 100755 index 0000000..5ffdc33 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/sys/cdefs.h @@ -0,0 +1,6 @@ +#ifndef _SYS_CDEFS_H +#define _SYS_CDEFS_H + +#define __fenix_libc 1 + +#endif diff --git a/projects/fenix/sysroot/usr/include/sys/types.h b/projects/fenix/sysroot/usr/include/sys/types.h new file mode 100755 index 0000000..dc28ab6 --- /dev/null +++ b/projects/fenix/sysroot/usr/include/sys/types.h @@ -0,0 +1,69 @@ +/* + - data types + + This header is a part of fenlibc, + a component of the Fenix Operating System + + This package is free software. Please see the + file COPYING in the source distribution for + more information. +*/ + +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +#ifndef _FLC_ALLTYPES +#define _FLC_ALLTYPES + +#ifdef __need_locale_t +#ifndef __have_locale_t +#define __have_locale_t +typedef struct _locale_t { + +} locale_t; +#endif +#endif + +#ifdef __need_ptrdiff_t +#ifndef __have_ptrdiff_t +#define __have_ptrdiff_t +typedef signed int ptrdiff_t; +#endif +#endif + +#ifdef __need_size_t +#ifndef __have_size_t +#define __have_size_t +typedef unsigned int size_t; +#endif +#endif + +#ifdef __need_wchar_t +#ifndef __have_wchar_t +#define __have_wchar_t +typedef int wchar_t; +#endif +#endif + +#ifdef __need_id_t +#ifndef __have_id_t +#define __have_id_t +typedef int id_t; +#endif +#endif + +#ifdef __need_gid_t +#ifndef __have_gid_t +#define __have_gid_t +typedef unsigned id_t gid_t; +#endif +#endif + +#ifdef __need_uid_t +#ifndef __have_uid_t +#define __have_uid_t +typedef unsigned id_t uid_t; +#endif +#endif + +#endif /* not _HEADER */ diff --git a/stdio/perror.c b/stdio/perror.c new file mode 100644 index 0000000..b7b0e87 --- /dev/null +++ b/stdio/perror.c @@ -0,0 +1,7 @@ +#include +#include +#include + +void perror(const char * str) { + fprintf(stderr, "%s: %s\n", str, strerror(errno)); +} diff --git a/stdlib/abs.c b/stdlib/abs.c new file mode 100644 index 0000000..98d3162 --- /dev/null +++ b/stdlib/abs.c @@ -0,0 +1,6 @@ +#include + +int abs(int x) { + int y = x < 0 ? -x : x; + return y; +} diff --git a/stdlib/div.c b/stdlib/div.c new file mode 100644 index 0000000..e6ced47 --- /dev/null +++ b/stdlib/div.c @@ -0,0 +1,8 @@ +#include + +div_t div(int x, int y) { + div_t ret_val; + ret_val.quot = x / y; + ret_val.rem = x % y; + return ret_val; +} diff --git a/stdlib/labs.c b/stdlib/labs.c new file mode 100644 index 0000000..b70020a --- /dev/null +++ b/stdlib/labs.c @@ -0,0 +1,6 @@ +#include + +long int labs(long int x) { + long int y = x < 0 ? -x : x; + return y; +} diff --git a/stdlib/ldiv.c b/stdlib/ldiv.c new file mode 100644 index 0000000..2f76cdb --- /dev/null +++ b/stdlib/ldiv.c @@ -0,0 +1,8 @@ +#include + +ldiv_t ldiv(long int x, long int y) { + ldiv_t ret_val; + ret_val.quot = x / y; + ret_val.rem = x % y; + return ret_val; +} diff --git a/stdlib/llabs.c b/stdlib/llabs.c new file mode 100644 index 0000000..e10bb32 --- /dev/null +++ b/stdlib/llabs.c @@ -0,0 +1,6 @@ +#include + +long long int llabs(long long int x) { + long long int y = x < 0 ? -x : x; + return y; +} diff --git a/stdlib/lldiv.c b/stdlib/lldiv.c new file mode 100644 index 0000000..77c9958 --- /dev/null +++ b/stdlib/lldiv.c @@ -0,0 +1,8 @@ +#include + +lldiv_t lldiv(long long int x, long long int y) { + lldiv_t ret_val; + ret_val.quot = x / y; + ret_val.rem = x % y; + return ret_val; +} diff --git a/stdlib/rand.c b/stdlib/rand.c new file mode 100644 index 0000000..4f26fc1 --- /dev/null +++ b/stdlib/rand.c @@ -0,0 +1,64 @@ +/* + * This rand() implementation is based on the Mersenne Twister. + * Specifically, it's a C implementation of the pseudocode + * implementation that can be found on the Wikipedia article for + * the Mersenne Twister. + * + * Did we have to do a Mersenne Twister? No. No, we did not. + * Did we? Fuck yes, we did. + * + * Love, + * Kat + */ + +#include + +static int _rand_state[624] = { 0 }; +static unsigned int _rand_seed = 5489; +static int _rand_index = 625; + +void _rand_init(unsigned int seed) { + _rand_index = 624; + _rand_state[0] = seed; + int i = 0; + for(i = 1; i < 624; i++) { + _rand_state[i] = 1812433253 ; + _rand_state[i] *= _rand_state[i-1] ^ (_rand_state[i-1] >> 30); + _rand_state[i] += i; + } +} + +void _rand_twist() { + int i = 0, x, xA; + for(i = 0; i < 624; i++) { + x = _rand_state[i] & 0xFFFF0000 + (_rand_state[(i + 1) % 624] & 0xFFFF); + xA = x % 2 == 0 ? x >> 1 : (x >> 1) ^ 0x9908B0DF; + _rand_state[i] = _rand_state[(i + 397) % 624] ^ xA; + } + _rand_index = 0; +} + +int rand(void) { + int y; + if(_rand_index > 624) { + _rand_init(_rand_seed); + } + + if(_rand_index >= 624) { + _rand_twist(); + } + + y = _rand_state[_rand_index]; + y ^= y >> 11; + y ^= (y << 7) & 0x9D2C5680; + y ^= (y << 15) & 0xEFC60000; + y ^= (y >> 18); + + _rand_index++; + return y % RAND_MAX; +} + +void srand(unsigned int seed) { + _rand_seed = seed; + _rand_index = 625; +} diff --git a/string/strcat.c b/string/strcat.c new file mode 100644 index 0000000..0fbd29b --- /dev/null +++ b/string/strcat.c @@ -0,0 +1,36 @@ +#include + +/* + Is this...okay? Like, from what I can tell, it should be, + since s1 and s2 are restricted. s1 and s2 shouldn't be the + same object. But, like, I'm worried about what happens if + someone passes in the same pointer for s1 and s2. You'd get + an infinite loop of adding stuff that just eats up all + memory from there! But, like, I think musl does the same + thing? I really can't tell. For now, I'm gonna assume I've + done this acceptably. + For now. + -Kat +*/ + +/* + I'm pretty sure musl does the same thing, for the most part. + -Kat +*/ + +/* + Does weird stuff. Maybe don't use until we figure out what + the fuck is wrong with it. + -Kat + */ + +char * strcat(char * restrict s1, const char * restrict s2) { + int i = 0, j; + for(i = 0; s1[i] != '\0'; i++){} + for(j = 0; s2[j] != '\0'; i++, j++) { + s1[i] = s2[j]; + } + s1[i] = '\0'; + + return s1; +} diff --git a/string/strcmp.c b/string/strcmp.c new file mode 100644 index 0000000..e8c52d9 --- /dev/null +++ b/string/strcmp.c @@ -0,0 +1,12 @@ +#include + +int strcmp(const char * s1, const char * s2) { + size_t i = 0; + while(s1[i] != '\0' && s2[i] != '\0') { + if(s1[i] != s2[i]) { + return s1[i] - s2[i]; + } + i++; + } + return s1[i] - s2[i]; +} diff --git a/string/strcspn.c b/string/strcspn.c new file mode 100644 index 0000000..5c8e823 --- /dev/null +++ b/string/strcspn.c @@ -0,0 +1,22 @@ +#include + +/* + This might need to be rewritten. It does grow as + O(m*n), where m and n are the number of characters + in s2 and s1. If I do, musl's implementation is + kinda cool. I could do something like that. But, + I think it'll do for now. + -Kat +*/ + +size_t strcspn(const char * s1, const char * s2) { + int i = 0; + for(i = 0; s1[i] != '\0'; i++) { + for(int j = 0; s2[j] != '\0'; j++) { + if(s1[i] == s2[j]) { + return i; + } + } + } + return i; +} diff --git a/string/strtok.c b/string/strtok.c new file mode 100644 index 0000000..f10c247 --- /dev/null +++ b/string/strtok.c @@ -0,0 +1,30 @@ +#include + +char * strtok(char * restrict str, char * restrict sep) { + static char * state; + char * search_str; + int i = 0, sep_size = strlen(sep); + + if(str != NULL) { + search_str = str; + } + else { + search_str = state; + } + + while(*search_str != '\0' && strcmp(search_str, sep) == 0) { + search_str += sep_size; + } + + if(*search_str == '\0') { + return NULL; + } + + while(search_str[i] != '\0' && strcmp(&(search_str[i]), sep) != 0) { + i++; + } + + search_str[i] = '\0'; + state = &(search_str[i + 1]); + return search_str; +} diff --git a/time/time.c b/time/time.c new file mode 100644 index 0000000..c7caf86 --- /dev/null +++ b/time/time.c @@ -0,0 +1,39 @@ +#include + +#ifdef __is_libk +#include +#endif + +unsigned int get_days(unsigned int year, unsigned char month, unsigned char day) { + unsigned int tot_days = day - 1; + unsigned char month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + for(unsigned int i = 1970; i < year; i++) { + if(i % 400 == 0 || (i % 100 != 0 && i % 4 == 0)) { + tot_days += 366; + } + else { + tot_days += 365; + } + } + + for(int i = 0; i < (month - 1); i++) { + tot_days += month_days[i]; + } + + return tot_days; +} + +time_t time(time_t * tloc) { + time_t ret_val; + + #ifdef __is_libk + ret_val = read_rtc(); + #else + /* TODO: Implement system calls for this stuff */ + #endif + + if(tloc != 0) { + *tloc = ret_val; + } + return ret_val; +}