- Added files for developing programs with kolibri-libc

git-svn-id: svn://kolibrios.org@8685 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2021-04-26 21:12:04 +00:00
parent c1911092d3
commit 4e4a78fb2d
20 changed files with 2356 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,54 @@
#ifndef __NETWORK_H__
#define __NETWORK_H__
#include <sys/socket.h>
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_OVERFLOW 14
// Flags for addrinfo
#define AI_PASSIVE 1
#define AI_CANONNAME 2
#define AI_NUMERICHOST 4
#define AI_NUMERICSERV 8
#define AI_ADDRCONFIG 0x400
#pragma pack(push, 1)
struct ARP_entry{
unsigned int IP;
unsigned char MAC[6];
unsigned short status;
unsigned short TTL;
};
#pragma pack(pop)
#pragma pack(push, 1)
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
int ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#pragma pack(pop)
extern int networklib_init ();
extern int (*inet_addr __attribute__ ((stdcall)))(const char* hostname);
extern char* (*inet_ntoa __attribute__ ((stdcall)))(int ip_addr);
extern int (*getaddrinfo __attribute__ ((stdcall)))(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res);
extern void (*freeaddrinfo __attribute__ ((stdcall)))(struct addrinfo* ai);
#endif

View File

@ -0,0 +1,45 @@
#ifndef _CTYPE_H_
#define _CTYPE_H_
/*
** All character classification functions except isascii().
** Integer argument (c) must be in ASCII range (0-127) for
** dependable answers.
*/
#define __ALNUM 1
#define __ALPHA 2
#define __CNTRL 4
#define __DIGIT 8
#define __GRAPH 16
#define __LOWER 32
#define __PRINT 64
#define __PUNCT 128
#define __BLANK 256
#define __UPPER 512
#define __XDIGIT 1024
#ifdef _KOLIBRI_LIBC_OBJ
extern unsigned short __is[129];
#else
extern unsigned short *__is;
#endif
#define isalnum(c)(__is[c+1] & __ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */
#define isalpha(c)(__is[c+1] & __ALPHA ) /* 'a'-'z', 'A'-'Z' */
#define iscntrl(c)(__is[c+1] & __CNTRL ) /* 0-31, 127 */
#define isdigit(c)(__is[c+1] & __DIGIT ) /* '0'-'9' */
#define isgraph(c)(__is[c+1] & __GRAPH ) /* '!'-'~' */
#define islower(c)(__is[c+1] & __LOWER ) /* 'a'-'z' */
#define isprint(c)(__is[c+1] & __PRINT ) /* ' '-'~' */
#define ispunct(c)(__is[c+1] & __PUNCT ) /* !alnum && !cntrl && !space */
#define isspace(c)(__is[c+1] & __BLANK ) /* HT, LF, VT, FF, CR, ' ' */
#define isupper(c)(__is[c+1] & __UPPER ) /* 'A'-'Z' */
#define isxdigit(c)(__is[c+1] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */
#define isascii(c) (!((c)&(~0x7f)))
#define toascii(c) ((c)&0x7f)
extern unsigned char tolower(unsigned char c);
extern unsigned char toupper(unsigned char c);
#endif

View File

