libc.h 5.42 KB
#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_ */