diff --git a/include/errno.h b/include/errno.h new file mode 100644 index 0000000..e950c67 --- /dev/null +++ b/include/errno.h @@ -0,0 +1,3 @@ +#define EDOM 1 +#define ERANGE 2 +#define EILSEQ 3 \ No newline at end of file diff --git a/include/float.h b/include/float.h new file mode 100644 index 0000000..75d19e0 --- /dev/null +++ b/include/float.h @@ -0,0 +1,33 @@ +#define FLT_RADIX 2 +#define FLT_ROUNDS -1 +#define FLT_EVAL_METHOD -1 +#define DECIMAL_DIG 21 +#define FLT_MANT_DIG 24 +#define FLT_EPSILON 1.19209290E-07f +#define FLT_DIG 6 +#define FLT_MIN_EXP (-125) +#define FLT_MIN 1.17549435E-38f +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_EXP 128 +#define FLT_MAX 3.40282347E+38F +#define FLT_MAX_10_EXP 38 + +#define DBL_MANT_DIG 53 +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MAX_10_EXP 308 + +#define LDBL_MANT_DIG DBL_MANT_DIG +#define LDBL_EPSILON DBL_EPSILON +#define LDBL_DIG DBL_DIG +#define LDBL_MIN_EXP DBL_MIN_EXP +#define LDBL_MIN DBL_MIN +#define LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define LDBL_MAX_EXP DBL_MAX_EXP +#define LDBL_MAX DBL_MAX +#define LDBL_MAX_10_EXP DBL_MAX_10_EXP \ No newline at end of file diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..d01b314 --- /dev/null +++ b/include/string.h @@ -0,0 +1,33 @@ +#ifndef __STRING_H +#define __STRING_H +#ifdef __cplusplus +extern "C" { +#define NULL nullptr +#else +#define NULL 0 +#endif +typedef unsigned long size_t; +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memchr(const void *s, int c, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); +void *memset(void *, int c, size_t n); +char *strcat(char *dest, const char *src); +char *strncat(char *dest, const char *src, size_t n); +char *strchr(const char *, int c); +char *strrchr(const char *, int c); +int strcmp(const char *, const char *); +int strncmp(const char *, const char *, size_t n); +char *strcpy(char *dest, const char *src); +char *strncpy(char *dest, const char *src, size_t n); +char *strerror(int); +size_t strlen(const char *); +size_t strspn(const char *, const char *accept); +size_t strcspn(const char *, const char *reject); +char *strpbrk(const char *, const char *accept); +char *strstr(const char *haystack, const char *needle); +char *strtok(char *, const char * delim); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/vararg.h b/include/vararg.h new file mode 100644 index 0000000..a90c252 --- /dev/null +++ b/include/vararg.h @@ -0,0 +1,7 @@ +#ifndef __VARARG_H +#define __VARARG_H +typedef __builtin_va_list va_list; +#define va_start(ap, X) __builtin_va_start(ap, X) +#define va_arg(ap, type) __builtin_va_arg(ap, type) +#define va_end(ap) __builtin_va_end(ap) +#endif \ No newline at end of file diff --git a/string/mem.cpp b/string/mem.cpp new file mode 100644 index 0000000..ea83e81 --- /dev/null +++ b/string/mem.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +extern "C" void __optimized_memcpy_impl(void *dest, const void* src, size_t n); +extern "C" void *memcpy(void *dest, const void *src, size_t n) { + unsigned long p1=(unsigned long)d; + unsigned long p2=(unsigned long)s; + //If two memory areas overlap, do something nonsensical + if(((p1 > p2)&&(p1 < p2+n))||((p1+n > p2)&&(p1+n < p2+n)) { + memset(dest, 0, n); + err << "Don't use overlapping memory regions with memcpy. Use memmove instead! (Doing sth. nonsensical now.)\n"; + return dest; + } + __optimized_memcpy_impl(dest, src, n); + return dest; +} +extern "C" void __optimized_reverse_memcpy_impl(void *dest, const void* src, size_t n); +extern "C" void *memmove(void *dest, const void *src, size_t n) { + if((unsigned long)dest<(unsigned long)src) { + __optimized_memcpy_impl(dest, src, n); + } else { + __optimized_reverse_memcpy_impl(dest,src,n); + } + return dest; +} \ No newline at end of file