@ -0,0 +1,144 @@
#ifndef _ERRNO_H_
#define _ERRNO_H_
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int errno;
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* Input/output error */
#define ENXIO 6 /* Device not configured */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file descriptor */
#define ECHILD 10 /* No child processes */
#define EDEADLK 11 /* Resource deadlock avoided */
/* 11 was EAGAIN */
#define ENOMEM 12 /* Cannot allocate memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device / Resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* Operation not supported by device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* Too many open files in system */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Inappropriate ioctl for device */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
/* math software */
#define EDOM 33 /* Numerical argument out of domain */
#define ERANGE 34 /* Result too large */
/* non-blocking and interrupt i/o */
#define EAGAIN 35 /* Resource temporarily unavailable */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define EINPROGRESS 36 /* Operation now in progress */
#define EALREADY 37 /* Operation already in progress */
/* ipc/network software -- argument errors */
#define ENOTSOCK 38 /* Socket operation on non-socket */
#define EDESTADDRREQ 39 /* Destination address required */
#define EMSGSIZE 40 /* Message too long */
#define EPROTOTYPE 41 /* Protocol wrong type for socket */
#define ENOPROTOOPT 42 /* Protocol not available */
#define EPROTONOSUPPORT 43 /* Protocol not supported */
#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
#define ENOTSUP 45 /* Operation not supported */
#define EOPNOTSUPP ENOTSUP /* Operation not supported on socket */
#define EPFNOSUPPORT 46 /* Protocol family not supported */
#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
#define EADDRINUSE 48 /* Address already in use */
#define EADDRNOTAVAIL 49 /* Can't assign requested address */
/* ipc/network software -- operational errors */
#define ENETDOWN 50 /* Network is down */
#define ENETUNREACH 51 /* Network is unreachable */
#define ENETRESET 52 /* Network dropped connection on reset */
#define ECONNABORTED 53 /* Software caused connection abort */
#define ECONNRESET 54 /* Connection reset by peer */
#define ENOBUFS 55 /* No buffer space available */
#define EISCONN 56 /* Socket is already connected */
#define ENOTCONN 57 /* Socket is not connected */
#define ESHUTDOWN 58 /* Can't send after socket shutdown */
#define ETOOMANYREFS 59 /* Too many references: can't splice */
#define ETIMEDOUT 60 /* Operation timed out */
#define ECONNREFUSED 61 /* Connection refused */
#define ELOOP 62 /* Too many levels of symbolic links */
#define ENAMETOOLONG 63 /* File name too long */
/* should be rearranged */
#define EHOSTDOWN 64 /* Host is down */
#define EHOSTUNREACH 65 /* No route to host */
#define ENOTEMPTY 66 /* Directory not empty */
/* quotas & mush */
#define EPROCLIM 67 /* Too many processes */
#define EUSERS 68 /* Too many users */
#define EDQUOT 69 /* Disc quota exceeded */
/* Network File System */
#define ESTALE 70 /* Stale NFS file handle */
#define EREMOTE 71 /* Too many levels of remote in path */
#define EBADRPC 72 /* RPC struct is bad */
#define ERPCMISMATCH 73 /* RPC version wrong */
#define EPROGUNAVAIL 74 /* RPC prog. not avail */
#define EPROGMISMATCH 75 /* Program version wrong */
#define EPROCUNAVAIL 76 /* Bad procedure for program */
#define ENOLCK 77 /* No locks available */
#define ENOSYS 78 /* Function not implemented */
#define EFTYPE 79 /* Inappropriate file type or format */
#define EAUTH 80 /* Authentication error */
#define ENEEDAUTH 81 /* Need authenticator */
/* Intelligent device errors */
#define EPWROFF 82 /* Device power is off */
#define EDEVERR 83 /* Device error, e.g. paper out */
#define EOVERFLOW 84 /* Value too large to be stored in data type */
/* Program loading errors */
#define EBADEXEC 85 /* Bad executable */
#define EBADARCH 86 /* Bad CPU type in executable */
#define ESHLIBVERS 87 /* Shared library version mismatch */
#define EBADMACHO 88 /* Malformed Macho file */
#define ECANCELED 89 /* Operation canceled */
#define EIDRM 90 /* Identifier removed */
#define ENOMSG 91 /* No message of desired type */
#define EILSEQ 92 /* Illegal byte sequence */
#define ENOATTR 93 /* Attribute not found */
#define EBADMSG 94 /* Bad message */
#define EMULTIHOP 95 /* Reserved */
#define ENODATA 96 /* No message available on STREAM */
#define ENOLINK 97 /* Reserved */
#define ENOSR 98 /* No STREAM resources */
#define ENOSTR 99 /* Not a STREAM */
#define EPROTO 100 /* Protocol error */
#define ETIME 101 /* STREAM ioctl timeout */
#define ENOPOLICY 103 /* No such policy registered */
#define ENOTRECOVERABLE 104 /* State not recoverable */
#define EOWNERDEAD 105 /* Previous owner died */
#define EQFULL 106 /* Interface output queue is full */
#define ELAST 106 /* Must be equal largest errno */
#ifdef __cplusplus
}
#endif
#endif // _ERRNO_H_

View File

@ -0,0 +1,65 @@
#ifndef _FLOAT_H_
#define _FLOAT_H_
#define FLT_RADIX 2
/* IEEE float */
#define FLT_MANT_DIG 24
#define FLT_DIG 6
#define FLT_ROUNDS 1
#define FLT_EPSILON 1.19209290e-07F
#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
/* IEEE double */
#define DBL_MANT_DIG 53
#define DBL_DIG 15
#define DBL_EPSILON 2.2204460492503131e-16
#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
/* horrible intel long double */
#if defined __i386__ || defined __x86_64__
#define LDBL_MANT_DIG 64
#define LDBL_DIG 18
#define LDBL_EPSILON 1.08420217248550443401e-19L
#define LDBL_MIN_EXP (-16381)
#define LDBL_MIN 3.36210314311209350626e-4932L
#define LDBL_MIN_10_EXP (-4931)
#define LDBL_MAX_EXP 16384
#define LDBL_MAX 1.18973149535723176502e+4932L
#define LDBL_MAX_10_EXP 4932
#else
/* same as IEEE double */
#define LDBL_MANT_DIG 53
#define LDBL_DIG 15
#define LDBL_EPSILON 2.2204460492503131e-16
#define LDBL_MIN_EXP (-1021)
#define LDBL_MIN 2.2250738585072014e-308
#define LDBL_MIN_10_EXP (-307)
#define LDBL_MAX_EXP 1024
#define LDBL_MAX 1.7976931348623157e+308
#define LDBL_MAX_10_EXP 308
#endif
#ifndef NAN
# define NAN (__nan__)
#endif
#ifndef INFINITY
# define INFINITY (__inf__)
#endif
#endif /* _FLOAT_H_ */

