libc: support for building libstdc++?
This commit is contained in:
parent
c3a6b4f486
commit
b33815c632
@ -1,4 +1,5 @@
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
extern void __assert_func(const char * file, int line, const char * func, const char * failedexpr);
|
||||||
#define assert(statement) ((statement) ? (void)0 : __assert_func(__FILE__, __LINE__, __FUNCTION__, #statement))
|
#define assert(statement) ((statement) ? (void)0 : __assert_func(__FILE__, __LINE__, __FUNCTION__, #statement))
|
||||||
#else
|
#else
|
||||||
#define assert(statement) ((void)0)
|
#define assert(statement) ((void)0)
|
||||||
|
@ -17,3 +17,16 @@ extern int isascii(int c);
|
|||||||
|
|
||||||
extern int tolower(int c);
|
extern int tolower(int c);
|
||||||
extern int toupper(int c);
|
extern int toupper(int c);
|
||||||
|
|
||||||
|
/* Derived from newlib */
|
||||||
|
#define _U 01
|
||||||
|
#define _L 02
|
||||||
|
#define _N 04
|
||||||
|
#define _S 010
|
||||||
|
#define _P 020
|
||||||
|
#define _C 040
|
||||||
|
#define _X 0100
|
||||||
|
#define _B 0200
|
||||||
|
|
||||||
|
extern char _ctype_[256];
|
||||||
|
|
||||||
|
10
base/usr/include/iconv.h
Normal file
10
base/usr/include/iconv.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef void * iconv_t;
|
||||||
|
|
||||||
|
extern iconv_t iconv_open(const char *tocode, const char *fromcode);
|
||||||
|
extern int iconv_close(iconv_t cd);
|
||||||
|
extern size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
|
||||||
|
|
@ -6,7 +6,9 @@ extern double pow(double x, double y);
|
|||||||
extern double exp(double x);
|
extern double exp(double x);
|
||||||
extern double fmod(double x, double y);
|
extern double fmod(double x, double y);
|
||||||
extern double sqrt(double x);
|
extern double sqrt(double x);
|
||||||
|
extern float sqrtf(float x);
|
||||||
extern double fabs(double x);
|
extern double fabs(double x);
|
||||||
|
extern float fabsf(float x);
|
||||||
extern double sin(double x);
|
extern double sin(double x);
|
||||||
extern double cos(double x);
|
extern double cos(double x);
|
||||||
|
|
||||||
|
@ -83,3 +83,10 @@ extern int vsscanf(const char *str, const char *format, va_list ap);
|
|||||||
extern int sscanf(const char *str, const char *format, ...);
|
extern int sscanf(const char *str, const char *format, ...);
|
||||||
extern int vfscanf(FILE * stream, const char *format, va_list ap);
|
extern int vfscanf(FILE * stream, const char *format, va_list ap);
|
||||||
extern int fscanf(FILE *stream, const char *format, ...);
|
extern int fscanf(FILE *stream, const char *format, ...);
|
||||||
|
extern int scanf(const char *format, ...);
|
||||||
|
|
||||||
|
typedef long fpos_t;
|
||||||
|
|
||||||
|
extern int fgetpos(FILE *stream, fpos_t *pos);
|
||||||
|
extern int fsetpos(FILE *stream, const fpos_t *pos);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ extern int setenv(const char *name, const char *value, int overwrite);
|
|||||||
extern int unsetenv(const char * str);
|
extern int unsetenv(const char * str);
|
||||||
|
|
||||||
extern double strtod(const char *nptr, char **endptr);
|
extern double strtod(const char *nptr, char **endptr);
|
||||||
|
extern float strtof(const char *nptr, char **endptr);
|
||||||
extern double atof(const char * nptr);
|
extern double atof(const char * nptr);
|
||||||
extern int atoi(const char * nptr);
|
extern int atoi(const char * nptr);
|
||||||
extern long atol(const char * nptr);
|
extern long atol(const char * nptr);
|
||||||
@ -49,7 +50,14 @@ extern void abort(void);
|
|||||||
extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
|
extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
|
||||||
int (*compar)(const void *, const void *));
|
int (*compar)(const void *, const void *));
|
||||||
|
|
||||||
extern char * mktemp(char * template);
|
extern char * mktemp(char *);
|
||||||
|
|
||||||
extern size_t mbstowcs(wchar_t *dest, const char *src, size_t n);
|
extern size_t mbstowcs(wchar_t *dest, const char *src, size_t n);
|
||||||
extern size_t wcstombs(char * dest, const wchar_t *src, size_t n);
|
extern size_t wcstombs(char * dest, const wchar_t *src, size_t n);
|
||||||
|
|
||||||
|
typedef struct { int quot; int rem; } div_t;
|
||||||
|
typedef struct { long int quot; long int rem; } ldiv_t;
|
||||||
|
|
||||||
|
extern div_t div(int numerator, int denominator);
|
||||||
|
extern ldiv_t ldiv(long numerator, long denominator);
|
||||||
|
|
||||||
|
@ -45,5 +45,6 @@ extern char * strtok_r(char * str, const char * delim, char ** saveptr);
|
|||||||
extern char * strncpy(char *dest, const char *src, size_t n);
|
extern char * strncpy(char *dest, const char *src, size_t n);
|
||||||
|
|
||||||
extern char * strerror(int errnum);
|
extern char * strerror(int errnum);
|
||||||
|
extern size_t strxfrm(char *dest, const char *src, size_t n);
|
||||||
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
20
libc/ctype/_ctype.c
Normal file
20
libc/ctype/_ctype.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
char _ctype_[256]= {
|
||||||
|
_C, _C, _C, _C, _C, _C, _C, _C,
|
||||||
|
_C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
|
||||||
|
_C, _C, _C, _C, _C, _C, _C, _C,
|
||||||
|
_C, _C, _C, _C, _C, _C, _C, _C,
|
||||||
|
_S|_B, _P, _P, _P, _P, _P, _P, _P,
|
||||||
|
_P, _P, _P, _P, _P, _P, _P, _P,
|
||||||
|
_N, _N, _N, _N, _N, _N, _N, _N,
|
||||||
|
_N, _N, _P, _P, _P, _P, _P, _P,
|
||||||
|
_P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
|
||||||
|
_U, _U, _U, _U, _U, _U, _U, _U,
|
||||||
|
_U, _U, _U, _U, _U, _U, _U, _U,
|
||||||
|
_U, _U, _U, _P, _P, _P, _P, _P,
|
||||||
|
_P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
|
||||||
|
_L, _L, _L, _L, _L, _L, _L, _L,
|
||||||
|
_L, _L, _L, _L, _L, _L, _L, _L,
|
||||||
|
_L, _L, _L, _P, _P, _P, _P, _C
|
||||||
|
};
|
37
libc/iconv/iconv.c
Normal file
37
libc/iconv/iconv.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <iconv.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct _iconv_state {
|
||||||
|
char *tocode;
|
||||||
|
char *fromcode;
|
||||||
|
};
|
||||||
|
|
||||||
|
iconv_t iconv_open(const char *tocode, const char *fromcode) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (iconv_t)-1;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
struct _iconv_state * state = malloc(sizeof(struct _iconv_state));
|
||||||
|
|
||||||
|
state->tocode = strdup(tocode);
|
||||||
|
state->fromcode = strdup(fromcode);
|
||||||
|
|
||||||
|
return (iconv_t)state;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int iconv_close(iconv_t cd) {
|
||||||
|
struct _iconv_state * state = (struct _iconv_state*)cd;
|
||||||
|
|
||||||
|
free(state->tocode);
|
||||||
|
free(state->fromcode);
|
||||||
|
|
||||||
|
free(cd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) {
|
||||||
|
return -1;
|
||||||
|
}
|
@ -68,6 +68,10 @@ double fabs(double x) {
|
|||||||
return __builtin_fabs(x);
|
return __builtin_fabs(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float fabsf(float x) {
|
||||||
|
return fabs(x);
|
||||||
|
}
|
||||||
|
|
||||||
double fmod(double x, double y) {
|
double fmod(double x, double y) {
|
||||||
MATH;
|
MATH;
|
||||||
if (x >= 0.0) {
|
if (x >= 0.0) {
|
||||||
@ -85,6 +89,10 @@ double sqrt(double x) {
|
|||||||
return __builtin_sqrt(x);
|
return __builtin_sqrt(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float sqrtf(float x) {
|
||||||
|
return sqrt(x);
|
||||||
|
}
|
||||||
|
|
||||||
static double bad_sine_table[] = {
|
static double bad_sine_table[] = {
|
||||||
0,
|
0,
|
||||||
0.01745240644,
|
0.01745240644,
|
||||||
|
@ -52,3 +52,11 @@ int fscanf(FILE *stream, const char *format, ...) {
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int scanf(const char *format, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
int out = vfscanf(stdin, format, args);
|
||||||
|
va_end(args);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
@ -289,6 +289,18 @@ long ftell(FILE * stream) {
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fgetpos(FILE *stream, fpos_t *pos) {
|
||||||
|
long ret = ftell(stream);
|
||||||
|
if (ret == -1) return -1;
|
||||||
|
|
||||||
|
*pos = ret;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsetpos(FILE *stream, const fpos_t *pos) {
|
||||||
|
return fseek(stream, *pos, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
size_t fread(void *ptr, size_t size, size_t nmemb, FILE * stream) {
|
size_t fread(void *ptr, size_t size, size_t nmemb, FILE * stream) {
|
||||||
char * tracking = (char*)ptr;
|
char * tracking = (char*)ptr;
|
||||||
for (size_t i = 0; i < nmemb; ++i) {
|
for (size_t i = 0; i < nmemb; ++i) {
|
||||||
|
33
libc/stdlib/div.c
Normal file
33
libc/stdlib/div.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
div_t div(int numerator, int denominator) {
|
||||||
|
div_t out;
|
||||||
|
out.quot = numerator / denominator;
|
||||||
|
out.rem = numerator % denominator;
|
||||||
|
|
||||||
|
if (numerator >= 0 && out.rem < 0) {
|
||||||
|
out.quot++;
|
||||||
|
out.rem -= denominator;
|
||||||
|
} else if (numerator < 0 && out.rem > 0) {
|
||||||
|
out.quot--;
|
||||||
|
out.rem += denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ldiv_t ldiv(long numerator, long denominator) {
|
||||||
|
ldiv_t out;
|
||||||
|
out.quot = numerator / denominator;
|
||||||
|
out.rem = numerator % denominator;
|
||||||
|
|
||||||
|
if (numerator >= 0 && out.rem < 0) {
|
||||||
|
out.quot++;
|
||||||
|
out.rem -= denominator;
|
||||||
|
} else if (numerator < 0 && out.rem > 0) {
|
||||||
|
out.quot--;
|
||||||
|
out.rem += denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
@ -72,3 +72,6 @@ double strtod(const char *nptr, char **endptr) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float strtof(const char *nptr, char **endptr) {
|
||||||
|
return strtod(nptr,endptr);
|
||||||
|
}
|
||||||
|
19
libc/string/strxfrm.c
Normal file
19
libc/string/strxfrm.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We only really support the "C" locale, so this is always
|
||||||
|
* just a dumb memcpy.
|
||||||
|
*/
|
||||||
|
size_t strxfrm(char *dest, const char *src, size_t n) {
|
||||||
|
size_t i = 0;
|
||||||
|
while (*src && i < n) {
|
||||||
|
*dest = *src;
|
||||||
|
dest++;
|
||||||
|
src++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i < n) {
|
||||||
|
*dest = '\0';
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user