libc.h
5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#ifndef __TV_libc_h_
#define __TV_libc_h_
#include <rkfsn.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NULL 0
typedef struct {
int quot;
int rem;
} div_t;
typedef struct {
long quot;
long rem;
} ldiv_t;
#define RAND_MAX 2147483647
typedef unsigned int size_t;
struct complex
{
double __x, __y;
};
extern void abort(void);
extern int printf(const char*, ...);
extern int sprintf(char *buf, const char *fmt, ...);
extern int vsprintf(char *buf, const char *fmt, /* va_list */ char *);
#ifdef __TV_ASSERT
#ifdef __ANSI_CPP__
#define assert(EX) {if (!(EX)) {printf("Assertion failed: %s, %s:%d\n", \
# EX, __FILE__, __LINE__); abort();}}
#else
#define assert(EX) {if (!(EX)) {printf("Assertion failed: %s, %s:%d\n", \
"EX", __FILE__, __LINE__); abort();}}
#endif
#else /* __TV_ASSERT */
#undef assert
#define assert(EX) {0;}
#endif /* __TV_ASSERT */
/*
** String/memory functions
*/
extern void *memcpy(void *dest, const void *src, size_t n);
extern void *memmove(void *dest, const void *src, size_t n);
extern void *memccpy(void *dest, const void *src, int c, size_t n);
extern void *memset(void *s, int c, size_t n);
extern int memcmp(const void *s1, const void *s2, size_t n);
extern void *memchr(const void *s, int c, size_t n);
extern char *strcpy(char *dest, const char *src);
extern char *strncpy(char *dest, const char *src, size_t n);
extern char *strcat(char *src, const char *dest);
extern char *strncat(char *dest, const char *src, size_t n);
extern int strcmp(const char *s1, const char *s2);
extern int strncmp(const char *s1, const char *s2, size_t n);
extern int strcoll(const char *s1, const char *s2);
extern size_t strxfrm(char *dest, const char *src, size_t n);
extern char *strchr(const char *s, int c);
extern char *strrchr(const char *s, int c);
extern size_t strcspn(const char *s, const char *reject);
extern size_t strspn(const char *s, const char *accept);
extern char *strpbrk(const char *s, const char *accept);
extern char *strstr(const char *haystack, const char *needle);
extern char *strtok(char *s, const char *delim);
extern size_t strlen(const char *s);
extern char *index(const char *s, int c);
extern char *rindex(const char *s, int c);
extern void bcopy(const void *src, void *dest, size_t n);
extern void bzero(void *s, size_t n);
extern int bcmp(const void *s1, const void *s2, size_t n);
extern int ffs(int i);
extern int strcasecmp(const char *s1, const char *s2);
extern int strncasecmp(const char *s1, const char *s2, size_t n);
extern char *stpcpy(char *dest, const char *src);
extern int tolower(int c);
extern int toupper(int c);
extern int isascii(int c);
extern int toascii(int c);
/*
** Math functions
*/
extern double acos(double x);
extern double asin(double x);
extern double atan(double x);
extern double atan2(double y, double x);
extern double cos(double x);
extern double sin(double x);
extern double tan(double x);
extern double cosh(double x);
extern double sinh(double x);
extern double tanh(double x);
extern double acosh(double x);
extern double asinh(double x);
extern double atanh(double x);
extern double exp(double x);
extern double frexp(double value, int *exp);
extern double ldexp(double x, int exp);
extern double log(double x);
extern double log10(double x);
extern double expm1(double x);
extern double log1p(double x);
extern double modf(double value, double *iptr);
extern double pow(double x, double y);
extern double sqrt(double x);
extern double cbrt(double x);
extern double ceil(double x);
extern double fabs(double x);
extern double floor(double x);
extern double fmod(double x, double y);
extern double rint(double x);
extern double hypot(double x, double y);
extern double cabs(struct complex);
extern int isinf(double value);
extern int isnan(double value);
extern int finite(double value);
extern double infnan(int error);
extern double copysign(double x, double y);
extern double scalb(double x, int n);
extern double drem(double x, double y);
extern double logb(double x);
extern double atof(const char *nptr);
extern int atoi(const char *nptr);
extern long atol(const char *nptr);
extern double strtod(const char *nptr, char **endptr);
extern long strtol(const char *nptr, char **endptr, int base);
extern int rand(void);
extern void srand(unsigned int seed);
extern long random(void);
extern void srandom(unsigned int seed);
extern void *initstate(unsigned int seed, void *statebuf, int n);
extern void *setstate(void *statebuf);
extern void *bsearch(const void *key, const void *base, size_t nel,
size_t size, int (*compar)(const void *, const void *));
extern int abs(int x);
extern long labs(long x);
extern div_t div(int numer, int denom);
extern ldiv_t ldiv(long numer, long denom);
/*
* time functions
*/
typedef unsigned long time_t;
struct tm
{
int tm_sec; /* Seconds. [0-61] (2 leap seconds) */
int tm_min; /* Minutes. [0-59] */
int tm_hour; /* Hours. [0-23] */
int tm_mday; /* Day. [1-31] */
int tm_mon; /* Month. [0-11] */
int tm_year; /* Year - 1900. */
int tm_wday; /* Day of week. [0-6] */
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/
};
extern struct tm *gmtime_r(const time_t *t, struct tm *tm);
extern struct tm *localtime_r(const time_t *t, struct tm *tm);
#ifdef __cplusplus
}
#endif
#endif /* __TV_libc_h_ */