View File

@ -0,0 +1,21 @@
#ifndef _LIMITS_H_
#define _LIMITS_H_
#define INT_MAX 2147483647
#define UINT_MAX (INT_MAX * 2U + 1)
#ifndef ARG_MAX
#define ARG_MAX 4096
#endif
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
#ifndef STDIO_MAX_MEM
#define STDIO_MAX_MEM 4096
#endif
#endif /* _LIMITS_H_ */

View File

@ -0,0 +1,171 @@
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#ifndef _MATH_H_
#define _MATH_H_
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
extern double _FUNC(acos)(double _x);
extern double _FUNC(asin)(double _x);
extern double _FUNC(atan)(double _x);
extern double _FUNC(atan2)(double _y, double _x);
extern double _FUNC(ceil)(double _x);
extern double _FUNC(cos)(double _x);
extern double _FUNC(cosh)(double _x);
extern double _FUNC(exp)(double _x);
extern double _FUNC(fabs)(double _x);
extern double _FUNC(floor)(double _x);
extern double _FUNC(fmod)(double _x, double _y);
extern double _FUNC(frexp)(double _x, int *_pexp);
extern double _FUNC(ldexp)(double _x, int _exp);
extern double _FUNC(log)(double _y);
extern double _FUNC(log10)(double _x);
extern double _FUNC(modf)(double _x, double *_pint);
extern double _FUNC(pow)(double _x, double _y);
extern double _FUNC(sin)(double _x);
extern double _FUNC(sinh)(double _x);
extern double _FUNC(sqrt)(double _x);
extern double _FUNC(tan)(double _x);
extern double _FUNC(tanh)(double _x);
#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074
#define M_LOG10E 0.43429448190325182765
#define M_LN2 0.69314718055994530942
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.78539816339744830962
#define M_1_PI 0.31830988618379067154
#define M_2_PI 0.63661977236758134308
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440
#define PI M_PI
#define PI2 M_PI_2
extern double _FUNC(acosh)(double);
extern double _FUNC(asinh)(double);
extern double _FUNC(atanh)(double);
extern double _FUNC(cbrt)(double);
extern double _FUNC(exp10)(double _x);
extern double _FUNC(exp2)(double _x);
extern double _FUNC(expm1)(double);
extern double _FUNC(hypot)(double, double);
extern double _FUNC(log1p)(double);
extern double _FUNC(log2)(double _x);
extern long double _FUNC(modfl)(long double _x, long double *_pint);
extern double _FUNC(pow10)(double _x);
extern double _FUNC(pow2)(double _x);
extern double _FUNC(powi)(double, int);
extern void _FUNC(sincos)(double, double *, double *);
/* These are in libm.a (Cygnus). You must link -lm to get these */
/* See libm/math.h for comments */
#ifndef __cplusplus
struct exception {
int type;
const char *name;
double arg1;
double arg2;
double retval;
int err;
};
#endif
extern double _FUNC(erf)(double);
extern double _FUNC(erfc)(double);
extern double _FUNC(gamma)(double);
extern int _FUNC(isinf)(double);
extern int _FUNC(isnan)(double);
extern int _FUNC(finite)(double);
extern double _FUNC(j0)(double);
extern double _FUNC(j1)(double);
extern double _FUNC(jn)(int, double);
extern double _FUNC(lgamma)(double);
extern double _FUNC(nan)(const char*);
extern double _FUNC(y0)(double);
extern double _FUNC(y1)(double);
extern double _FUNC(yn)(int, double);
extern double _FUNC(logb)(double);
extern double _FUNC(nextafter)(double, double);
extern double _FUNC(remainder)(double, double);
extern double _FUNC(scalb)(double, double);
#ifndef __cplusplus
extern int _FUNC(matherr)(struct exception *);
#endif
extern double _FUNC(significand)(double);
extern double _FUNC(copysign)(double, double);
extern int _FUNC(ilogb)(double);
extern double _FUNC(rint)(double);
extern double _FUNC(scalbn)(double, int);
extern double _FUNC(drem)(double, double);
extern double _FUNC(gamma_r)(double, int *);
extern double _FUNC(lgamma_r)(double, int *);
extern float _FUNC(acosf)(float);
extern float _FUNC(asinf)(float);
extern float _FUNC(atanf)(float);
extern float _FUNC(atan2f)(float, float);
extern float _FUNC(cosf)(float);
extern float _FUNC(sinf)(float);
extern float _FUNC(tanf)(float);
extern float _FUNC(coshf)(float);
extern float _FUNC(sinhf)(float);
extern float _FUNC(tanhf)(float);
extern float _FUNC(expf)(float);
extern float _FUNC(frexpf)(float, int *);
extern float _FUNC(ldexpf)(float, int);
extern float _FUNC(logf)(float);
extern float _FUNC(log10f)(float);
extern float _FUNC(modff)(float, float *);
extern float _FUNC(powf)(float, float);
extern float _FUNC(sqrtf)(float);
extern float _FUNC(ceilf)(float);
extern float _FUNC(fabsf)(float);
extern float _FUNC(floorf)(float);
extern float _FUNC(fmodf)(float, float);
extern float _FUNC(erff)(float);
extern float _FUNC(erfcf)(float);
extern float _FUNC(gammaf)(float);
extern float _FUNC(hypotf)(float, float);
extern int _FUNC(isinff)(float);
extern int _FUNC(isnanf)(float);
extern int _FUNC(finitef)(float);
extern float _FUNC(j0f)(float);
extern float _FUNC(j1f)(float);
extern float _FUNC(jnf)(int, float);
extern float _FUNC(lgammaf)(float);
extern float _FUNC(nanf)(const char*);
extern float _FUNC(y0f)(float);
extern float _FUNC(y1f)(float);
extern float _FUNC(ynf)(int, float);
extern float _FUNC(acoshf)(float);
extern float _FUNC(asinhf)(float);
extern float _FUNC(atanhf)(float);
extern float _FUNC(cbrtf)(float);
extern float _FUNC(logbf)(float);
extern float _FUNC(nextafterf)(float, float);
extern float _FUNC(remainderf)(float, float);
extern float _FUNC(scalbf)(float, float);
extern float _FUNC(significandf)(float);
extern float _FUNC(copysignf)(float, float);
extern int _FUNC(ilogbf)(float);
extern float _FUNC(rintf)(float);
extern float _FUNC(scalbnf)(float, int);
extern float _FUNC(dremf)(float, float);
extern float _FUNC(expm1f)(float);
extern float _FUNC(log1pf)(float);
extern float _FUNC(gammaf_r)(float, int *);
extern float _FUNC(lgammaf_r)(float, int *);
#ifdef __cplusplus
}
#endif
#endif /* _MATH_H_ */

