From 2150d97e49066289b59dc53a31728cd4ba369e55 Mon Sep 17 00:00:00 2001 From: bebbo Date: Sun, 29 Sep 2024 20:33:15 +0200 Subject: [PATCH] more pointer->value stuff to support libraries --- Makefile | 12 +- sys-include/limits.h | 1 + sys-include/machine/_default_types.h | 2 +- sys-include/stabs.h | 26 +- sys-include/stdio.h | 1021 +++++++++++++++++++------- sys-include/string.h | 235 ++++-- sys-include/sys/_default_fcntl.h | 4 + sys-include/sys/errno.h | 7 +- sys-include/sys/reent.h | 853 ++++++++++++++++++++- sys-include/time.h | 45 +- 10 files changed, 1839 insertions(+), 367 deletions(-) diff --git a/Makefile b/Makefile index 83bd5c0..5cebd33 100644 --- a/Makefile +++ b/Makefile @@ -179,10 +179,10 @@ help: # ================================================= # all # ================================================= -.PHONY: all gcc gdb gprof binutils fd2sfd fd2pragma ira sfdc vasm libnix ixemul libgcc clib2 libdebug libpthread ndk ndk13 min -all: gcc binutils gdb gprof fd2sfd fd2pragma ira sfdc vasm libnix ixemul libgcc clib2 libdebug libpthread ndk ndk13 libSDL12 $(BUILD)/libnix/libb/libnix4.library +.PHONY: all gcc gdb gprof binutils fd2sfd fd2pragma ira sfdc vasm libnix ixemul libgcc clib2 libdebug libpthread ndk ndk13 min libnix4.library +all: gcc binutils gdb gprof fd2sfd fd2pragma ira sfdc vasm libnix ixemul libgcc clib2 libdebug libpthread ndk ndk13 libSDL12 libnix4.library -min: binutils gcc gprof libnix libgcc $(BUILD)/libnix/libb/libnix4.library +min: binutils gcc gprof libnix libgcc libnix4.library # ================================================= # clean @@ -876,7 +876,8 @@ LIBNIX_SRC = $(shell find 2>/dev/null $(PROJECTS)/libnix -not \( -path $(PROJECT libnix: $(BUILD)/libnix/_done -$(BUILD)/libnix/_done: $(BUILD)/newlib/_done $(BUILD)/ndk-include_ndk $(BUILD)/ndk-include_ndk13 $(BUILD)/_netinclude $(BUILD)/binutils/_done $(BUILD)/gcc/_done $(PROJECTS)/libnix/Makefile.gcc6 $(LIBAMIGA) $(LIBNIX_SRC) +$(BUILD)/libnix/_done: $(BUILD)/ndk-include_ndk $(BUILD)/ndk-include_ndk13 $(BUILD)/_netinclude $(BUILD)/binutils/_done $(BUILD)/gcc/_done $(PROJECTS)/libnix/Makefile.gcc6 $(LIBAMIGA) $(LIBNIX_SRC) + @rsync -a --no-group --delete sys-include/ $(PREFIX)/$(TARGET)/sys-include @mkdir -p $(PREFIX)/$(TARGET)/libnix/lib/libnix @mkdir -p $(BUILD)/libnix @mkdir -p $(PREFIX)/lib/gcc/$(TARGET)/$(GCC_VERSION) @@ -905,7 +906,8 @@ $(BUILD)/gcc/_libgcc_done: $(BUILD)/libnix/_done $(BUILD)/libpthread/_done $(LIB # ================================================= # libnix4.library # ================================================= -$(BUILD)/libnix/libb/libnix4.library: $(BUILD)/gcc/_libgcc_done +libnix4.library: $(BUILD)/libnix/libb/libnix4.library +$(BUILD)/libnix/libb/libnix4.library: $(BUILD)/gcc/_libgcc_done $(BUILD)/libnix/_done $(L0)"make libnix4.library"$(L1) CFLAGS="$(CFLAGS_FOR_TARGET)" \ $(MAKE) -C $(BUILD)/libnix -f $(PROJECTS)/libnix/Makefile.gcc6 root=$(PROJECTS)/libnix libb/libnix4.library $(L2) diff --git a/sys-include/limits.h b/sys-include/limits.h index 00a1e9c..1ae72ae 100644 --- a/sys-include/limits.h +++ b/sys-include/limits.h @@ -3,6 +3,7 @@ #include #include +#include # ifdef _MB_LEN_MAX # define MB_LEN_MAX _MB_LEN_MAX diff --git a/sys-include/machine/_default_types.h b/sys-include/machine/_default_types.h index 7ad5d2e..8c5770d 100644 --- a/sys-include/machine/_default_types.h +++ b/sys-include/machine/_default_types.h @@ -62,7 +62,7 @@ typedef unsigned __INT8_TYPE__ __uint8_t; #endif #define ___int8_t_defined 1 #elif __EXP(SCHAR_MAX) == 0x7f -typedef char __int8_t ; +typedef signed char __int8_t ; typedef unsigned char __uint8_t ; #define ___int8_t_defined 1 #endif diff --git a/sys-include/stabs.h b/sys-include/stabs.h index 3356686..f54912f 100644 --- a/sys-include/stabs.h +++ b/sys-include/stabs.h @@ -1,16 +1,26 @@ #ifndef _HEADERS_STABS_H #define _HEADERS_STABS_H -#if defined(__m68k_elf__) || defined(__ELF__) +#if defined(__m68k_elf__) || defined(__ELF__) || (defined(__near) && defined(__chip) && defined(__fast)) + +#define __PASTE(a,b) a##b -/* add symbol a to list b (c unused) */ #define ADD2LIST(a,b,c) \ - asm(".section\t.list_" #b ",\"aw\""); \ - asm("\t.long _" #a); + __PASTE(ADD2LIST,c)(_##a,b) #define ADD2LIST2(a,b,c) \ + __PASTE(ADD2LIST,c)(a,b) + +/* add symbol a to list b */ +#define ADD2LIST22(a,b) \ asm(".section\t.list_" #b ",\"aw\""); \ - asm("\t.long " #a); + asm("\t.long " #a); \ + asm(".text"); + +#define ADD2LIST24(a,b) \ + asm(".section\t.dlist_" #b ",\"aw\""); \ + asm("\t.long " #a); \ + asm(".text"); /* Install private constructors and destructors pri MUST be -127<=pri<=127 */ #define ADD2INIT(a,pri) ADD2LIST(a,__INIT_LIST__,22); \ @@ -18,6 +28,8 @@ #define ADD2EXIT(a,pri) ADD2LIST(a,__EXIT_LIST__,22); \ ADD2LIST2(pri+128,__EXIT_LIST__,22) +#define ADDTABL_END() ADD2LIST2(-1,__FuncTable__,22) + #else /* add symbol a to list b (type c (22=text 24=data 26=bss)) */ #define ADD2LIST(a,b,c) asm(".stabs \"_" #b "\"," #c ",0,0,_" #a ) @@ -28,6 +40,8 @@ #define ADD2EXIT(a,pri) ADD2LIST(a,__EXIT_LIST__,22); \ asm(".stabs \"___EXIT_LIST__\",20,0,0," #pri "+128") +#define ADDTABL_END() asm(".stabs \"___FuncTable__\",20,0,0,-1") + #endif /* These are some macros for handling of symboltable information @@ -118,6 +132,6 @@ _ADDTABL_ARG(arg1); \ _ADDTABL_CALL(name); \ _ADDTABL_ENDN(name,4) -#define ADDTABL_END() asm(".stabs \"___FuncTable__\",20,0,0,-1") + #endif /* _HEADERS_STABS_H */ diff --git a/sys-include/stdio.h b/sys-include/stdio.h index 1136dd7..5263c6b 100644 --- a/sys-include/stdio.h +++ b/sys-include/stdio.h @@ -1,289 +1,133 @@ -#ifndef _STDIO_H -#define _STDIO_H -#include -#include - -/* Adjusted to be compatible with the bsd headers - * (At least for normal ANSI stuff) - * Member names are not the same, but they need not be :-) +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#)stdio.h 5.3 (Berkeley) 3/15/86 */ -typedef long fpos_t; - -#ifndef __SFILE_DEFINED__ -#define __SFILE_DEFINED__ - /* - * Stdio buffers. - * - * This and __FILE are defined here because we need them for struct _reent, - * but we don't want stdio.h included when stdlib.h is. + * NB: to fit things in six character monocase externals, the + * stdio code uses the prefix `__s' for stdio objects, typically + * followed by a three-character attempt at a mnemonic. */ -struct __sbuf { - unsigned char *_base; - int _size; -}; +#ifndef _STDIO_H_ +#define _STDIO_H_ -struct __sFILE { - unsigned char *_p; /* pointer to actual character */ - int _r; /* Bytes left in buffer for reading, writemode: 0 */ - int _w; /* Space left in buffer for writing + fp->linebufsize, - * readmode: 0 - */ - short _flags; -#define __SLBF 0x0001 /* line buffered */ -#define __SNBF 0x0002 /* unbuffered */ -#define __SRD 0x0004 /* read mode */ -#define __SWR 0x0008 /* write mode */ -#define __SRW 0x0010 /* read and write allowed */ -#define __SEOF 0x0020 /* EOF read */ -#define __SERR 0x0040 /* error encountered */ -#define __SMBF 0x0080 /* buffer malloc'ed by library */ -#define __SSTR 0x0200 /* sprintf/sscanf buffer */ -#define __SWO 0x8000 /* write-only mode */ +#include "_ansi.h" +#define _FSTDIO /* ``function stdio'' */ -#define __BPTRS 0x4000 /* tmpdir and name are BPTRS. */ +#define __need_size_t +#define __need_NULL +#include +#include - short file; /* The filehandle */ - struct __sbuf _bf; -// unsigned char *buffer; /* original buffer pointer */ -// int bufsize; /* size of the buffer */ - int linebufsize; /* 0 full buffered - * -bufsize line buffered&write mode - * readmode: undefined */ - /* from this point on not binary compatible to bsd headers */ - unsigned char unget[4]; /* ungetc buffer 4 bytes necessary (for -Na*) - * ANSI requires 3 bytes (for -.*), so one more - * doesn't matter - */ - unsigned char *tmpp; /* Stored p if ungetc pending, otherwise NULL */ - int tmpinc; /* Stored incount if ungetc pending, otherwise undefined */ - long tmpdir; /* lock to directory if temporary file */ - char *name; /* filename if temporary file */ -#ifdef __posix_threads__ - unsigned __spinlock[2]; +/* typedef only __gnuc_va_list, used throughout the header */ +#define __need___va_list +#include + +/* typedef va_list only when required */ +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE +#ifdef __GNUC__ +#ifndef _VA_LIST_DEFINED +typedef __gnuc_va_list va_list; +#define _VA_LIST_DEFINED #endif -}; - -#ifdef __posix_threads__ -extern void __regargs __spinLock(unsigned * l); -inline void __regargs __spinUnlock(unsigned * l) { - if (--l[1] == 0) - *l = 0; -} -#define __STDIO_LOCK(l) __spinLock(l->__spinlock) -#define __STDIO_UNLOCK(l) __spinUnlock(l->__spinlock) -#else -#define __spinLock(a) -#define __spinUnlock(a) -#define __STDIO_LOCK(l) -#define __STDIO_UNLOCK(l) +#else /* !__GNUC__ */ +#include #endif +#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ + +/* + * defines __FILE, _fpos_t. + * They must be defined there because struct _reent needs them (and we don't + * want reent.h to include this file. + */ + +#include +#include + +_BEGIN_STD_C #if !defined(__FILE_defined) -typedef struct __sFILE __FILE; typedef __FILE FILE; # define __FILE_defined #endif -#endif -#ifndef NULL -#define NULL ((void *)0l) -#endif -#define BUFSIZ 1024 -#define EOF (-1) -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#define _IOFBF 0 -#define _IOLBF 1 -#define _IONBF 2 - -extern __stdargs FILE *fopen(const char *filename, const char *mode); -extern __stdargs FILE *freopen(const char *filename, const char *mode, FILE *stream); -extern __stdargs FILE *fdopen(int filedes, const char *mode); -extern __stdargs int fclose(FILE *stream); -extern __stdargs int ungetc(int c, FILE *stream); -extern __stdargs int vsprintf(char *s, const char *format, va_list args); -extern __stdargs int vfprintf(FILE *stream, const char *format, va_list args); -extern __stdargs int vsscanf(const char *s, const char *format, va_list args); -extern __stdargs int vfscanf(FILE *stream, const char *format, va_list args); -extern __stdargs int vsnprintf(char *s, size_t size, const char *format, va_list args); -extern __stdargs int fseek(FILE *stream, long int offset, int whence); -extern __stdargs char *fgets(char *s, int size, FILE *stream); -extern __stdargs int fputs(const char *s, FILE *stream); -extern __stdargs long ftell(FILE *stream); -extern __stdargs int setvbuf(FILE *stream, char *buf, int mode, size_t size); -extern __stdargs size_t fread(void *, size_t, size_t, FILE *); -extern __stdargs size_t fwrite(const void *, size_t, size_t, FILE *); -extern __stdargs char *tmpnam(char *buf); -extern __stdargs void perror(const char *string); -extern __stdargs int puts(const char *s); -extern __stdargs int remove(const char *filename); -extern __stdargs int rename(const char *old, const char *neww); -extern __stdargs FILE *tmpfile(void); - -/* More bsd headers compatibility */ - -extern __stdargs int __swbuf(int c, FILE *stream); -extern __stdargs int __srget(FILE *stream); -extern FILE **__sF; /* Standard I/O streams */ -#define stdin (__sF[0]) /* Other streams are not in __sF */ -#define stdout (__sF[1]) -#define stderr (__sF[2]) - -extern __stdargs int fprintf(FILE *stream, const char *format, ...); -extern __stdargs int fscanf(FILE *stream, const char *format, ...); -extern __stdargs int printf(const char *format, ...); -extern __stdargs int scanf(const char *format, ...); -extern __stdargs int sscanf(const char *s, const char *format, ...); -extern __stdargs int snprintf(char *s, size_t size, const char *format, ...); -extern __stdargs int sprintf(char *s, const char *format, ...); - -extern __stdargs int asprintf(char **__restrict strp, const char *__restrict fmt, ...); - -extern __stdargs int getc(FILE *fp); -extern __stdargs int putc(int c, FILE * fp); - -extern __stdargs FILE *popen(const char *command, const char *type); -extern __stdargs int pclose(FILE *stream); - -/* Inline functions or protos. */ -#ifdef __NO_INLINE__ -extern __stdargs void clearerr(FILE *stream); -extern __stdargs int feof(FILE * fp); -extern __stdargs int ferror(FILE *fp); -extern __stdargs int fgetc(FILE *stream); -extern __stdargs int fgetpos(FILE *stream, fpos_t *pos); -extern __stdargs int fileno(FILE *file); -extern __stdargs int fputc(int c, FILE *stream); -extern __stdargs int fsetpos(FILE *stream, fpos_t *pos); -extern __stdargs int getchar(); -extern __stdargs char *gets(char *s); -extern __stdargs int vprintf(const char *format, va_list args); -extern __stdargs int putchar(int c); -extern __stdargs int vscanf(const char *format, va_list args); -extern __stdargs void rewind(FILE *stream); -extern __stdargs int setbuf(FILE *stream, char *buf); +#ifdef __CYGWIN__ +typedef _fpos64_t fpos_t; #else - -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -#define __MY_INLINE__ static inline -#else -#define __MY_INLINE__ extern inline +typedef _fpos_t fpos_t; +#ifdef __LARGE64_FILES +typedef _fpos64_t fpos64_t; #endif +#endif /* !__CYGWIN__ */ -__MY_INLINE__ __stdargs void clearerr(FILE *stream) -{ stream->_flags&=~(__SERR|__SEOF);} +#include -__MY_INLINE__ __stdargs int feof(FILE * fp) -{ return ((fp)->_flags&__SEOF);} - -__MY_INLINE__ __stdargs int ferror(FILE *fp) -{ return ((fp)->_flags&__SERR);} - -__MY_INLINE__ __stdargs int fgetc(FILE *stream) -{ return getc(stream);} - -__MY_INLINE__ __stdargs int fgetpos(FILE *stream,fpos_t *pos) -{ *pos=ftell(stream); return 0;} - -__MY_INLINE__ __stdargs int fileno(FILE *file) -{ return file->file;} - -__MY_INLINE__ __stdargs int fputc(int c,FILE *stream) -{ return putc(c,stream);} - -__MY_INLINE__ __stdargs int fsetpos(FILE *stream,fpos_t *pos) -{ return fseek(stream,*pos,SEEK_SET);} - -__MY_INLINE__ __stdargs int getchar() -{ return getc(stdin);} - -__MY_INLINE__ __stdargs char *gets(char *s) -{ return fgets(s, 0, stdin);} - -__MY_INLINE__ __stdargs int vprintf(const char *format,va_list args) -{ return vfprintf(stdout,format,args);} - -__MY_INLINE__ __stdargs int putchar(int c) -{ return putc(c, stdout);} - -__MY_INLINE__ __stdargs int vscanf(const char *format,va_list args) -{ return vfscanf(stdin,format,args);} - -__MY_INLINE__ __stdargs void rewind(FILE *stream) -{ fseek(stream,0,SEEK_SET);} - -__MY_INLINE__ __stdargs int setbuf(FILE *stream,char *buf) -{ return setvbuf(stream,buf,buf?_IOFBF:_IONBF,BUFSIZ);} +#define __SLBF 0x0001 /* line buffered */ +#define __SNBF 0x0002 /* unbuffered */ +#define __SRD 0x0004 /* OK to read */ +#define __SWR 0x0008 /* OK to write */ + /* RD and WR are never simultaneously asserted */ +#define __SRW 0x0010 /* open for reading & writing */ +#define __SEOF 0x0020 /* found EOF */ +#define __SERR 0x0040 /* found error */ +#define __SMBF 0x0080 /* _buf is from malloc */ +#define __SAPP 0x0100 /* fdopen()ed in append mode - so must write to end */ +#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ +#define __SOPT 0x0400 /* do fseek() optimisation */ +#define __SNPT 0x0800 /* do not do fseek() optimisation */ +#define __SOFF 0x1000 /* set iff _offset is in fact correct */ +#define __SORD 0x2000 /* true => stream orientation (byte/wide) decided */ +#if defined(__CYGWIN__) +# define __SCLE 0x4000 /* convert line endings CR/LF <-> NL */ #endif +#define __SL64 0x8000 /* is 64-bit offset large file */ -/* own stuff */ -extern struct MinList __filelist; /* List of all fopen'ed files */ -extern struct MinList __memorylist; /* List of memory puddles */ - -extern __stdargs int fflush(FILE *stream); /* fflush single file */ -extern __stdargs void __chkabort(void); /* check for SIGABRT */ +/* _flags2 flags */ +#define __SNLK 0x0001 /* stdio functions do not lock streams themselves */ +#define __SWID 0x2000 /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */ /* - ** FILE/SOCKET abstraction layer + * The following three definitions are for ANSI C, which took them + * from System V, which stupidly took internal interface macros and + * made them official arguments to setvbuf(), without renaming them. + * Hence, these ugly _IOxxx names are *supposed* to appear in user code. + * + * Although these happen to match their counterparts above, the + * implementation does not rely on that (so these could be renumbered). */ +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ -struct stat; -struct StandardPacket; +#define EOF (-1) -#define LX_FILE 0x01 -#define LX_SOCKET 0x80 -#define LX_SYS 0x04 -#define LX_ATTY 0x02 - -struct _StdFileDes; -struct _StdFileFx { - ssize_t __stdargs (*lx_read)(struct _StdFileDes *, void *, size_t); - ssize_t __stdargs (*lx_write)(struct _StdFileDes *, const void *, size_t); - int __stdargs (*lx_close)(struct _StdFileDes *); - int __stdargs (*lx_dup)(struct _StdFileDes *); - int __stdargs (*lx_fstat)(struct _StdFileDes *, struct stat *); - int __stdargs (*lx_select)(struct _StdFileDes *sfd, int select_cmd, int io_mode, struct fd_set *, unsigned long *); -}; - -typedef struct _StdFileDes { - unsigned short lx_pos; /* __stdfiledes[lx_pos]; */ - unsigned char lx_flags; /* LX_FILE, LX_SOCKET, LX_ATTY, LX_SYS*/ - unsigned char lx_inuse; /* use counter */ -#if __STDC_VERSION__ >= 199901L - union { - struct { - int lx_fh; - int lx_oflags; - struct StandardPacket *lx_packet; - }; - struct { - int lx_sock; - int lx_family; - int lx_protocol; - int lx_domain; - }; - }; +#ifdef __BUFSIZ__ +#define BUFSIZ __BUFSIZ__ #else - int lx_fh; - int lx_oflags; - struct StandardPacket *lx_packet; - int lx_domain; -#define lx_sock lx_fh -#define lx_family lx_oflags -#define lx_protocol lx_packet +#define BUFSIZ 1024 #endif - struct _StdFileFx * lx_fx; -} StdFileDes; - -extern __stdargs StdFileDes *_lx_fhfromfd(int fd); - -#define L_tmpnam 8 +#ifdef __FOPEN_MAX__ +#define FOPEN_MAX __FOPEN_MAX__ +#else +#define FOPEN_MAX 20 +#endif #ifdef __FILENAME_MAX__ #define FILENAME_MAX __FILENAME_MAX__ @@ -291,4 +135,669 @@ extern __stdargs StdFileDes *_lx_fhfromfd(int fd); #define FILENAME_MAX 1024 #endif -#endif /* _STDIO_H */ +#ifdef __L_tmpnam__ +#define L_tmpnam __L_tmpnam__ +#else +#define L_tmpnam FILENAME_MAX +#endif + +#if __BSD_VISIBLE || __XSI_VISIBLE +#define P_tmpdir "T:" +#endif + +#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 + +#define stdin (_REENT->_stdin) +#define stdout (_REENT->_stdout) +#define stderr (_REENT->_stderr) + +#define _stdin_r(x) ((x)->_stdin) +#define _stdout_r(x) ((x)->_stdout) +#define _stderr_r(x) ((x)->_stderr) + +/* + * Functions defined in ANSI C standard. + */ + +#ifndef __VALIST +#ifdef __GNUC__ +#define __VALIST __gnuc_va_list +#else +#define __VALIST char* +#endif +#endif + +#if __POSIX_VISIBLE +__stdargs char * ctermid (char *); +#endif +#if __XSI_VISIBLE && __XSI_VISIBLE < 600 +__stdargs char * cuserid (char *); +#endif +__stdargs FILE * tmpfile (void); +__stdargs char * tmpnam (char *); +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +__stdargs char * tempnam (const char *, const char *); +#endif +__stdargs int fclose (FILE *); +__stdargs int fflush (FILE *); +__stdargs FILE * freopen (const char *__restrict, const char *__restrict, FILE *__restrict); +__stdargs void setbuf (FILE *__restrict, char *__restrict); +__stdargs int setvbuf (FILE *__restrict, char *__restrict, int, size_t); +__stdargs int fprintf (FILE *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int fscanf (FILE *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__scanf__, 2, 3))); +__stdargs int printf (const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 1, 2))); +__stdargs int scanf (const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__scanf__, 1, 2))); +__stdargs int sscanf (const char *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__scanf__, 2, 3))); +__stdargs int vfprintf (FILE *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int vprintf (const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 1, 0))); +__stdargs int vsprintf (char *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int fgetc (FILE *); +__stdargs char * fgets (char *__restrict, int, FILE *__restrict); +__stdargs int fputc (int, FILE *); +__stdargs int fputs (const char *__restrict, FILE *__restrict); +__stdargs int getc (FILE *); +__stdargs int getchar (void); +__stdargs char * gets (char *); +__stdargs int putc (int, FILE *); +__stdargs int putchar (int); +__stdargs int puts (const char *); +__stdargs int ungetc (int, FILE *); +__stdargs size_t fread (void *__restrict, size_t _size, size_t _n, FILE *__restrict); +__stdargs size_t fwrite (const void *__restrict , size_t _size, size_t _n, FILE *); +#ifdef _COMPILING_NEWLIB +__stdargs int fgetpos (FILE *, _fpos_t *); +#else +__stdargs int fgetpos (FILE *__restrict, fpos_t *__restrict); +#endif +__stdargs int fseek (FILE *, long, int); +#ifdef _COMPILING_NEWLIB +__stdargs int fsetpos (FILE *, const _fpos_t *); +#else +__stdargs int fsetpos (FILE *, const fpos_t *); +#endif +__stdargs long ftell ( FILE *); +__stdargs void rewind (FILE *); +__stdargs void clearerr (FILE *); +__stdargs int feof (FILE *); +__stdargs int ferror (FILE *); +__stdargs void perror (const char *); +#ifndef _REENT_ONLY +__stdargs FILE * fopen (const char *__restrict _name, const char *__restrict _type); +__stdargs int sprintf (char *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int remove (const char *); +__stdargs int rename (const char *, const char *); +#ifdef _COMPILING_NEWLIB +__stdargs int _rename (const char *, const char *); +#endif +#endif +#if __LARGEFILE_VISIBLE || __POSIX_VISIBLE >= 200112 +#ifdef _COMPILING_NEWLIB +__stdargs int fseeko (FILE *, _off_t, int); +__stdargs _off_t ftello (FILE *); +#else +__stdargs int fseeko (FILE *, off_t, int); +__stdargs off_t ftello (FILE *); +#endif +#endif +#if __GNU_VISIBLE +__stdargs int fcloseall (void); +#endif +#ifndef _REENT_ONLY +#if __ISO_C_VISIBLE >= 1999 +__stdargs int snprintf (char *__restrict, size_t, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int vsnprintf (char *__restrict, size_t, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int vfscanf (FILE *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 2, 0))); +__stdargs int vscanf (const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 1, 0))); +__stdargs int vsscanf (const char *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 2, 0))); +#endif +#if __GNU_VISIBLE +__stdargs int asprintf (char **__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int vasprintf (char **, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +#endif +#if __MISC_VISIBLE /* Newlib-specific */ +__stdargs int asiprintf (char **, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs char * asniprintf (char *, size_t *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs char * asnprintf (char *__restrict, size_t *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +#ifndef diprintf +__stdargs int diprintf (int, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +#endif +__stdargs int fiprintf (FILE *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int fiscanf (FILE *, const char *, ...) + _ATTRIBUTE ((__format__ (__scanf__, 2, 3))); +__stdargs int iprintf (const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 1, 2))); +__stdargs int iscanf (const char *, ...) + _ATTRIBUTE ((__format__ (__scanf__, 1, 2))); +__stdargs int siprintf (char *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int siscanf (const char *, const char *, ...) + _ATTRIBUTE ((__format__ (__scanf__, 2, 3))); +__stdargs int sniprintf (char *, size_t, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int vasiprintf (char **, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs char * vasniprintf (char *, size_t *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs char * vasnprintf (char *, size_t *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int vdiprintf (int, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int vfiprintf (FILE *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int vfiscanf (FILE *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 2, 0))); +__stdargs int viprintf (const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 1, 0))); +__stdargs int viscanf (const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 1, 0))); +__stdargs int vsiprintf (char *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int vsiscanf (const char *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 2, 0))); +__stdargs int vsniprintf (char *, size_t, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +#endif /* __MISC_VISIBLE */ +#endif /* !_REENT_ONLY */ + +/* + * Routines in POSIX 1003.1:2001. + */ + +#if __POSIX_VISIBLE +#ifndef _REENT_ONLY +__stdargs FILE * fdopen (int, const char *); +#endif +__stdargs int fileno (FILE *); +#endif +#if __MISC_VISIBLE || __POSIX_VISIBLE >= 199209 +__stdargs int pclose (FILE *); +__stdargs FILE * popen (const char *, const char *); +#endif + +#if __BSD_VISIBLE +__stdargs void setbuffer (FILE *, char *, int); +__stdargs int setlinebuf (FILE *); +#endif + +#if __MISC_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112) +__stdargs int getw (FILE *); +__stdargs int putw (int, FILE *); +#endif +#if __MISC_VISIBLE || __POSIX_VISIBLE +__stdargs int getc_unlocked (FILE *); +__stdargs int getchar_unlocked (void); +__stdargs void flockfile (FILE *); +__stdargs int ftrylockfile (FILE *); +__stdargs void funlockfile (FILE *); +__stdargs int putc_unlocked (int, FILE *); +__stdargs int putchar_unlocked (int); +#endif + +/* + * Routines in POSIX 1003.1:200x. + */ + +#if __POSIX_VISIBLE >= 200809 +# ifndef _REENT_ONLY +# ifndef dprintf +__stdargs int dprintf (int, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +# endif +__stdargs FILE * fmemopen (void *__restrict, size_t, const char *__restrict); +/* getdelim - see __getdelim for now */ +/* getline - see __getline for now */ +__stdargs FILE * open_memstream (char **, size_t *); +__stdargs int vdprintf (int, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +# endif +#endif +#if __ATFILE_VISIBLE +__stdargs int renameat (int, const char *, int, const char *); +# ifdef __CYGWIN__ +__stdargs int renameat2 (int, const char *, int, const char *, unsigned int); +# endif +#endif + +/* + * Recursive versions of the above. + */ + +__stdargs int _asiprintf_r (struct _reent *, char **, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 4, 5))); +__stdargs char * _asnprintf_r (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 4, 5))); +__stdargs int _asprintf_r (struct _reent *, char **__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _diprintf_r (struct _reent *, int, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _dprintf_r (struct _reent *, int, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _fclose_r (struct _reent *, FILE *); +__stdargs int _fcloseall_r (struct _reent *); +__stdargs FILE * _fdopen_r (struct _reent *, int, const char *); +__stdargs int _fflush_r (struct _reent *, FILE *); +__stdargs int _fgetc_r (struct _reent *, FILE *); +__stdargs int _fgetc_unlocked_r (struct _reent *, FILE *); +__stdargs char * _fgets_r (struct _reent *, char *__restrict, int, FILE *__restrict); +__stdargs char * _fgets_unlocked_r (struct _reent *, char *__restrict, int, FILE *__restrict); +#ifdef _COMPILING_NEWLIB +__stdargs int _fgetpos_r (struct _reent *, FILE *__restrict, _fpos_t *__restrict); +__stdargs int _fsetpos_r (struct _reent *, FILE *, const _fpos_t *); +#else +__stdargs int _fgetpos_r (struct _reent *, FILE *, fpos_t *); +__stdargs int _fsetpos_r (struct _reent *, FILE *, const fpos_t *); +#endif +__stdargs int _fiprintf_r (struct _reent *, FILE *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _fiscanf_r (struct _reent *, FILE *, const char *, ...) + _ATTRIBUTE ((__format__ (__scanf__, 3, 4))); +__stdargs FILE * _fmemopen_r (struct _reent *, void *__restrict, size_t, const char *__restrict); +__stdargs FILE * _fopen_r (struct _reent *, const char *__restrict, const char *__restrict); +__stdargs FILE * _freopen_r (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict); +__stdargs int _fprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _fpurge_r (struct _reent *, FILE *); +__stdargs int _fputc_r (struct _reent *, int, FILE *); +__stdargs int _fputc_unlocked_r (struct _reent *, int, FILE *); +__stdargs int _fputs_r (struct _reent *, const char *__restrict, FILE *__restrict); +__stdargs int _fputs_unlocked_r (struct _reent *, const char *__restrict, FILE *__restrict); +__stdargs size_t _fread_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict); +__stdargs size_t _fread_unlocked_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict); +__stdargs int _fscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__scanf__, 3, 4))); +__stdargs int _fseek_r (struct _reent *, FILE *, long, int); +__stdargs int _fseeko_r (struct _reent *, FILE *, _off_t, int); +__stdargs long _ftell_r (struct _reent *, FILE *); +__stdargs _off_t _ftello_r (struct _reent *, FILE *); +__stdargs void _rewind_r (struct _reent *, FILE *); +__stdargs size_t _fwrite_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict); +__stdargs size_t _fwrite_unlocked_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict); +__stdargs int _getc_r (struct _reent *, FILE *); +__stdargs int _getc_unlocked_r (struct _reent *, FILE *); +__stdargs int _getchar_r (struct _reent *); +__stdargs int _getchar_unlocked_r (struct _reent *); +__stdargs char * _gets_r (struct _reent *, char *); +__stdargs int _iprintf_r (struct _reent *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int _iscanf_r (struct _reent *, const char *, ...) + _ATTRIBUTE ((__format__ (__scanf__, 2, 3))); +__stdargs FILE * _open_memstream_r (struct _reent *, char **, size_t *); +__stdargs void _perror_r (struct _reent *, const char *); +__stdargs int _printf_r (struct _reent *, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 2, 3))); +__stdargs int _putc_r (struct _reent *, int, FILE *); +__stdargs int _putc_unlocked_r (struct _reent *, int, FILE *); +__stdargs int _putchar_unlocked_r (struct _reent *, int); +__stdargs int _putchar_r (struct _reent *, int); +__stdargs int _puts_r (struct _reent *, const char *); +__stdargs int _remove_r (struct _reent *, const char *); +__stdargs int _rename_r (struct _reent *, + const char *_old, const char *_new); +__stdargs int _scanf_r (struct _reent *, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__scanf__, 2, 3))); +__stdargs int _siprintf_r (struct _reent *, char *, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _siscanf_r (struct _reent *, const char *, const char *, ...) + _ATTRIBUTE ((__format__ (__scanf__, 3, 4))); +__stdargs int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...) + _ATTRIBUTE ((__format__ (__printf__, 4, 5))); +__stdargs int _snprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 4, 5))); +__stdargs int _sprintf_r (struct _reent *, char *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__printf__, 3, 4))); +__stdargs int _sscanf_r (struct _reent *, const char *__restrict, const char *__restrict, ...) + _ATTRIBUTE ((__format__ (__scanf__, 3, 4))); +__stdargs char * _tempnam_r (struct _reent *, const char *, const char *); +__stdargs FILE * _tmpfile_r (struct _reent *); +__stdargs char * _tmpnam_r (struct _reent *, char *); +__stdargs int _ungetc_r (struct _reent *, int, FILE *); +__stdargs int _vasiprintf_r (struct _reent *, char **, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 4, 0))); +__stdargs char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 4, 0))); +__stdargs int _vasprintf_r (struct _reent *, char **, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vdiprintf_r (struct _reent *, int, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vdprintf_r (struct _reent *, int, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vfiprintf_r (struct _reent *, FILE *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vfiscanf_r (struct _reent *, FILE *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 3, 0))); +__stdargs int _vfprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vfscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 3, 0))); +__stdargs int _viprintf_r (struct _reent *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int _viscanf_r (struct _reent *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 2, 0))); +__stdargs int _vprintf_r (struct _reent *, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 2, 0))); +__stdargs int _vscanf_r (struct _reent *, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 2, 0))); +__stdargs int _vsiprintf_r (struct _reent *, char *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vsiscanf_r (struct _reent *, const char *, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 3, 0))); +__stdargs int _vsniprintf_r (struct _reent *, char *, size_t, const char *, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 4, 0))); +__stdargs int _vsnprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 4, 0))); +__stdargs int _vsprintf_r (struct _reent *, char *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__printf__, 3, 0))); +__stdargs int _vsscanf_r (struct _reent *, const char *__restrict, const char *__restrict, __VALIST) + _ATTRIBUTE ((__format__ (__scanf__, 3, 0))); + +/* Other extensions. */ + +__stdargs int fpurge (FILE *); +__stdargs ssize_t __getdelim (char **, size_t *, int, FILE *); +__stdargs ssize_t __getline (char **, size_t *, FILE *); + +#if __MISC_VISIBLE +__stdargs void clearerr_unlocked (FILE *); +__stdargs int feof_unlocked (FILE *); +__stdargs int ferror_unlocked (FILE *); +__stdargs int fileno_unlocked (FILE *); +__stdargs int fflush_unlocked (FILE *); +__stdargs int fgetc_unlocked (FILE *); +__stdargs int fputc_unlocked (int, FILE *); +__stdargs size_t fread_unlocked (void *__restrict, size_t _size, size_t _n, FILE *__restrict); +__stdargs size_t fwrite_unlocked (const void *__restrict , size_t _size, size_t _n, FILE *); +#endif + +#if __GNU_VISIBLE +__stdargs char * fgets_unlocked (char *__restrict, int, FILE *__restrict); +__stdargs int fputs_unlocked (const char *__restrict, FILE *__restrict); +#endif + +#ifdef __LARGE64_FILES +#if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB) +__stdargs FILE * fdopen64 (int, const char *); +__stdargs FILE * fopen64 (const char *, const char *); +__stdargs FILE * freopen64 (const char *, const char *, FILE *); +__stdargs _off64_t ftello64 (FILE *); +__stdargs _off64_t fseeko64 (FILE *, _off64_t, int); +__stdargs int fgetpos64 (FILE *, _fpos64_t *); +__stdargs int fsetpos64 (FILE *, const _fpos64_t *); +__stdargs FILE * tmpfile64 (void); + +__stdargs FILE * _fdopen64_r (struct _reent *, int, const char *); +__stdargs FILE * _fopen64_r (struct _reent *,const char *, const char *); +__stdargs FILE * _freopen64_r (struct _reent *, const char *, const char *, FILE *); +__stdargs _off64_t _ftello64_r (struct _reent *, FILE *); +__stdargs _off64_t _fseeko64_r (struct _reent *, FILE *, _off64_t, int); +__stdargs int _fgetpos64_r (struct _reent *, FILE *, _fpos64_t *); +__stdargs int _fsetpos64_r (struct _reent *, FILE *, const _fpos64_t *); +__stdargs FILE * _tmpfile64_r (struct _reent *); +#endif /* !__CYGWIN__ */ +#endif /* __LARGE64_FILES */ + +/* + * Routines internal to the implementation. + */ + +__stdargs int __srget_r (struct _reent *, FILE *); +__stdargs int __swbuf_r (struct _reent *, int, FILE *); + +/* + * Stdio function-access interface. + */ + +#if __BSD_VISIBLE +# ifdef __LARGE64_FILES +__stdargs FILE *funopen (const void *__cookie, + __stdargs int (*__readfn)(void *__c, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs int (*__writefn)(void *__c, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence), + __stdargs int (*__closefn)(void *__c)); +__stdargs FILE *_funopen_r (struct _reent *, const void *__cookie, + __stdargs int (*__readfn)(void *__c, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs int (*__writefn)(void *__c, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence), + __stdargs int (*__closefn)(void *__c)); +# else +__stdargs FILE *funopen (const void *__cookie, + __stdargs int (*__readfn)(void *__cookie, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs int (*__writefn)(void *__cookie, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence), + __stdargs int (*__closefn)(void *__cookie)); +__stdargs FILE *_funopen_r (struct _reent *, const void *__cookie, + __stdargs int (*__readfn)(void *__cookie, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs int (*__writefn)(void *__cookie, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + __stdargs fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence), + __stdargs int (*__closefn)(void *__cookie)); +# endif /* !__LARGE64_FILES */ + +# define fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \ + (fpos_t (*)())0, (int (*)())0) +# define fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \ + (fpos_t (*)())0, (int (*)())0) +#endif /* __BSD_VISIBLE */ + +#if __GNU_VISIBLE +__stdargs typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n); +__stdargs typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf, + size_t __n); +# ifdef __LARGE64_FILES +typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off, + int __whence); +# else +typedef __stdargs int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence); +# endif /* !__LARGE64_FILES */ +typedef __stdargs int cookie_close_function_t(void *__cookie); +typedef struct +{ + /* These four struct member names are dictated by Linux; hopefully, + they don't conflict with any macros. */ + cookie_read_function_t *read; + cookie_write_function_t *write; + cookie_seek_function_t *seek; + cookie_close_function_t *close; +} cookie_io_functions_t; +__stdargs FILE *fopencookie (void *__cookie, + const char *__mode, cookie_io_functions_t __functions); +__stdargs FILE *_fopencookie_r (struct _reent *, void *__cookie, + const char *__mode, cookie_io_functions_t __functions); +#endif /* __GNU_VISIBLE */ + +#ifndef __CUSTOM_FILE_IO__ +/* + * The __sfoo macros are here so that we can + * define function versions in the C library. + */ +#define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++)) + +#ifdef __SCLE +/* For a platform with CR/LF, additional logic is required by + __sgetc_r which would otherwise simply be a macro; therefore we + use an inlined function. The function is only meant to be inlined + in place as used and the function body should never be emitted. + + There are two possible means to this end when compiling with GCC, + one when compiling with a standard C99 compiler, and for other + compilers we're just stuck. At the moment, this issue only + affects the Cygwin target, so we'll most likely be using GCC. */ + +_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p); + +_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p) + { + int __c = __sgetc_raw_r(__ptr, __p); + if ((__p->_flags & __SCLE) && (__c == '\r')) + { + int __c2 = __sgetc_raw_r(__ptr, __p); + if (__c2 == '\n') + __c = __c2; + else + ungetc(__c2, __p); + } + return __c; + } +#else +#define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p) +#endif + +#ifdef __GNUC__ +_ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) { +#ifdef __SCLE + if ((_p->_flags & __SCLE) && _c == '\n') + __sputc_r (_ptr, '\r', _p); +#endif + if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) + return (*_p->_p++ = _c); + else + return (__swbuf_r(_ptr, _c, _p)); +} +#else +/* + * This has been tuned to generate reasonable code on the vax using pcc + */ +#define __sputc_raw_r(__ptr, __c, __p) \ + (--(__p)->_w < 0 ? \ + (__p)->_w >= (__p)->_lbfsize ? \ + (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \ + (int)*(__p)->_p++ : \ + __swbuf_r(__ptr, '\n', __p) : \ + __swbuf_r(__ptr, (int)(__c), __p) : \ + (*(__p)->_p = (__c), (int)*(__p)->_p++)) +#ifdef __SCLE +#define __sputc_r(__ptr, __c, __p) \ + ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \ + ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \ + __sputc_raw_r((__ptr), (__c), (__p))) +#else +#define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p) +#endif +#endif + +#define __sfeof(p) ((int)(((p)->_flags & __SEOF) != 0)) +#define __sferror(p) ((int)(((p)->_flags & __SERR) != 0)) +#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) +#define __sfileno(p) ((p)->_file) + +#ifndef __cplusplus +#ifndef _REENT_SMALL +#define feof(p) __sfeof(p) +#define ferror(p) __sferror(p) +#define clearerr(p) __sclearerr(p) + +#if __MISC_VISIBLE +#define feof_unlocked(p) __sfeof(p) +#define ferror_unlocked(p) __sferror(p) +#define clearerr_unlocked(p) __sclearerr(p) +#endif /* __MISC_VISIBLE */ +#endif /* _REENT_SMALL */ + +#if 0 /* __POSIX_VISIBLE - FIXME: must initialize stdio first, use fn */ +#define fileno(p) __sfileno(p) +#endif + +static __inline int +_getchar_unlocked(void) +{ + struct _reent *_ptr; + + _ptr = _REENT; + return (__sgetc_r(_ptr, _stdin_r(_ptr))); +} + +static __inline int +_putchar_unlocked(int _c) +{ + struct _reent *_ptr; + + _ptr = _REENT; + return (__sputc_r(_ptr, _c, _stdout_r(_ptr))); +} + +#ifdef __SINGLE_THREAD__ +#define getc(_p) __sgetc_r(_REENT, _p) +#define putc(_c, _p) __sputc_r(_REENT, _c, _p) +#define getchar() _getchar_unlocked() +#define putchar(_c) _putchar_unlocked(_c) +#endif /* __SINGLE_THREAD__ */ + +#if __MISC_VISIBLE || __POSIX_VISIBLE +#define getchar_unlocked() _getchar_unlocked() +#define putchar_unlocked(_c) _putchar_unlocked(_c) +#endif +#endif /* __cplusplus */ + +#if __MISC_VISIBLE +/* fast always-buffered version, true iff error */ +#define fast_putc(x,p) (--(p)->_w < 0 ? \ + __swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0)) +#endif + +#if __GNU_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600) +#define L_cuserid 9 /* posix says it goes in stdio.h :( */ +#endif +#if __POSIX_VISIBLE +#define L_ctermid 16 +#endif + +#else /* __CUSTOM_FILE_IO__ */ + +#define getchar() getc(stdin) +#define putchar(x) putc(x, stdout) + +#if __MISC_VISIBLE || __POSIX_VISIBLE +#define getchar_unlocked() getc_unlocked(stdin) +#define putchar_unlocked(x) putc_unlocked(x, stdout) +#endif + +#endif /* !__CUSTOM_FILE_IO__ */ + +_END_STD_C + +#if __SSP_FORTIFY_LEVEL > 0 +#include +#endif + +#endif /* _STDIO_H_ */ diff --git a/sys-include/string.h b/sys-include/string.h index 88e1780..14c4d53 100644 --- a/sys-include/string.h +++ b/sys-include/string.h @@ -1,82 +1,183 @@ -#ifndef _STRING_H_ -#define _STRING_H_ - /* * string.h * * Definitions for memory and string functions. */ +#ifndef _STRING_H_ +#define _STRING_H_ + +#include "_ansi.h" +#include #include -#include +#include + +#define __need_size_t +#define __need_NULL #include -#ifndef NULL -#define NULL 0 +#if __POSIX_VISIBLE >= 200809 +#include #endif -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -__stdargs void *memset(void *, int, size_t); -__stdargs void *memcpy(void *, const void *, size_t); -__stdargs char *strchr(const char *, int); -__stdargs int strcoll(const char *, const char *); -__stdargs size_t strcspn(const char *, const char *); -__stdargs char *strerror(int); -__stdargs char *strcat(char *, const char *); -__stdargs char *strncat(char *, const char *, size_t); -__stdargs int strcmp(const char *, const char *); -__stdargs int strncmp(const char *, const char *, size_t); -__stdargs char *strncpy(char *, const char *, size_t); -__stdargs char *strpbrk(const char *, const char *); -__stdargs char *strrchr(const char *, int); -__stdargs size_t strspn(const char *, const char *); -__stdargs char *strstr(const char *, const char *); -__stdargs char *strtok(char *, const char *); -__stdargs char* strtok_r(char *str, const char *delim, char **nextp); -__stdargs size_t strxfrm(char *, const char *, size_t); -__stdargs char *strupr(char *s); - -/* Nonstandard routines */ -#ifndef _ANSI_SOURCE -__stdargs int bcmp(const void *, const void *, size_t); -__stdargs void bcopy(const void *, void *, size_t); -__stdargs void bzero(void *, size_t); -__stdargs int ffs(int); -__stdargs char *index(const char *, int); -__stdargs void *memccpy(void *, const void *, int, size_t); -__stdargs char *rindex(const char *, int); -__stdargs int strcasecmp(const char *, const char *); -__stdargs char *strdup(const char *); -__stdargs void strmode(int, char *); -__stdargs int strncasecmp(const char *, const char *, size_t); -__stdargs char *strsep(char **, const char *); -__stdargs void swab(const void *, void *, ssize_t); -__stdargs int stricmp(const char *, const char *); -__stdargs int strnicmp(const char *, const char *, size_t); - -__stdargs char *strerror_r(int errnum, char *buf, size_t buflen); -#endif - -#ifdef __NO_INLINE__ -__stdargs void *memmove(void *, const void *, size_t); -__stdargs int memcmp(const void *, const void *, size_t); -__stdargs void *memchr(const void *, int, size_t); -__stdargs size_t strlen(const char *); -__stdargs size_t strlen_plus_one(const char *string); -__stdargs char *strcpy(char *, const char *); -__stdargs char *strlwr(char *s); -__stdargs char *stpcpy(char *dst, const char *src); -__stdargs void *mempcpy(void *, const void *, size_t); -#else -#include "strsup.h" +#if __BSD_VISIBLE +#include #endif -#ifdef __cplusplus -} -#endif /* __cplusplus */ +_BEGIN_STD_C +__stdargs void * memchr (const void *, int, size_t); +__stdargs int memcmp (const void *, const void *, size_t); +__stdargs void * memcpy (void *__restrict, const void *__restrict, size_t); +__stdargs void * memmove (void *, const void *, size_t); +__stdargs void * memset (void *, int, size_t); +__stdargs char *strcat (char *__restrict, const char *__restrict); +__stdargs char *strchr (const char *, int); +__stdargs int strcmp (const char *, const char *); +__stdargs int strcoll (const char *, const char *); +__stdargs char *strcpy (char *__restrict, const char *__restrict); +__stdargs size_t strcspn (const char *, const char *); +__stdargs char *strerror (int); +__stdargs size_t strlen (const char *); +__stdargs char *strncat (char *__restrict, const char *__restrict, size_t); +__stdargs int strncmp (const char *, const char *, size_t); +__stdargs char *strncpy (char *__restrict, const char *__restrict, size_t); +__stdargs char *strpbrk (const char *, const char *); +__stdargs char *strrchr (const char *, int); +__stdargs size_t strspn (const char *, const char *); +__stdargs char *strstr (const char *, const char *); +#ifndef _REENT_ONLY +__stdargs char *strtok (char *__restrict, const char *__restrict); +#endif +__stdargs size_t strxfrm (char *__restrict, const char *__restrict, size_t); -#endif // _STRING_H_ +#if __POSIX_VISIBLE >= 200809 +__stdargs int strcoll_l (const char *, const char *, locale_t); +__stdargs char *strerror_l (int, locale_t); +__stdargs size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); +#endif +#if __MISC_VISIBLE || __POSIX_VISIBLE +__stdargs char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); +#endif +#if __BSD_VISIBLE +__stdargs int timingsafe_bcmp (const void *, const void *, size_t); +__stdargs int timingsafe_memcmp (const void *, const void *, size_t); +#endif +#if __MISC_VISIBLE || __POSIX_VISIBLE +__stdargs void * memccpy (void *__restrict, const void *__restrict, int, size_t); +#endif +#if __GNU_VISIBLE +__stdargs void * mempcpy (void *, const void *, size_t); +__stdargs void * memmem (const void *, size_t, const void *, size_t); +__stdargs void * memrchr (const void *, int, size_t); +__stdargs void * rawmemchr (const void *, int); +#endif +#if __POSIX_VISIBLE >= 200809 +__stdargs char *stpcpy (char *__restrict, const char *__restrict); +__stdargs char *stpncpy (char *__restrict, const char *__restrict, size_t); +#endif +#if __GNU_VISIBLE +__stdargs char *strcasestr (const char *, const char *); +__stdargs char *strchrnul (const char *, int); +#endif +#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4 +__stdargs char *strdup (const char *); +#endif +__stdargs char *_strdup_r (struct _reent *, const char *); +#if __POSIX_VISIBLE >= 200809 +__stdargs char *strndup (const char *, size_t); +#endif +__stdargs char *_strndup_r (struct _reent *, const char *, size_t); + +/* There are two common strerror_r variants. If you request + _GNU_SOURCE, you get the GNU version; otherwise you get the POSIX + version. POSIX requires that #undef strerror_r will still let you + invoke the underlying function, but that requires gcc support. */ +#if __GNU_VISIBLE +__stdargs char *strerror_r (int, char *, size_t); +#elif __POSIX_VISIBLE >= 200112 +# ifdef __GNUC__ +__stdargs int strerror_r (int, char *, size_t) +#ifdef __ASMNAME + __asm__ (__ASMNAME ("__xpg_strerror_r")) +#endif + ; +# else +__stdargs int __xpg_strerror_r (int, char *, size_t); +# define strerror_r __xpg_strerror_r +# endif +#endif + +/* Reentrant version of strerror. */ +__stdargs char * _strerror_r (struct _reent *, int, int, int *); + +#if __BSD_VISIBLE +__stdargs size_t strlcat (char *, const char *, size_t); +__stdargs size_t strlcpy (char *, const char *, size_t); +#endif +#if __POSIX_VISIBLE >= 200809 +__stdargs size_t strnlen (const char *, size_t); +#endif +#if __BSD_VISIBLE +__stdargs char *strsep (char **, const char *); +#endif +#if __BSD_VISIBLE +__stdargs char *strnstr(const char *, const char *, size_t) __pure; +#endif + +#if __MISC_VISIBLE +__stdargs char *strlwr (char *); +__stdargs char *strupr (char *); +#endif + +#ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ +__stdargs const char *strsignal (int __signo); +#endif + +#ifdef __CYGWIN__ +__stdargs int strtosigno (const char *__name); +#endif + +#if __GNU_VISIBLE +__stdargs int strverscmp (const char *, const char *); +#endif + +#if __GNU_VISIBLE && defined(__GNUC__) +#define strdupa(__s) \ + (__extension__ ({const char *__sin = (__s); \ + size_t __len = strlen (__sin) + 1; \ + char * __sout = (char *) __builtin_alloca (__len); \ + (char *) memcpy (__sout, __sin, __len);})) +#define strndupa(__s, __n) \ + (__extension__ ({const char *__sin = (__s); \ + size_t __len = strnlen (__sin, (__n)) + 1; \ + char *__sout = (char *) __builtin_alloca (__len); \ + __sout[__len-1] = '\0'; \ + (char *) memcpy (__sout, __sin, __len-1);})) +#endif /* __GNU_VISIBLE && __GNUC__ */ + +/* There are two common basename variants. If you do NOT #include + and you do + + #define _GNU_SOURCE + #include + + you get the GNU version. Otherwise you get the POSIX versionfor which you + should #include i for the function prototype. POSIX requires that + #undef basename will still let you invoke the underlying function. However, + this also implies that the POSIX version is used in this case. That's made + sure here. */ +#if __GNU_VISIBLE && !defined(basename) +# define basename basename +__stdargs char *__nonnull ((1)) basename (const char *) __asm__(__ASMNAME("__gnu_basename")); +#endif + +#include + +_END_STD_C + +#if __SSP_FORTIFY_LEVEL > 0 +#include +#endif + +#endif /* _STRING_H_ */ diff --git a/sys-include/sys/_default_fcntl.h b/sys-include/sys/_default_fcntl.h index ced270e..64a80bf 100644 --- a/sys-include/sys/_default_fcntl.h +++ b/sys-include/sys/_default_fcntl.h @@ -43,6 +43,10 @@ extern "C" { /* O_NDELAY _FNBIO set in include/fcntl.h */ #define O_NONBLOCK _FNONBLOCK #define O_NOCTTY _FNOCTTY + +// dummy +#define O_NOFOLLOW 0 + /* For machines which care - */ #if defined (__CYGWIN__) #define _FBINARY 0x10000 diff --git a/sys-include/sys/errno.h b/sys-include/sys/errno.h index c442483..59ca893 100644 --- a/sys-include/sys/errno.h +++ b/sys-include/sys/errno.h @@ -8,14 +8,9 @@ extern "C" { #endif #define _SYS_ERRNO_H_ -#ifndef __stdargs -#define __stdargs -#endif - #include -//#ifndef __libnix__ -#if 0 +#ifndef __libnix__ #ifndef _REENT_ONLY #define errno (*__errno()) #ifdef __NO_INLINE__ diff --git a/sys-include/sys/reent.h b/sys-include/sys/reent.h index 49f4c6b..6ef940b 100644 --- a/sys-include/sys/reent.h +++ b/sys-include/sys/reent.h @@ -1,12 +1,851 @@ -#ifndef __LIBNIX_SYS_REENT_H -#define __LIBNIX_SYS_REENT_H +/* This header file provides the reentrancy. */ -#if !defined(__FILE_defined) -typedef struct __sFILE __FILE; -typedef __FILE FILE; -# define __FILE_defined +/* WARNING: All identifiers here must begin with an underscore. This file is + included by stdio.h and others and we therefore must only use identifiers + in the namespace allotted to us. */ + +#ifndef _SYS_REENT_H_ +#ifdef __cplusplus +extern "C" { +#endif +#define _SYS_REENT_H_ + +#include <_ansi.h> +#include +#include + +#define _NULL 0 + +#ifndef __Long +#if __LONG_MAX__ == 2147483647L +#define __Long long +typedef unsigned __Long __ULong; +#elif __INT_MAX__ == 2147483647 +#define __Long int +typedef unsigned __Long __ULong; +#endif +#endif + +#if !defined( __Long) +#include +#endif + +#ifndef __Long +#define __Long __int32_t +typedef __uint32_t __ULong; #endif struct _reent; -#endif // __LIBNIX_SYS_REENT_H +struct __locale_t; + +/* + * If _REENT_SMALL is defined, we make struct _reent as small as possible, + * by having nearly everything possible allocated at first use. + */ + +struct _Bigint +{ + struct _Bigint *_next; + int _k, _maxwds, _sign, _wds; + __ULong _x[1]; +}; + +/* needed by reentrant structure */ +struct __tm +{ + int __tm_sec; + int __tm_min; + int __tm_hour; + int __tm_mday; + int __tm_mon; + int __tm_year; + int __tm_wday; + int __tm_yday; + int __tm_isdst; +}; + +/* + * atexit() support. + */ + +#define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */ + +struct _on_exit_args { + void * _fnargs[_ATEXIT_SIZE]; /* user fn args */ + void * _dso_handle[_ATEXIT_SIZE]; + /* Bitmask is set if user function takes arguments. */ + __ULong _fntypes; /* type of exit routine - + Must have at least _ATEXIT_SIZE bits */ + /* Bitmask is set if function was registered via __cxa_atexit. */ + __ULong _is_cxa; +}; + +#ifdef _REENT_SMALL +struct _atexit { + struct _atexit *_next; /* next in list */ + int _ind; /* next index in this table */ + void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ + struct _on_exit_args * _on_exit_args_ptr; +}; +# define _ATEXIT_INIT {_NULL, 0, {_NULL}, _NULL} +#else +struct _atexit { + struct _atexit *_next; /* next in list */ + int _ind; /* next index in this table */ + /* Some entries may already have been called, and will be NULL. */ + void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ + struct _on_exit_args _on_exit_args; +}; +# define _ATEXIT_INIT {_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}} +#endif + +#ifdef _REENT_GLOBAL_ATEXIT +# define _REENT_INIT_ATEXIT +#else +# define _REENT_INIT_ATEXIT \ + _NULL, _ATEXIT_INIT, +#endif + +/* + * Stdio buffers. + * + * This and __FILE are defined here because we need them for struct _reent, + * but we don't want stdio.h included when stdlib.h is. + */ + +struct __sbuf { + unsigned char *_base; + int _size; +}; + +/* + * Stdio state variables. + * + * The following always hold: + * + * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), + * _lbfsize is -_bf._size, else _lbfsize is 0 + * if _flags&__SRD, _w is 0 + * if _flags&__SWR, _r is 0 + * + * This ensures that the getc and putc macros (or inline functions) never + * try to write or read from a file that is in `read' or `write' mode. + * (Moreover, they can, and do, automatically switch from read mode to + * write mode, and back, on "r+" and "w+" files.) + * + * _lbfsize is used only to make the inline line-buffered output stream + * code as compact as possible. + * + * _ub, _up, and _ur are used when ungetc() pushes back more characters + * than fit in the current _bf, or when ungetc() pushes back a character + * that does not match the previous one in _bf. When this happens, + * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff + * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. + */ + +#if defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS) +/* + * struct __sFILE_fake is the start of a struct __sFILE, with only the + * minimal fields allocated. In __sinit() we really allocate the 3 + * standard streams, etc., and point away from this fake. + */ +struct __sFILE_fake { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + + struct _reent *_data; +}; + +/* Following is needed both in libc/stdio and libc/stdlib so we put it + * here instead of libc/stdio/local.h where it was previously. */ + +extern void __sinit (struct _reent *); + +# define _REENT_SMALL_CHECK_INIT(ptr) \ + do \ + { \ + if ((ptr) && !(ptr)->__sdidinit) \ + __sinit (ptr); \ + } \ + while (0) +#else /* _REENT_SMALL && !_REENT_GLOBAL_STDIO_STREAMS */ +# define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */ +#endif /* _REENT_SMALL && !_REENT_GLOBAL_STDIO_STREAMS */ + +#if !defined(__libnix__) && !defined(__SFILE_DEFINED__) +#define __SFILE_DEFINED__ + +struct __sFILE { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + +#ifdef _REENT_SMALL + struct _reent *_data; +#endif + + /* operations */ + void * _cookie; /* cookie passed to io functions */ + + __stdargs _READ_WRITE_RETURN_TYPE (*_read) (struct _reent *, void *, + char *, _READ_WRITE_BUFSIZE_TYPE); + __stdargs _READ_WRITE_RETURN_TYPE (*_write) (struct _reent *, void *, + const char *, + _READ_WRITE_BUFSIZE_TYPE); + __stdargs _fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int); + __stdargs int (*_close) (struct _reent *, void *); + + /* separate buffer for long sequences of ungetc() */ + struct __sbuf _ub; /* ungetc buffer */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + int _ur; /* saved _r when _r is counting ungetc data */ + + /* tricks to meet minimum requirements even when malloc() fails */ + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + /* separate buffer for fgetline() when line crosses buffer boundary */ + struct __sbuf _lb; /* buffer for fgetline() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + _off_t _offset; /* current lseek offset */ + +#ifndef _REENT_SMALL + struct _reent *_data; /* Here for binary compatibility? Remove? */ +#endif + +#ifndef __SINGLE_THREAD__ + _flock_t _lock; /* for thread-safety locking */ +#endif + _mbstate_t _mbstate; /* for wide char stdio functions. */ + int _flags2; /* for future use */ +}; + +#endif // __SFILE_DEFINED__ + +#ifdef __CUSTOM_FILE_IO__ + +/* Get custom _FILE definition. */ +#include + +#else /* !__CUSTOM_FILE_IO__ */ +#ifdef __LARGE64_FILES +struct __sFILE64 { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + + struct _reent *_data; + + /* operations */ + void * _cookie; /* cookie passed to io functions */ + + __stdargs _READ_WRITE_RETURN_TYPE (*_read) (struct _reent *, void *, + char *, _READ_WRITE_BUFSIZE_TYPE); + __stdargs _READ_WRITE_RETURN_TYPE (*_write) (struct _reent *, void *, + const char *, + _READ_WRITE_BUFSIZE_TYPE); + __stdargs _fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int); + __stdargs int (*_close) (struct _reent *, void *); + + /* separate buffer for long sequences of ungetc() */ + struct __sbuf _ub; /* ungetc buffer */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + int _ur; /* saved _r when _r is counting ungetc data */ + + /* tricks to meet minimum requirements even when malloc() fails */ + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + /* separate buffer for fgetline() when line crosses buffer boundary */ + struct __sbuf _lb; /* buffer for fgetline() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + int _flags2; /* for future use */ + + _off64_t _offset; /* current lseek offset */ + __stdargs _fpos64_t (*_seek64) (struct _reent *, void *, _fpos64_t, int); + +#ifndef __SINGLE_THREAD__ + _flock_t _lock; /* for thread-safety locking */ +#endif + _mbstate_t _mbstate; /* for wide char stdio functions. */ +}; +typedef struct __sFILE64 __FILE; +#else +#if defined(__libnix__) +#include +#else +typedef struct __sFILE __FILE; +#endif +#endif /* __LARGE64_FILES */ +#endif /* !__CUSTOM_FILE_IO__ */ + +struct _glue +{ + struct _glue *_next; + int _niobs; + __FILE *_iobs; +}; + +/* + * rand48 family support + * + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ +#define _RAND48_SEED_0 (0x330e) +#define _RAND48_SEED_1 (0xabcd) +#define _RAND48_SEED_2 (0x1234) +#define _RAND48_MULT_0 (0xe66d) +#define _RAND48_MULT_1 (0xdeec) +#define _RAND48_MULT_2 (0x0005) +#define _RAND48_ADD (0x000b) +struct _rand48 { + unsigned short _seed[3]; + unsigned short _mult[3]; + unsigned short _add; +#ifdef _REENT_SMALL + /* Put this in here as well, for good luck. */ + __extension__ unsigned long long _rand_next; +#endif +}; + +/* How big the some arrays are. */ +#define _REENT_EMERGENCY_SIZE 25 +#define _REENT_ASCTIME_SIZE 26 +#define _REENT_SIGNAL_SIZE 24 + +/* + * struct _reent + * + * This structure contains *all* globals needed by the library. + * It's raison d'etre is to facilitate threads by making all library routines + * reentrant. IE: All state information is contained here. + */ + +#ifdef _REENT_SMALL + +struct _mprec +{ + /* used by mprec routines */ + struct _Bigint *_result; + int _result_k; + struct _Bigint *_p5s; + struct _Bigint **_freelist; +}; + + +struct _misc_reent +{ + /* miscellaneous reentrant data */ + char *_strtok_last; + _mbstate_t _mblen_state; + _mbstate_t _wctomb_state; + _mbstate_t _mbtowc_state; + char _l64a_buf[8]; + int _getdate_err; + _mbstate_t _mbrlen_state; + _mbstate_t _mbrtowc_state; + _mbstate_t _mbsrtowcs_state; + _mbstate_t _wcrtomb_state; + _mbstate_t _wcsrtombs_state; +}; + +/* This version of _reent is laid out with "int"s in pairs, to help + * ports with 16-bit int's but 32-bit pointers, align nicely. */ +struct _reent +{ + /* As an exception to the above put _errno first for binary + compatibility with non _REENT_SMALL targets. */ + int _errno; /* local copy of errno */ + + /* FILE is a big struct and may change over time. To try to achieve binary + compatibility with future versions, put stdin,stdout,stderr here. + These are pointers into member __sf defined below. */ + __FILE *_stdin, *_stdout, *_stderr; /* XXX */ + + int _inc; /* used by tmpnam */ + + char *_emergency; + + int __sdidinit; /* 1 means stdio has been init'd */ + + int _unspecified_locale_info; /* unused, reserved for locale stuff */ + struct __locale_t *_locale;/* per-thread locale */ + + struct _mprec *_mp; + + __stdargs void (*__cleanup) (struct _reent *); + + int _gamma_signgam; + + /* used by some fp conversion routines */ + int _cvtlen; /* should be size_t */ + char *_cvtbuf; + + struct _rand48 *_r48; + struct __tm *_localtime_buf; + char *_asctime_buf; + + /* signal info */ + void (**(_sig_func))(int); + +# ifndef _REENT_GLOBAL_ATEXIT + /* atexit stuff */ + struct _atexit *_atexit; + struct _atexit _atexit0; +# endif + + struct _glue __sglue; /* root of glue chain */ + __FILE *__sf; /* file descriptors */ + struct _misc_reent *_misc; /* strtok, multibyte states */ + char *_signal_buf; /* strsignal */ +}; + +#ifdef _REENT_GLOBAL_STDIO_STREAMS +extern __FILE __sf[3]; + +# define _REENT_INIT(var) \ + { 0, \ + &__sf[0], \ + &__sf[1], \ + &__sf[2], \ + 0, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _REENT_INIT_ATEXIT \ + {_NULL, 0, _NULL}, \ + _NULL, \ + _NULL, \ + _NULL \ + } + +#define _REENT_INIT_PTR_ZEROED(var) \ + { (var)->_stdin = &__sf[0]; \ + (var)->_stdout = &__sf[1]; \ + (var)->_stderr = &__sf[2]; \ + } + +#else /* _REENT_GLOBAL_STDIO_STREAMS */ + +extern const struct __sFILE_fake __sf_fake_stdin; +extern const struct __sFILE_fake __sf_fake_stdout; +extern const struct __sFILE_fake __sf_fake_stderr; + +# define _REENT_INIT(var) \ + { 0, \ + (__FILE *)&__sf_fake_stdin, \ + (__FILE *)&__sf_fake_stdout, \ + (__FILE *)&__sf_fake_stderr, \ + 0, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _REENT_INIT_ATEXIT \ + {_NULL, 0, _NULL}, \ + _NULL, \ + _NULL, \ + _NULL \ + } + +#define _REENT_INIT_PTR_ZEROED(var) \ + { (var)->_stdin = (__FILE *)&__sf_fake_stdin; \ + (var)->_stdout = (__FILE *)&__sf_fake_stdout; \ + (var)->_stderr = (__FILE *)&__sf_fake_stderr; \ + } + +#endif /* _REENT_GLOBAL_STDIO_STREAMS */ + +/* Only add assert() calls if we are specified to debug. */ +#ifdef _REENT_CHECK_DEBUG +#include +#define __reent_assert(x) assert(x) +#else +#define __reent_assert(x) ((void)0) +#endif + +#ifdef __CUSTOM_FILE_IO__ +#error Custom FILE I/O and _REENT_SMALL not currently supported. +#endif + +/* Generic _REENT check macro. */ +#define _REENT_CHECK(var, what, type, size, init) do { \ + struct _reent *_r = (var); \ + if (_r->what == NULL) { \ + _r->what = (type)malloc(size); \ + __reent_assert(_r->what); \ + init; \ + } \ +} while (0) + +#define _REENT_CHECK_TM(var) \ + _REENT_CHECK(var, _localtime_buf, struct __tm *, sizeof *((var)->_localtime_buf), \ + /* nothing */) + +#define _REENT_CHECK_ASCTIME_BUF(var) \ + _REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \ + memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE)) + +/* Handle the dynamically allocated rand48 structure. */ +#define _REENT_INIT_RAND48(var) do { \ + struct _reent *_r = (var); \ + _r->_r48->_seed[0] = _RAND48_SEED_0; \ + _r->_r48->_seed[1] = _RAND48_SEED_1; \ + _r->_r48->_seed[2] = _RAND48_SEED_2; \ + _r->_r48->_mult[0] = _RAND48_MULT_0; \ + _r->_r48->_mult[1] = _RAND48_MULT_1; \ + _r->_r48->_mult[2] = _RAND48_MULT_2; \ + _r->_r48->_add = _RAND48_ADD; \ + _r->_r48->_rand_next = 1; \ +} while (0) +#define _REENT_CHECK_RAND48(var) \ + _REENT_CHECK(var, _r48, struct _rand48 *, sizeof *((var)->_r48), _REENT_INIT_RAND48((var))) + +#define _REENT_INIT_MP(var) do { \ + struct _reent *_r = (var); \ + _r->_mp->_result_k = 0; \ + _r->_mp->_result = _r->_mp->_p5s = _NULL; \ + _r->_mp->_freelist = _NULL; \ +} while (0) +#define _REENT_CHECK_MP(var) \ + _REENT_CHECK(var, _mp, struct _mprec *, sizeof *((var)->_mp), _REENT_INIT_MP(var)) + +#define _REENT_CHECK_EMERGENCY(var) \ + _REENT_CHECK(var, _emergency, char *, _REENT_EMERGENCY_SIZE, /* nothing */) + +#define _REENT_INIT_MISC(var) do { \ + struct _reent *_r = (var); \ + _r->_misc->_strtok_last = _NULL; \ + _r->_misc->_mblen_state.__count = 0; \ + _r->_misc->_mblen_state.__value.__wch = 0; \ + _r->_misc->_wctomb_state.__count = 0; \ + _r->_misc->_wctomb_state.__value.__wch = 0; \ + _r->_misc->_mbtowc_state.__count = 0; \ + _r->_misc->_mbtowc_state.__value.__wch = 0; \ + _r->_misc->_mbrlen_state.__count = 0; \ + _r->_misc->_mbrlen_state.__value.__wch = 0; \ + _r->_misc->_mbrtowc_state.__count = 0; \ + _r->_misc->_mbrtowc_state.__value.__wch = 0; \ + _r->_misc->_mbsrtowcs_state.__count = 0; \ + _r->_misc->_mbsrtowcs_state.__value.__wch = 0; \ + _r->_misc->_wcrtomb_state.__count = 0; \ + _r->_misc->_wcrtomb_state.__value.__wch = 0; \ + _r->_misc->_wcsrtombs_state.__count = 0; \ + _r->_misc->_wcsrtombs_state.__value.__wch = 0; \ + _r->_misc->_l64a_buf[0] = '\0'; \ + _r->_misc->_getdate_err = 0; \ +} while (0) +#define _REENT_CHECK_MISC(var) \ + _REENT_CHECK(var, _misc, struct _misc_reent *, sizeof *((var)->_misc), _REENT_INIT_MISC(var)) + +#define _REENT_CHECK_SIGNAL_BUF(var) \ + _REENT_CHECK(var, _signal_buf, char *, _REENT_SIGNAL_SIZE, /* nothing */) + +#define _REENT_SIGNGAM(ptr) ((ptr)->_gamma_signgam) +#define _REENT_RAND_NEXT(ptr) ((ptr)->_r48->_rand_next) +#define _REENT_RAND48_SEED(ptr) ((ptr)->_r48->_seed) +#define _REENT_RAND48_MULT(ptr) ((ptr)->_r48->_mult) +#define _REENT_RAND48_ADD(ptr) ((ptr)->_r48->_add) +#define _REENT_MP_RESULT(ptr) ((ptr)->_mp->_result) +#define _REENT_MP_RESULT_K(ptr) ((ptr)->_mp->_result_k) +#define _REENT_MP_P5S(ptr) ((ptr)->_mp->_p5s) +#define _REENT_MP_FREELIST(ptr) ((ptr)->_mp->_freelist) +#define _REENT_ASCTIME_BUF(ptr) ((ptr)->_asctime_buf) +#define _REENT_TM(ptr) ((ptr)->_localtime_buf) +#define _REENT_EMERGENCY(ptr) ((ptr)->_emergency) +#define _REENT_STRTOK_LAST(ptr) ((ptr)->_misc->_strtok_last) +#define _REENT_MBLEN_STATE(ptr) ((ptr)->_misc->_mblen_state) +#define _REENT_MBTOWC_STATE(ptr)((ptr)->_misc->_mbtowc_state) +#define _REENT_WCTOMB_STATE(ptr)((ptr)->_misc->_wctomb_state) +#define _REENT_MBRLEN_STATE(ptr) ((ptr)->_misc->_mbrlen_state) +#define _REENT_MBRTOWC_STATE(ptr) ((ptr)->_misc->_mbrtowc_state) +#define _REENT_MBSRTOWCS_STATE(ptr) ((ptr)->_misc->_mbsrtowcs_state) +#define _REENT_WCRTOMB_STATE(ptr) ((ptr)->_misc->_wcrtomb_state) +#define _REENT_WCSRTOMBS_STATE(ptr) ((ptr)->_misc->_wcsrtombs_state) +#define _REENT_L64A_BUF(ptr) ((ptr)->_misc->_l64a_buf) +#define _REENT_GETDATE_ERR_P(ptr) (&((ptr)->_misc->_getdate_err)) +#define _REENT_SIGNAL_BUF(ptr) ((ptr)->_signal_buf) + +#else /* !_REENT_SMALL */ + +struct _reent +{ + int _errno; /* local copy of errno */ + + /* FILE is a big struct and may change over time. To try to achieve binary + compatibility with future versions, put stdin,stdout,stderr here. + These are pointers into member __sf defined below. */ + __FILE *_stdin, *_stdout, *_stderr; + + int _inc; /* used by tmpnam */ + char _emergency[_REENT_EMERGENCY_SIZE]; + + /* TODO */ + int _unspecified_locale_info; /* unused, reserved for locale stuff */ + struct __locale_t *_locale;/* per-thread locale */ + + int __sdidinit; /* 1 means stdio has been init'd */ + + __stdargs void (*__cleanup) (struct _reent *); + + /* used by mprec routines */ + struct _Bigint *_result; + int _result_k; + struct _Bigint *_p5s; + struct _Bigint **_freelist; + + /* used by some fp conversion routines */ + int _cvtlen; /* should be size_t */ + char *_cvtbuf; + + union + { + struct + { + unsigned int _unused_rand; + char * _strtok_last; + char _asctime_buf[_REENT_ASCTIME_SIZE]; + struct __tm _localtime_buf; + int _gamma_signgam; + __extension__ unsigned long long _rand_next; + struct _rand48 _r48; + _mbstate_t _mblen_state; + _mbstate_t _mbtowc_state; + _mbstate_t _wctomb_state; + char _l64a_buf[8]; + char _signal_buf[_REENT_SIGNAL_SIZE]; + int _getdate_err; + _mbstate_t _mbrlen_state; + _mbstate_t _mbrtowc_state; + _mbstate_t _mbsrtowcs_state; + _mbstate_t _wcrtomb_state; + _mbstate_t _wcsrtombs_state; + int _h_errno; + } _reent; + /* Two next two fields were once used by malloc. They are no longer + used. They are used to preserve the space used before so as to + allow addition of new reent fields and keep binary compatibility. */ + struct + { +#define _N_LISTS 30 + unsigned char * _nextf[_N_LISTS]; + unsigned int _nmalloc[_N_LISTS]; + } _unused; + } _new; + +# ifndef _REENT_GLOBAL_ATEXIT + /* atexit stuff */ + struct _atexit *_atexit; /* points to head of LIFO stack */ + struct _atexit _atexit0; /* one guaranteed table, required by ANSI */ +# endif + + /* signal info */ + void (**(_sig_func))(int); + + /* These are here last so that __FILE can grow without changing the offsets + of the above members (on the off chance that future binary compatibility + would be broken otherwise). */ + struct _glue __sglue; /* root of glue chain */ +# ifndef _REENT_GLOBAL_STDIO_STREAMS + __FILE __sf[3]; /* first three file descriptors */ +# endif +}; + +#ifdef _REENT_GLOBAL_STDIO_STREAMS +extern __FILE __sf[3]; +#define _REENT_STDIO_STREAM(var, index) &__sf[index] +#else +#define _REENT_STDIO_STREAM(var, index) &(var)->__sf[index] +#endif + +#define _REENT_INIT(var) \ + { 0, \ + _REENT_STDIO_STREAM(&(var), 0), \ + _REENT_STDIO_STREAM(&(var), 1), \ + _REENT_STDIO_STREAM(&(var), 2), \ + 0, \ + "", \ + 0, \ + _NULL, \ + 0, \ + _NULL, \ + _NULL, \ + 0, \ + _NULL, \ + _NULL, \ + 0, \ + _NULL, \ + { \ + { \ + 0, \ + _NULL, \ + "", \ + {0, 0, 0, 0, 0, 0, 0, 0, 0}, \ + 0, \ + 1, \ + { \ + {_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \ + {_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, \ + _RAND48_ADD \ + }, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}}, \ + "", \ + "", \ + 0, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}}, \ + {0, {0}} \ + } \ + }, \ + _REENT_INIT_ATEXIT \ + _NULL, \ + {_NULL, 0, _NULL} \ + } + +#define _REENT_INIT_PTR_ZEROED(var) \ + { (var)->_stdin = _REENT_STDIO_STREAM(var, 0); \ + (var)->_stdout = _REENT_STDIO_STREAM(var, 1); \ + (var)->_stderr = _REENT_STDIO_STREAM(var, 2); \ + (var)->_new._reent._rand_next = 1; \ + (var)->_new._reent._r48._seed[0] = _RAND48_SEED_0; \ + (var)->_new._reent._r48._seed[1] = _RAND48_SEED_1; \ + (var)->_new._reent._r48._seed[2] = _RAND48_SEED_2; \ + (var)->_new._reent._r48._mult[0] = _RAND48_MULT_0; \ + (var)->_new._reent._r48._mult[1] = _RAND48_MULT_1; \ + (var)->_new._reent._r48._mult[2] = _RAND48_MULT_2; \ + (var)->_new._reent._r48._add = _RAND48_ADD; \ + } + +#define _REENT_CHECK_RAND48(ptr) /* nothing */ +#define _REENT_CHECK_MP(ptr) /* nothing */ +#define _REENT_CHECK_TM(ptr) /* nothing */ +#define _REENT_CHECK_ASCTIME_BUF(ptr) /* nothing */ +#define _REENT_CHECK_EMERGENCY(ptr) /* nothing */ +#define _REENT_CHECK_MISC(ptr) /* nothing */ +#define _REENT_CHECK_SIGNAL_BUF(ptr) /* nothing */ + +#define _REENT_SIGNGAM(ptr) ((ptr)->_new._reent._gamma_signgam) +#define _REENT_RAND_NEXT(ptr) ((ptr)->_new._reent._rand_next) +#define _REENT_RAND48_SEED(ptr) ((ptr)->_new._reent._r48._seed) +#define _REENT_RAND48_MULT(ptr) ((ptr)->_new._reent._r48._mult) +#define _REENT_RAND48_ADD(ptr) ((ptr)->_new._reent._r48._add) +#define _REENT_MP_RESULT(ptr) ((ptr)->_result) +#define _REENT_MP_RESULT_K(ptr) ((ptr)->_result_k) +#define _REENT_MP_P5S(ptr) ((ptr)->_p5s) +#define _REENT_MP_FREELIST(ptr) ((ptr)->_freelist) +#define _REENT_ASCTIME_BUF(ptr) ((ptr)->_new._reent._asctime_buf) +#define _REENT_TM(ptr) (&(ptr)->_new._reent._localtime_buf) +#define _REENT_EMERGENCY(ptr) ((ptr)->_emergency) +#define _REENT_STRTOK_LAST(ptr) ((ptr)->_new._reent._strtok_last) +#define _REENT_MBLEN_STATE(ptr) ((ptr)->_new._reent._mblen_state) +#define _REENT_MBTOWC_STATE(ptr)((ptr)->_new._reent._mbtowc_state) +#define _REENT_WCTOMB_STATE(ptr)((ptr)->_new._reent._wctomb_state) +#define _REENT_MBRLEN_STATE(ptr)((ptr)->_new._reent._mbrlen_state) +#define _REENT_MBRTOWC_STATE(ptr)((ptr)->_new._reent._mbrtowc_state) +#define _REENT_MBSRTOWCS_STATE(ptr)((ptr)->_new._reent._mbsrtowcs_state) +#define _REENT_WCRTOMB_STATE(ptr)((ptr)->_new._reent._wcrtomb_state) +#define _REENT_WCSRTOMBS_STATE(ptr)((ptr)->_new._reent._wcsrtombs_state) +#define _REENT_L64A_BUF(ptr) ((ptr)->_new._reent._l64a_buf) +#define _REENT_SIGNAL_BUF(ptr) ((ptr)->_new._reent._signal_buf) +#define _REENT_GETDATE_ERR_P(ptr) (&((ptr)->_new._reent._getdate_err)) + +#endif /* !_REENT_SMALL */ + +#define _REENT_INIT_PTR(var) \ + { memset((var), 0, sizeof(*(var))); \ + _REENT_INIT_PTR_ZEROED(var); \ + } + +/* This value is used in stdlib/misc.c. reent/reent.c has to know it + as well to make sure the freelist is correctly free'd. Therefore + we define it here, rather than in stdlib/misc.c, as before. */ +#define _Kmax (sizeof (size_t) << 3) + +/* + * All references to struct _reent are via this pointer. + * Internally, newlib routines that need to reference it should use _REENT. + */ + +#ifndef __ATTRIBUTE_IMPURE_PTR__ +#define __ATTRIBUTE_IMPURE_PTR__ +#endif + +extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__; +extern struct _reent *const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__; + +__stdargs void _reclaim_reent (struct _reent *); + +/* #define _REENT_ONLY define this to get only reentrant routines */ + +#if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__) +#ifndef __getreent + __stdargs struct _reent * __getreent (void); +#endif +# define _REENT (__getreent()) +#else /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */ +# define _REENT _impure_ptr +#endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */ + +#define _GLOBAL_REENT _global_impure_ptr + +#ifdef _REENT_GLOBAL_ATEXIT +extern struct _atexit *_global_atexit; /* points to head of LIFO stack */ +# define _GLOBAL_ATEXIT _global_atexit +#else +# define _GLOBAL_ATEXIT (_GLOBAL_REENT->_atexit) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _SYS_REENT_H_ */ diff --git a/sys-include/time.h b/sys-include/time.h index 752ed59..68c2784 100644 --- a/sys-include/time.h +++ b/sys-include/time.h @@ -34,10 +34,6 @@ _BEGIN_STD_C -#ifndef __stdargs -#define __stdargs -#endif - struct tm { int tm_sec; @@ -153,19 +149,19 @@ __stdargs int getdate_r (const char *, struct tm *); #endif /* __GNU_VISIBLE */ #endif /* HAVE_GETDATE */ -/* defines for the opengroup specifications Derived from Issue 1 of the SVID. */ -#if __SVID_VISIBLE || __XSI_VISIBLE -extern __IMPORT long _timezone; -extern __IMPORT int _daylight; -#endif -#if __POSIX_VISIBLE -extern __IMPORT char *_tzname[2]; +extern long * __timezone; +extern int * __daylight; +extern char **__tzname; -/* POSIX defines the external tzname being defined in time.h */ +//#define timezone (*__timezone) +#define daylight (*__daylight) +#define _timezone (*__timezone) +#define _daylight (*__daylight) + +#define _tzname (*__tzname) #ifndef tzname -#define tzname _tzname +#define tzname (*__tzname) #endif -#endif /* __POSIX_VISIBLE */ #ifdef __cplusplus } @@ -177,6 +173,12 @@ extern __IMPORT char *_tzname[2]; #include #endif /*__CYGWIN__*/ +/* Clocks, P1003.1b-1993, p. 263 */ + +//__stdargs int clock_settime (clockid_t clock_id, const struct timespec *tp); +__stdargs int clock_gettime (clockid_t clock_id, struct timespec *tp); +__stdargs int clock_getres (clockid_t clock_id, struct timespec *res); + #if defined(_POSIX_TIMERS) #include @@ -185,11 +187,7 @@ extern __IMPORT char *_tzname[2]; extern "C" { #endif -/* Clocks, P1003.1b-1993, p. 263 */ -__stdargs int clock_settime (clockid_t clock_id, const struct timespec *tp); -__stdargs int clock_gettime (clockid_t clock_id, struct timespec *tp); -__stdargs int clock_getres (clockid_t clock_id, struct timespec *res); /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */ @@ -284,7 +282,7 @@ extern "C" { #endif -#if defined(_POSIX_MONOTONIC_CLOCK) +#if 1 //defined(_POSIX_MONOTONIC_CLOCK) /* The identifier for the system-wide monotonic clock, which is defined * as a clock whose value cannot be set via clock_settime() and which @@ -311,6 +309,15 @@ __stdargs int clock_getenable_attr (clockid_t clock_id, int *attr); #endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */ +#if !__BSD_VISIBLE +#ifndef timeradd +void timeradd(struct timeval *a, struct timeval *b, struct timeval *res); +#endif +#ifndef timersub +void timersub(struct timeval *a, struct timeval *b, struct timeval *res); +#endif +#endif + #ifdef __cplusplus } #endif