-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libc improvements: ctype, errno, div/ldiv/lldiv, strerror; math.h, ti…
…me.h, wchar.h stubs (#128)
- Loading branch information
1 parent
d563b76
commit fdb1bd0
Showing
12 changed files
with
211 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdlib.h> | ||
|
||
template <typename T, typename R> static inline R _div(T numer, T denom) { | ||
R result; | ||
result.quot = numer / denom; | ||
result.rem = numer % denom; | ||
return result; | ||
} | ||
|
||
extern "C" { | ||
div_t div(int numer, int denom) { return _div<int, div_t>(numer, denom); } | ||
ldiv_t ldiv(long numer, long denom) { return _div<long, ldiv_t>(numer, denom); } | ||
lldiv_t lldiv(long long numer, long long denom) { return _div<long long, lldiv_t>(numer, denom); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int _errno = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <string.h> | ||
|
||
static const char *errors[] = { | ||
"ERANGE", | ||
"EDOM", | ||
"EILSEQ", | ||
"EINVAL", | ||
"ENOMEM" | ||
}; | ||
|
||
__attribute__((weak)) const char *strerror(int n) { | ||
if (n > 0) { | ||
return errors[((unsigned char) n) - 1]; | ||
} else { | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef _ERRNO_H_ | ||
#define _ERRNO_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern int _errno; | ||
#define errno (_errno) | ||
|
||
#define ERANGE 1 | ||
#define EDOM 2 | ||
#define EILSEQ 3 | ||
#define EINVAL 4 | ||
#define ENOMEM 5 | ||
#define ELAST 5 | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // not _ERRNO_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Stub implementation of math.h. | ||
|
||
#ifndef _MATH_H_ | ||
#define _MATH_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define FP_NORMAL 0 | ||
#define FP_SUBNORMAL 1 | ||
#define FP_ZERO 2 | ||
#define FP_INFINITE 3 | ||
#define FP_NAN 4 | ||
|
||
#define INFINITY (1.0f / 0.0f) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // not _MATH_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Stub implementation of time.h. | ||
|
||
#ifndef _TIME_H_ | ||
#define _TIME_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef long time_t; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // not _TIME_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Stub implementation of wchar.h. | ||
|
||
#ifndef _WCHAR_H_ | ||
#define _WCHAR_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef unsigned long mbstate_t; | ||
typedef unsigned long wint_t; | ||
|
||
#define WEOF 0xFFFFFFFFul | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // not _WCHAR_H_ |