View File

@ -0,0 +1,17 @@
#ifndef _SETJMP_H_
#define _SETJMP_H_
#include <stddef.h>
typedef unsigned long __jmp_buf[6];
typedef struct __jmp_buf_tag {
__jmp_buf __jb;
unsigned long __fl;
unsigned long __ss[128/sizeof(long)];
} jmp_buf[1];
extern int _FUNC(setjmp)(jmp_buf env);
extern void _FUNC(longjmp)(jmp_buf env, int val);
#endif // _SETJMP_H_

View File

@ -0,0 +1,77 @@
#ifndef _STDARG_H_
#define _STDARG_H_
#include <stddef.h>
#ifdef __x86_64__
#ifndef _WIN64
//This should be in sync with the declaration on our lib/libtcc1.c
/* GCC compatible definition of va_list. */
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
union {
unsigned int overflow_offset;
char *overflow_arg_area;
};
char *reg_save_area;
} __va_list_struct;
typedef __va_list_struct va_list[1];
extern void _FUNC(__va_start)(__va_list_struct *ap, void *fp);
extern void* _FUNC(__va_arg)(__va_list_struct *ap, int arg_type, int size, int align);
#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
#define va_arg(ap, type) \
(*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
#define va_copy(dest, src) (*(dest) = *(src))
#define va_end(ap)
#else /* _WIN64 */
typedef char *va_list;
#define va_start(ap,last) __builtin_va_start(ap,last)
#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap)
#define va_copy(dest, src) ((dest) = (src))
#define va_end(ap)
#endif
#elif __arm__
typedef char *va_list;
#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
& ~(_tcc_alignof(type) - 1))
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
&~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
#define va_copy(dest, src) (dest) = (src)
#define va_end(ap)
#elif defined(__aarch64__)
typedef struct {
void *__stack;
void *__gr_top;
void *__vr_top;
int __gr_offs;
int __vr_offs;
} va_list;
#define va_start(ap, last) __va_start(ap, last)
#define va_arg(ap, type) __va_arg(ap, type)
#define va_end(ap)
#define va_copy(dest, src) ((dest) = (src))
#else /* __i386__ */
typedef char *va_list;
/* only correct for i386 */
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
#define va_copy(dest, src) (dest) = (src)
#define va_end(ap)
#endif
/* fix a buggy dependency on GCC in libio.h */
typedef va_list __gnuc_va_list;
#define _VA_LIST_DEFINED
#endif /* _STDARG_H */

View File

@ -0,0 +1,11 @@
#ifndef _STDBOOL_H_
#define _STDBOOL_H_
/* ISOC99 boolean */
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif /* _STDBOOL_H */

View File

