From 7da93d58fdc73c40a721f9f1c7d7a42609e10a53 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 15 Jun 2002 15:49:32 +0000 Subject: This is my initial attempt to get rid of the newlib headers requirement, for gcc built without newlib. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1017 a1c6a512-1295-4272-9138-f99709370657 --- firmware/include/_ansi.h | 77 ++++++++++++++++++++++++++++++++++++ firmware/include/assert.h | 20 ++++++++++ firmware/include/ctype.h | 71 +++++++++++++++++++++++++++++++++ firmware/include/malloc.h | 26 ++++++++++++ firmware/include/math.h | 54 +++++++++++++++++++++++++ firmware/include/stdio.h | 41 +++++++++++++++++++ firmware/include/stdlib.h | 35 +++++++++++++++++ firmware/include/string.h | 94 ++++++++++++++++++++++++++++++++++++++++++++ firmware/include/sys/timeb.h | 39 ++++++++++++++++++ 9 files changed, 457 insertions(+) create mode 100644 firmware/include/_ansi.h create mode 100644 firmware/include/assert.h create mode 100644 firmware/include/ctype.h create mode 100644 firmware/include/malloc.h create mode 100644 firmware/include/math.h create mode 100644 firmware/include/stdio.h create mode 100644 firmware/include/stdlib.h create mode 100644 firmware/include/string.h create mode 100644 firmware/include/sys/timeb.h diff --git a/firmware/include/_ansi.h b/firmware/include/_ansi.h new file mode 100644 index 0000000000..8bebd1457e --- /dev/null +++ b/firmware/include/_ansi.h @@ -0,0 +1,77 @@ +/* Provide support for both ANSI and non-ANSI environments. */ + +/* Some ANSI environments are "broken" in the sense that __STDC__ cannot be + relied upon to have it's intended meaning. Therefore we must use our own + concoction: _HAVE_STDC. Always use _HAVE_STDC instead of __STDC__ in newlib + sources! + + To get a strict ANSI C environment, define macro __STRICT_ANSI__. This will + "comment out" the non-ANSI parts of the ANSI header files (non-ANSI header + files aren't affected). */ + +#ifndef _ANSIDECL_H_ +#define _ANSIDECL_H_ + +#include + +/* First try to figure out whether we really are in an ANSI C environment. */ +/* FIXME: This probably needs some work. Perhaps sys/config.h can be + prevailed upon to give us a clue. */ + +#ifdef __STDC__ +#define _HAVE_STDC +#endif + +#ifdef _HAVE_STDC +#define _PTR void * +#define _AND , +#define _NOARGS void +#define _CONST const +#define _VOLATILE volatile +#define _SIGNED signed +#define _DOTS , ... +#define _VOID void +#ifdef __CYGWIN__ +#define _EXFUN(name, proto) __cdecl name proto +#define _EXPARM(name, proto) (* __cdecl name) proto +#else +#define _EXFUN(name, proto) name proto +#define _EXPARM(name, proto) (* name) proto +#endif +#define _DEFUN(name, arglist, args) name(args) +#define _DEFUN_VOID(name) name(_NOARGS) +#define _CAST_VOID (void) +#ifndef _LONG_DOUBLE +#define _LONG_DOUBLE long double +#endif +#ifndef _PARAMS +#define _PARAMS(paramlist) paramlist +#endif +#else +#define _PTR char * +#define _AND ; +#define _NOARGS +#define _CONST +#define _VOLATILE +#define _SIGNED +#define _DOTS +#define _VOID void +#define _EXFUN(name, proto) name() +#define _DEFUN(name, arglist, args) name arglist args; +#define _DEFUN_VOID(name) name() +#define _CAST_VOID +#define _LONG_DOUBLE double +#ifndef _PARAMS +#define _PARAMS(paramlist) () +#endif +#endif + +/* Support gcc's __attribute__ facility. */ + +#ifdef __GNUC__ +#define _ATTRIBUTE(attrs) __attribute__ (attrs) +#else +#define _ATTRIBUTE(attrs) +#endif + +#endif /* _ANSIDECL_H_ */ diff --git a/firmware/include/assert.h b/firmware/include/assert.h new file mode 100644 index 0000000000..ba22a9777b --- /dev/null +++ b/firmware/include/assert.h @@ -0,0 +1,20 @@ +/* + assert.h +*/ + +#undef assert + +#ifdef NDEBUG /* required by ANSI standard */ +#define assert(p) ((void)0) +#else + +#ifdef __STDC__ +#define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, #e)) +#else /* PCC */ +#define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, "e")) +#endif + +#endif /* NDEBUG */ + +void _EXFUN(__assert,(const char *, int, const char *)); + diff --git a/firmware/include/ctype.h b/firmware/include/ctype.h new file mode 100644 index 0000000000..18dd02f707 --- /dev/null +++ b/firmware/include/ctype.h @@ -0,0 +1,71 @@ +#ifndef _CTYPE_H_ +#ifdef __cplusplus +extern "C" { +#endif +#define _CTYPE_H_ + +#include "_ansi.h" + +int _EXFUN(isalnum, (int __c)); +int _EXFUN(isalpha, (int __c)); +int _EXFUN(iscntrl, (int __c)); +int _EXFUN(isdigit, (int __c)); +int _EXFUN(isgraph, (int __c)); +int _EXFUN(islower, (int __c)); +int _EXFUN(isprint, (int __c)); +int _EXFUN(ispunct, (int __c)); +int _EXFUN(isspace, (int __c)); +int _EXFUN(isupper, (int __c)); +int _EXFUN(isxdigit,(int __c)); +int _EXFUN(tolower, (int __c)); +int _EXFUN(toupper, (int __c)); + +#ifndef __STRICT_ANSI__ +int _EXFUN(isascii, (int __c)); +int _EXFUN(toascii, (int __c)); +int _EXFUN(_tolower, (int __c)); +int _EXFUN(_toupper, (int __c)); +#endif + +#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 __IMPORT _CONST char _ctype_[]; + +#ifndef __cplusplus +#define isalpha(c) ((_ctype_+1)[(unsigned)(c)]&(_U|_L)) +#define isupper(c) ((_ctype_+1)[(unsigned)(c)]&_U) +#define islower(c) ((_ctype_+1)[(unsigned)(c)]&_L) +#define isdigit(c) ((_ctype_+1)[(unsigned)(c)]&_N) +#define isxdigit(c) ((_ctype_+1)[(unsigned)(c)]&(_X|_N)) +#define isspace(c) ((_ctype_+1)[(unsigned)(c)]&_S) +#define ispunct(c) ((_ctype_+1)[(unsigned)(c)]&_P) +#define isalnum(c) ((_ctype_+1)[(unsigned)(c)]&(_U|_L|_N)) +#define isprint(c) ((_ctype_+1)[(unsigned)(c)]&(_P|_U|_L|_N|_B)) +#define isgraph(c) ((_ctype_+1)[(unsigned)(c)]&(_P|_U|_L|_N)) +#define iscntrl(c) ((_ctype_+1)[(unsigned)(c)]&_C) +/* Non-gcc versions will get the library versions, and will be + slightly slower */ +#ifdef __GNUC__ +# define toupper(c) \ + __extension__ ({ int __x = (c); islower(__x) ? (__x - 'a' + 'A') : __x;}) +# define tolower(c) \ + __extension__ ({ int __x = (c); isupper(__x) ? (__x - 'A' + 'a') : __x;}) +#endif +#endif /* !__cplusplus */ + +#ifndef __STRICT_ANSI__ +#define isascii(c) ((unsigned)(c)<=0177) +#define toascii(c) ((c)&0177) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _CTYPE_H_ */ diff --git a/firmware/include/malloc.h b/firmware/include/malloc.h new file mode 100644 index 0000000000..639675787a --- /dev/null +++ b/firmware/include/malloc.h @@ -0,0 +1,26 @@ +/* malloc.h -- header file for memory routines. */ + +#ifndef _INCLUDE_MALLOC_H_ +#define _INCLUDE_MALLOC_H_ + +#include <_ansi.h> + +#define __need_size_t +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* The routines. */ + +extern _PTR malloc _PARAMS ((size_t)); +extern _VOID free _PARAMS ((_PTR)); +extern _PTR realloc _PARAMS ((_PTR, size_t)); +extern _PTR calloc _PARAMS ((size_t, size_t)); + +#ifdef __cplusplus +} +#endif + +#endif /* _INCLUDE_MALLOC_H_ */ diff --git a/firmware/include/math.h b/firmware/include/math.h new file mode 100644 index 0000000000..d4b6715b3b --- /dev/null +++ b/firmware/include/math.h @@ -0,0 +1,54 @@ +/* math.h -- Definitions for the math floating point package. */ + +#ifndef _MATH_H_ +#ifdef __cplusplus +extern "C" { +#endif +#define _MATH_H_ + +#include "_ansi.h" + +#ifndef __STRICT_ANSI__ + +#define __signgam_r(ptr) ((ptr)->_new._reent._gamma_signgam) + +/* Values for the type field of struct exception. */ + +#define DOMAIN 1 +#define SING 2 +#define OVERFLOW 3 +#define UNDERFLOW 4 +#define TLOSS 5 +#define PLOSS 6 + +/* Useful constants. */ + +#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_TWOPI (M_PI * 2.0) +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_3PI_4 2.3561944901923448370E0 +#define M_SQRTPI 1.77245385090551602792981 +#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 M_LN2LO 1.9082149292705877000E-10 +#define M_LN2HI 6.9314718036912381649E-1 +#define M_SQRT3 1.73205080756887719000 +#define M_IVLN10 0.43429448190325182765 /* 1 / log(10) */ +#define M_LOG2_E 0.693147180559945309417 +#define M_INVLN2 1.4426950408889633870E0 /* 1 / log(2) */ + +#endif /* ! defined (__STRICT_ANSI__) */ + +#ifdef __cplusplus +} +#endif +#endif /* _MATH_H_ */ diff --git a/firmware/include/stdio.h b/firmware/include/stdio.h new file mode 100644 index 0000000000..e8d35bc502 --- /dev/null +++ b/firmware/include/stdio.h @@ -0,0 +1,41 @@ +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#define __need_size_t +#include + +#define __need___va_list +#include + +#ifndef NULL +#define NULL 0 +#endif + +#define EOF (-1) + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#define TMP_MAX 26 + +#ifdef __GNUC__ +#define __VALIST __gnuc_va_list +#else +#define __VALIST char* +#endif + +int _EXFUN(fprintf, (FILE *, const char *, ...)); +int _EXFUN(fscanf, (FILE *, const char *, ...)); +int _EXFUN(printf, (const char *, ...)); +int _EXFUN(vfprintf, (FILE *, const char *, __VALIST)); +int _EXFUN(vprintf, (const char *, __VALIST)); +int _EXFUN(vsprintf, (char *, const char *, __VALIST)); + +#endif /* _STDIO_H_ */ diff --git a/firmware/include/stdlib.h b/firmware/include/stdlib.h new file mode 100644 index 0000000000..ab07a3116e --- /dev/null +++ b/firmware/include/stdlib.h @@ -0,0 +1,35 @@ +/* + * stdlib.h + * + * Definitions for common types, variables, and functions. + */ + +#ifndef _STDLIB_H_ +#ifdef __cplusplus +extern "C" { +#endif +#define _STDLIB_H_ + +#include "_ansi.h" + +#define __need_size_t +#define __need_wchar_t +#include + +#ifndef NULL +#define NULL 0 +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +extern __IMPORT int __mb_cur_max; + +#define MB_CUR_MAX __mb_cur_max + +_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, int(*_compar)(const _PTR, const _PTR))); + +#ifdef __cplusplus +} +#endif +#endif /* _STDLIB_H_ */ diff --git a/firmware/include/string.h b/firmware/include/string.h new file mode 100644 index 0000000000..e85dac33ea --- /dev/null +++ b/firmware/include/string.h @@ -0,0 +1,94 @@ +/* + * string.h + * + * Definitions for memory and string functions. + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "_ansi.h" +#include + +#define __need_size_t +#include + +#ifndef NULL +#define NULL 0 +#endif + +_PTR _EXFUN(memchr,(const _PTR, int, size_t)); +int _EXFUN(memcmp,(const _PTR, const _PTR, size_t)); +_PTR _EXFUN(memcpy,(_PTR, const _PTR, size_t)); +_PTR _EXFUN(memmove,(_PTR, const _PTR, size_t)); +_PTR _EXFUN(memset,(_PTR, int, size_t)); +char *_EXFUN(strcat,(char *, const char *)); +char *_EXFUN(strchr,(const char *, int)); +int _EXFUN(strcmp,(const char *, const char *)); +int _EXFUN(strcoll,(const char *, const char *)); +char *_EXFUN(strcpy,(char *, const char *)); +size_t _EXFUN(strcspn,(const char *, const char *)); +char *_EXFUN(strerror,(int)); +size_t _EXFUN(strlen,(const char *)); +char *_EXFUN(strncat,(char *, const char *, size_t)); +int _EXFUN(strncmp,(const char *, const char *, size_t)); +char *_EXFUN(strncpy,(char *, const char *, size_t)); +char *_EXFUN(strpbrk,(const char *, const char *)); +char *_EXFUN(strrchr,(const char *, int)); +size_t _EXFUN(strspn,(const char *, const char *)); +char *_EXFUN(strstr,(const char *, const char *)); + +#ifndef _REENT_ONLY +char *_EXFUN(strtok,(char *, const char *)); +#endif + +size_t _EXFUN(strxfrm,(char *, const char *, size_t)); + +#ifndef __STRICT_ANSI__ +char *_EXFUN(strtok_r,(char *, const char *, char **)); + +int _EXFUN(bcmp,(const char *, const char *, size_t)); +void _EXFUN(bcopy,(const char *, char *, size_t)); +void _EXFUN(bzero,(char *, size_t)); +int _EXFUN(ffs,(int)); +char *_EXFUN(index,(const char *, int)); +_PTR _EXFUN(memccpy,(_PTR, const _PTR, int, size_t)); +char *_EXFUN(rindex,(const char *, int)); +int _EXFUN(strcasecmp,(const char *, const char *)); +char *_EXFUN(strdup,(const char *)); +char *_EXFUN(_strdup_r,(struct _reent *, const char *)); +int _EXFUN(strncasecmp,(const char *, const char *, size_t)); +char *_EXFUN(strsep,(char **, const char *)); +char *_EXFUN(strlwr,(char *)); +char *_EXFUN(strupr,(char *)); +#ifdef __CYGWIN__ +#ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ +const char *_EXFUN(strsignal, (int __signo)); +#endif +int _EXFUN(strtosigno, (const char *__name)); +#endif + +/* These function names are used on Windows and perhaps other systems. */ +#ifndef strcmpi +#define strcmpi strcasecmp +#endif +#ifndef stricmp +#define stricmp strcasecmp +#endif +#ifndef strncmpi +#define strncmpi strncasecmp +#endif +#ifndef strnicmp +#define strnicmp strncasecmp +#endif + +#endif /* ! __STRICT_ANSI__ */ + +#ifdef __cplusplus +} +#endif +#endif /* _STRING_H_ */ diff --git a/firmware/include/sys/timeb.h b/firmware/include/sys/timeb.h new file mode 100644 index 0000000000..0a2c3de8bd --- /dev/null +++ b/firmware/include/sys/timeb.h @@ -0,0 +1,39 @@ +/* timeb.h -- An implementation of the standard Unix file. + Written by Ian Lance Taylor + Public domain; no rights reserved. + + declares the structure used by the ftime function, as + well as the ftime function itself. Newlib does not provide an + implementation of ftime. */ + +#ifndef _SYS_TIMEB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define _SYS_TIMEB_H + +#include <_ansi.h> +#include + +#ifndef __time_t_defined +typedef _TIME_T_ time_t; +#define __time_t_defined +#endif + +struct timeb +{ + time_t time; + unsigned short millitm; + short timezone; + short dstflag; +}; + +extern int ftime _PARAMS ((struct timeb *)); + +#ifdef __cplusplus +} +#endif + +#endif /* ! defined (_SYS_TIMEB_H) */ -- cgit v1.2.3