@ -0,0 +1,37 @@
#ifndef _STDDEF_H_
#define _STDDEF_H_
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __WCHAR_TYPE__ wchar_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __PTRDIFF_TYPE__ intptr_t;
typedef __SIZE_TYPE__ uintptr_t;
#ifndef __int8_t_defined
#define __int8_t_defined
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed long long int int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
#endif
#ifndef NULL
#define NULL ((void*)0)
#endif
#ifdef _KOLIBRI_LIBC_OBJ
#define _FUNC(func) func
#else
#define _FUNC(func) (*func)
#endif
#define offsetof(type, field) ((size_t)&((type *)0)->field)
#endif /* _STDDEF_H_ */

View File

@ -0,0 +1,28 @@
#ifndef _STDINT_H_
#define _STDINT_H_
#include <stddef.h>
#define INT8_MIN (-128)
#define INT8_MAX (127)
#define UINT8_MAX (255)
#define INT16_MIN (-32768)
#define INT16_MAX (32767)
#define UINT16_MAX (65535)
#define INT32_MIN (-2147483647L-1)
#define INT32_MAX (2147483647L)
#define UINT32_MAX (4294967295UL)
#if __have_long64
#define INT64_MIN (-9223372036854775807L-1L)
#define INT64_MAX (9223372036854775807L)
#define UINT64_MAX (18446744073709551615U)
#elif __have_longlong64
#define INT64_MIN (-9223372036854775807LL-1LL)
#define INT64_MAX (9223372036854775807LL)
#define UINT64_MAX (18446744073709551615ULL)
#endif
#endif /* _STDINT_H_*/

View File

@ -0,0 +1,146 @@
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
// 2014-2019, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _STDIO_H_
#define _STDIO_H_
#include <stdarg.h>
#include <stddef.h>
#include <sys/ksys.h>
extern int _FUNC(puts)(const char *str);
extern int _FUNC(printf)(const char* format, ...);
extern int _FUNC(sprintf)(char* buffer, const char* format, ...);
extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...);
extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va);
extern int _FUNC(vprintf)(const char* format, va_list va);
extern void _FUNC(debug_printf)(const char* format, ...);
typedef size_t fpos_t;
#define _STDIO_F_R 1 << 0 // Read
#define _STDIO_F_W 1 << 1 // Write
#define _STDIO_F_A 1 << 2 // Append
#define _STDIO_F_X 1 << 3 // eXclusive
#define _STDIO_F_B 1 << 4 // Binary
typedef struct FILE_s {
char *name;
fpos_t position;
int error;
int eof;
int kind; // 0 - undiefned, 1 - text, 2 - binary
int orientation; // 0 - undiefned, 1 - byte, 2 - wide
int mode; // flags _STDIO_F_*
int append_offset; // do not seek before this point ("a" mode)
int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!)
int start_size;
} FILE;
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
#define BUFSIZ 1024
#define EOF -1
#define FOPEN_MAX 0xffffffff
#define FILENAME_MAX 255
#define L_tmpnam FILENAME_MAX
#define SEEK_CUR 0
#define SEEK_END 1
#define SEEK_SET 2
#define TMP_MAX FOPEN_MAX
#define stderr (FILE*)3
#define stdin (FILE*)1
#define stdout (FILE*)2
extern int _FUNC(fgetc)(FILE *);
extern char* _FUNC(fgets)(char *restrict, int, FILE *restrict);
extern int _FUNC(fprintf)(FILE *restrict, const char *restrict, ...);
extern int _FUNC(fputc)(int, FILE *);
extern int _FUNC(fputs)(const char *restrict, FILE *restrict);
extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *restrict);
extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...);
extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict);
extern int _FUNC(getc)(FILE *);
#define getc _FUNC(fgetc)
extern int _FUNC(getchar)(void);
extern int _FUNC(printf)(const char *restrict, ...);
extern int _FUNC(putc)(int, FILE *);
extern int _FUNC(putchar)(int);
extern int _FUNC(puts)(const char *);
extern int _FUNC(scanf)(const char *restrict, ...);
extern char* _FUNC(gets)(char *str);
//extern int _FUNC(ungetc)(int, FILE *);
extern int _FUNC(vfprintf)(FILE *restrict, const char *restrict, va_list);
extern int _FUNC(vfscanf)(FILE *restrict, const char *restrict, va_list);
extern int _FUNC(vprintf)(const char *restrict, va_list);
extern int _FUNC(vscanf)(const char *restrict, va_list);
extern int _FUNC(vsscanf)(const char *, const char*, va_list);
extern int _FUNC(remove)(const char *);
extern int _FUNC(rename)(const char *, const char *);
extern FILE* _FUNC(tmpfile)(void);
extern char* _FUNC(tmpnam)(char *);
extern int _FUNC(fclose)(FILE *);
extern int _FUNC(fflush)(FILE *);
extern FILE* _FUNC(fopen)(const char *restrict, const char *restrict);
extern FILE* _FUNC(freopen)(const char *restrict, const char *restrict, FILE *restrict);
extern void _FUNC(setbuf)(FILE *restrict, char *restrict);
extern int _FUNC(setvbuf)(FILE *restrict, char *restrict, int, size_t);
extern int _FUNC(fgetpos)(FILE *restrict, fpos_t *restrict);
extern int _FUNC(fseek)(FILE *, long, int);
extern int _FUNC(fsetpos)(FILE *, const fpos_t *);
extern long _FUNC(ftell)(FILE *);
extern void _FUNC(rewind)(FILE *);
extern void _FUNC(clearerr)(FILE *);
extern int _FUNC(feof)(FILE *);
extern int _FUNC(ferror)(FILE *);
extern void _FUNC(perror)(const char *);
extern size_t _FUNC(fread)(void *restrict, size_t, size_t, FILE *restrict);
extern int _FUNC(getchar)(void);
extern void _FUNC(con_set_title)(const char*);
#endif // _STDIO_H_

View File

@ -0,0 +1,40 @@
#ifndef _STDLIB_H_
#define _STDLIB_H_
#include <stddef.h>
#define RAND_MAX 65535
#ifndef NULL
# define NULL ((void*)0)
#endif
#define min(a, b) ((a)<(b) ? (a) : (b))
#define max(a, b) ((a)>(b) ? (a) : (b))
extern int _FUNC(atoi)(const char *s);
extern long _FUNC(atol)(const char *);
extern long long _FUNC(atoll)(const char *);
extern void _FUNC(itoa)(int n, char* s);
extern int _FUNC(abs)(int);
extern long _FUNC(labs)(long);
extern long long _FUNC(llabs)(long long);
typedef struct { int quot, rem; } div_t;
typedef struct { long quot, rem; } ldiv_t;
typedef struct { long long quot, rem; } lldiv_t;
extern div_t _FUNC(div)(int, int);
extern ldiv_t _FUNC(ldiv)(long, long);
extern lldiv_t _FUNC(lldiv)(long long, long long);
extern void* _FUNC(malloc)(size_t size);
extern void* _FUNC(calloc)(size_t num, size_t size);
extern void* _FUNC(realloc)(void *ptr, size_t newsize);
extern void _FUNC(free)(void *ptr);
extern long int _FUNC(strtol)(const char* str, char** endptr, int base);
extern void _FUNC(exit)(int status);
#endif

View File

@ -0,0 +1,186 @@
/* String handling <string.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#ifndef _STRING_H_
#define _STRING_H_
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* String function conventions */
/*
In any of the following functions taking a size_t n to specify the length of
an array or size of a memory region, n may be 0, but the pointer arguments to
the call shall still be valid unless otherwise stated.
*/
/* Copying functions */
extern void* _FUNC(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n);
/* Copy a number of n characters from the memory area pointed to by s2 to the
area pointed to by s1. If the two areas overlap, behaviour is undefined.
Returns the value of s1.
*/
extern void* _FUNC(memcpy)(void* s1, const void* s2, size_t n);
/* Copy a number of n characters from the memory area pointed to by s2 to the
area pointed to by s1. The two areas may overlap.
Returns the value of s1.
*/
extern void* memmove(void* s1, const void* s2, size_t n);
/* Copy the character array s2 (including terminating '\0' byte) into the
character array s1.
Returns the value of s1.
*/
extern char* _FUNC(strcpy)(char* s1, const char* s2);
/* Copy a maximum of n characters from the character array s2 into the character
array s1. If s2 is shorter than n characters, '\0' bytes will be appended to
the copy in s1 until n characters have been written. If s2 is longer than n
characters, NO terminating '\0' will be written to s1. If the arrays overlap,
behaviour is undefined.
Returns the value of s1.
*/
extern char* _FUNC(strncpy)(char* s1, const char* s2, size_t n);
/* Concatenation functions */
/* Append the contents of the character array s2 (including terminating '\0') to
the character array s1 (first character of s2 overwriting the '\0' of s1). If
the arrays overlap, behaviour is undefined.
Returns the value of s1.
*/
extern char* _FUNC(strcat)(char* s1, const char* s2);
/* Append a maximum of n characters from the character array s2 to the character
array s1 (first character of s2 overwriting the '\0' of s1). A terminating
'\0' is ALWAYS appended, even if the full n characters have already been
written. If the arrays overlap, behaviour is undefined.
Returns the value of s1.
*/
extern char* _FUNC(strncat)(char* s1, const char* s2, size_t n);
/* Comparison functions */
/* Compare the first n characters of the memory areas pointed to by s1 and s2.
Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
s1 > s2.
*/
extern int _FUNC(memcmp)(const void * s1, const void* s2, size_t n);
/* Compare the character arrays s1 and s2.
Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
s1 > s2.
*/
extern int _FUNC(strcmp)(const char * s1, const char* s2);
/* Compare the character arrays s1 and s2, interpreted as specified by the
LC_COLLATE category of the current locale.
Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
s1 > s2.
TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support
locales.
*/
extern int _FUNC(strcoll)(const char* s1, const char* s2);
/* Compare no more than the first n characters of the character arrays s1 and
s2.
Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if
s1 > s2.
*/
extern int _FUNC(strncmp)(const char* s1, const char* s2, size_t n);
/* Transform the character array s2 as appropriate for the LC_COLLATE setting of
the current locale. If length of resulting string is less than n, store it in
the character array pointed to by s1. Return the length of the resulting
string.
*/
extern size_t _FUNC(strxfrm)(char* s1, const char* s2, size_t n);
/* Search functions */
/* Search the first n characters in the memory area pointed to by s for the
character c (interpreted as unsigned char).
Returns a pointer to the first instance found, or NULL.
*/
extern void* _FUNC(memchr)(const void* s, int c, size_t n);
/* Search the character array s (including terminating '\0') for the character c
(interpreted as char).
Returns a pointer to the first instance found, or NULL.
*/
extern char* _FUNC(strchr)(const char* s, int c);
/* Determine the length of the initial substring of character array s1 which
consists only of characters not from the character array s2.
Returns the length of that substring.
*/
extern size_t _FUNC(strcspn)(const char* s1, const char* s2);
/* Search the character array s1 for any character from the character array s2.
Returns a pointer to the first occurrence, or NULL.
*/
extern char* _FUNC(strpbrk)(const char* s1, const char* s2);
/* Search the character array s (including terminating '\0') for the character c
(interpreted as char).
Returns a pointer to the last instance found, or NULL.
*/
extern char* _FUNC(strrchr)(const char * s, int c );
/* Determine the length of the initial substring of character array s1 which
consists only of characters from the character array s2.
Returns the length of that substring.
*/
extern size_t _FUNC(strspn)(const char * s1, const char * s2);
/* Search the character array s1 for the substring in character array s2.
Returns a pointer to that sbstring, or NULL. If s2 is of length zero,
returns s1.
*/
extern char* _FUNC(strstr)(const char * s1, const char * s2);
/* In a series of subsequent calls, parse a C string into tokens.
On the first call to strtok(), the first argument is a pointer to the to-be-
parsed C string. On subsequent calls, the first argument is NULL unless you
want to start parsing a new string. s2 holds an array of separator characters
which can differ from call to call. Leading separators are skipped, the first
trailing separator overwritten with '\0'.
Returns a pointer to the next token.
WARNING: This function uses static storage, and as such is not reentrant.
*/
extern char* _FUNC(strtok)(char* s1, const char* s2);
/* Miscellaneous functions */
/* Write the character c (interpreted as unsigned char) to the first n
characters of the memory area pointed to by s.
Returns s.
*/
extern void* _FUNC(memset)(void* s, int c, size_t n);
/* Map an error number to a (locale-specific) error message string. Error
numbers are typically errno values, but any number is mapped to a message.
TODO: PDCLib does not yet support locales.
*/
extern char* _FUNC(strerror)(int errnum);
/* Returns the length of the string s (excluding terminating '\0').*/
extern size_t _FUNC(strlen)(const char * s);
/* The function reverses the sequence of characters in the string pointed to by str. */
extern char* _FUNC(strrev)(char *str);
/* The strdup function executes the function pointed to by the str argument. */
extern char* _FUNC(strdup)(const char *str);
#endif

View File

@ -0,0 +1,34 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#ifndef _DIRENT_H_
#define _DIRENT_H_
#include <stddef.h>
#include <limits.h>
#define IS_FOLDER 16
#define IS_FILE 0
typedef unsigned ino_t;
struct dirent{
ino_t d_ino; //File serial number.
char d_name[PATH_MAX]; // Name of entry.
unsigned d_type;
};
typedef struct{
struct dirent* objs;
ino_t pos;
ino_t num_objs;
}DIR;
int _FUNC(closedir)(DIR *dir);
DIR* _FUNC(opendir)(const char *path);
struct dirent* _FUNC(readdir)(DIR *);
void _FUNC(rewinddir)(DIR *dir);
void _FUNC(seekdir)(DIR *dir, unsigned pos);
unsigned _FUNC(telldir)(DIR *dir);
#endif // _DIRENT_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,244 @@
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv2 */
#ifndef _SOCKET_H_
#define _SOCKET_H_
#include <stddef.h>
#include <sys/ksys.h>
#include <errno.h>
// Socket Types
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_RAW 3
// IP protocols
#define IPPROTO_IP 0
#define IPPROTO_ICMP 1
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_RAW 255
// IP options
#define IP_TTL 2
// Address families
#define AF_UNSPEC 0
#define AF_LOCAL 1
#define AF_INET 2 // Default INET=IPv4
#define AF_INET4 2 // IPv4
#define AF_INET6 10 // IPv6
#define PF_UNSPEC AF_UNSPEC
#define PF_LOCAL AF_LOCAL
#define PF_INET4 AF_INET4
#define PF_INET6 AF_INET6
// internal definition
#define AI_SUPPORTED 0x40F
// for system function 76
#define API_ETH (0<<16)
#define API_IPv4 (1<<16)
#define API_ICMP (2<<16)
#define API_UDP (3<<16)
#define API_TCP (4<<16)
#define API_ARP (5<<16)
#define API_PPPOE (6<<16)
// Socket flags for user calls
#define MSG_NOFLAG 0
#define MSG_PEEK 0x02
#define MSG_DONTWAIT 0x40
// Socket levels
#define SOL_SOCKET 0xffff
//Socket options
#define SO_BINDTODEVICE (1<<9)
#define SO_NONBLOCK (1<<31)
#define PORT(X) (X<<8)
#pragma pack(push,1)
struct sockaddr{
unsigned short sin_family;
unsigned short sin_port;
unsigned int sin_addr;
unsigned long long sin_zero;
};
typedef struct{
unsigned int level;
unsigned int optionname;
unsigned int optlenght;
unsigned char options;
}optstruct;
#pragma pack(pop)
static inline
void _conv_socket_err(){
switch(errno){
case 1: errno = ENOBUFS; break;
case 2: errno = EINPROGRESS; break;
case 4: errno = EOPNOTSUPP; break;
case 6: errno = EWOULDBLOCK; break;
case 9: errno = ENOTCONN; break;
case 10: errno = EALREADY; break;
case 11: errno = EINVAL; break;
case 12: errno = EMSGSIZE; break;
case 18: errno = ENOMEM; break;
case 20: errno = EADDRINUSE; break;
case 61: errno = ECONNREFUSED; break;
case 52: errno = ECONNRESET; break;
case 56: errno = EISCONN; break;
case 60: errno = ETIMEDOUT; break;
case 54: errno = ECONNABORTED; break;
default: errno = 0; break;
}
}
static inline
int socket(int domain, int type, int protocol)
{
int socket;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(socket)
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
);
_conv_socket_err();
return socket;
}
static inline
int close(int socket)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(1), "c"(socket)
);
_conv_socket_err();
return status;
}
static inline
int bind(int socket, const struct sockaddr *addres, int addres_len)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
);
_conv_socket_err();
return status;
}
static inline
int listen(int socket, int backlog)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
);
_conv_socket_err();
return status;
}
static inline
int connect(int socket, const struct sockaddr* address, int socket_len)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
);
_conv_socket_err();
return status;
}
static inline int
accept(int socket, const struct sockaddr *address, int address_len)
{
int new_socket;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(new_socket)
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
);
_conv_socket_err();
return new_socket;
}
static inline
int send(int socket, const void *message, size_t msg_len, int flag)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
);
_conv_socket_err();
return status;
}
static inline
int recv(int socket, void *buffer, size_t buff_len, int flag)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
);
_conv_socket_err();
return status;
}
static inline
int setsockopt(int socket,const optstruct* opt)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(8), "c"(socket),"d"(opt)
);
_conv_socket_err();
return status;
}
static inline
int getsockopt(int socket, optstruct* opt)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(9), "c"(socket),"d"(opt)
);
_conv_socket_err();
return status;
}
static inline
int socketpair(int *socket1, int *socket2)
{
asm_inline(
"int $0x40"
:"=b"(*socket2), "=a"(*socket1)
:"a"(75), "b"(10)
);
errno=*socket2;
_conv_socket_err();
return *socket1;
}
#endif //_SOCKET_H_

View File

@ -0,0 +1,30 @@
#ifndef _TIME_H_
#define _TIME_H_
#include <sys/ksys.h>
typedef unsigned long int clock_t;
typedef unsigned long int time_t;
#define clock() _ksys_get_clock()
#define CLOCKS_PER_SEC 100
struct tm {
int tm_sec; /* seconds after the minute 0-61*/
int tm_min; /* minutes after the hour 0-59 */
int tm_hour; /* hours since midnight 0-23 */
int tm_mday; /* day of the month 1-31 */
int tm_mon; /* months since January 0-11 */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday 0-6 */
int tm_yday; /* days since January 1 0-365 */
int tm_isdst; /* Daylight Saving Time flag */
};
extern time_t _FUNC(mktime)(struct tm * timeptr);
extern time_t _FUNC(time)(time_t* timer);
extern struct tm * _FUNC(localtime)(const time_t * timer); /* non-standard! ignore parameter and return just time now, not generate tm_isdst, tm_yday, tm_wday == -1 */
extern double _FUNC(difftime)(time_t end, time_t beginning);
extern struct tm buffertime;
#endif

Binary file not shown.