diff --git a/reactos/lib/crtdll/ctype/isalnum.c b/reactos/lib/crtdll/ctype/isalnum.c index 4c1afc9646c..1dbdbf92293 100644 --- a/reactos/lib/crtdll/ctype/isalnum.c +++ b/reactos/lib/crtdll/ctype/isalnum.c @@ -1,16 +1,23 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries - * FILE: lib/crtdll/conio/putch.c - * PURPOSE: Writes a character to stdout + * FILE: lib/crtdll/ctype/isalnum.c + * PURPOSE: Test for a alpha numeric character * PROGRAMER: Boudewijn Dekker * UPDATE HISTORY: * 28/12/98: Created */ #include + #undef isalnum int isalnum(int c) { - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')); + return _isctype(c,_ALPHA | _DIGIT); +} + +#undef iswalnum +int iswalnum(wint_t c) +{ + return iswctype(c,_ALPHA | _DIGIT); } diff --git a/reactos/lib/crtdll/ctype/isalpha.c b/reactos/lib/crtdll/ctype/isalpha.c index bbca268a25a..2e8a2982105 100644 --- a/reactos/lib/crtdll/ctype/isalpha.c +++ b/reactos/lib/crtdll/ctype/isalpha.c @@ -13,5 +13,11 @@ #undef isalpha int isalpha(int c) { - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); + return _isctype(c,_ALPHA); +} + +#undef iswalpha +int iswalpha(int c) +{ + return iswctype(c,_ALPHA); } diff --git a/reactos/lib/crtdll/ctype/isascii.c b/reactos/lib/crtdll/ctype/isascii.c index 1fbfc3f5b3b..3aefae82222 100644 --- a/reactos/lib/crtdll/ctype/isascii.c +++ b/reactos/lib/crtdll/ctype/isascii.c @@ -10,15 +10,14 @@ #include -#undef isascii -int isascii(int c) -{ - return ( (unsigned)(c) <0x80 ) ; -} - int __isascii(int c) { - return ( (unsigned)(c) <0x80 ) ; + return (!((c)&(~0x7f))) ; +} + +int iswascii(int c) +{ + return __isascii(c); } diff --git a/reactos/lib/crtdll/ctype/iscntrl.c b/reactos/lib/crtdll/ctype/iscntrl.c index 78739e25c49..e44f34c88e9 100644 --- a/reactos/lib/crtdll/ctype/iscntrl.c +++ b/reactos/lib/crtdll/ctype/iscntrl.c @@ -4,5 +4,11 @@ #undef iscntrl int iscntrl(int c) { - return ((c >=0x00 && c <= 0x1f) || c == 0x7f) ; + return _isctype(c,_CONTROL); +} + +#undef iswcntrl +int iswcntrl(int c) +{ + return iswctype(c,_CONTROL); } diff --git a/reactos/lib/crtdll/ctype/iscsym.c b/reactos/lib/crtdll/ctype/iscsym.c index 8a2d6aff730..702b4fa8728 100644 --- a/reactos/lib/crtdll/ctype/iscsym.c +++ b/reactos/lib/crtdll/ctype/iscsym.c @@ -1,9 +1,8 @@ - /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/crtdll/ctype/iscsym.c - * PURPOSE: Writes a character to stdout + * PURPOSE: Check for a valid characters in a c symbol * PROGRAMER: Boudewijn Dekker * UPDATE HISTORY: * 28/12/98: Created @@ -11,30 +10,12 @@ #include -#undef iscsym -int -iscsym (int c) +int __iscsymf(int c) { - return __iscsym(c); + return (isalpha(c) || ( c == '_' )) ; } -int -__iscsym (int c) +int __iscsym(int c) { - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || ( c == '_' ); -} - -#undef iscsymf -int -iscsymf (int c) -{ - return __iscsymf(c); -} - -int -__iscsymf (int c) -{ - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || ( c == '_' ); -} - - + return (isalnum(c) || ( c == '_' )) ; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/ctype/isctype.c b/reactos/lib/crtdll/ctype/isctype.c index a8867a8dd29..e5c07913d1a 100644 --- a/reactos/lib/crtdll/ctype/isctype.c +++ b/reactos/lib/crtdll/ctype/isctype.c @@ -1,24 +1,25 @@ - +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include +#define __dj_ISUPPER _UPPER +#define __dj_ISLOWER _LOWER +#define __dj_ISDIGIT _DIGIT +#define __dj_ISSPACE _SPACE +#define __dj_ISPUNCT _PUNCT +#define __dj_ISCNTRL _CONTROL +#define __dj_ISBLANK _BLANK +#define __dj_ISXDIGIT _HEX +#define __dj_ISALPHA _ALPHA +#define __dj_ISPRINT _PRINT +#define __dj_ISALNUM ( _ALPHA | _DIGIT ) +#define __dj_ISGRAPH _GRAPH -#define __dj_ISUPPER 0x1 -#define __dj_ISLOWER 0x2 -#define __dj_ISDIGIT 0x4 -#define __dj_ISSPACE 0x8 -#define __dj_ISPUNCT 0x10 -#define __dj_ISCNTRL 0x20 -#define __dj_ISBLANK 0x40 -#define __dj_ISXDIGIT 0x80 -#define __dj_ISPRINT (__dj_ISBLANK|__dj_ISPUNCT|__dj_ISUPPER|__dj_ISLOWER|__dj_ISDIGIT) -#define __dj_ISALNUM (__dj_ISUPPER|__dj_ISLOWER|__dj_ISDIGIT) -#define __dj_ISGRAPH (__dj_ISPUNCT|__dj_ISUPPER|__dj_ISLOWER|__dj_ISDIGIT) -#define __dj_ISALPHA (0x0100|__dj_ISUPPER|__dj_ISLOWER) +int __mb_cur_max = 2; +// removed the first value -unsigned short __dj_ctype_flags[] = { - 0, /* CTRL+?, 0xffff */ +unsigned short _pctype_dll[] = { __dj_ISCNTRL, /* CTRL+@, 0x00 */ __dj_ISCNTRL, /* CTRL+A, 0x01 */ __dj_ISCNTRL, /* CTRL+B, 0x02 */ @@ -277,14 +278,27 @@ unsigned short __dj_ctype_flags[] = { 0, /* 0xff */ }; +unsigned short *_ctype = _pctype_dll -1; // unused +unsigned short *_pwctype_dll = _pctype_dll; -int _isctype(int c, int t) +int _isctype(unsigned char c, int t) { - return (__dj_ctype_flags[(c & 0xFF)]&t == t ); + return ((_pctype_dll[(c & 0xFF)]&t) == t ); +} + +int iswctype(unsigned short c, int t) +{ + + return ((_pwctype_dll[(c & 0xFF)]&t) == t ); +} + +// obsolete +int is_wctype(unsigned short c, int t) +{ + + return ((_pctype_dll[(c & 0xFF)]&t) == t ); } -unsigned short *_pctype = __dj_ctype_flags; -int __mb_cur_max = 2; \ No newline at end of file diff --git a/reactos/lib/crtdll/ctype/isdigit.c b/reactos/lib/crtdll/ctype/isdigit.c index e8228959eaa..b0ad5a085dc 100644 --- a/reactos/lib/crtdll/ctype/isdigit.c +++ b/reactos/lib/crtdll/ctype/isdigit.c @@ -4,5 +4,11 @@ #undef isdigit int isdigit(int c) { - return (c >= '0' && c <= '9'); + return _isctype(c,_DIGIT); +} + +#undef iswdigit +int iswdigit(int c) +{ + return iswctype(c,_DIGIT); } diff --git a/reactos/lib/crtdll/ctype/isgraph.c b/reactos/lib/crtdll/ctype/isgraph.c index be8233f5177..ade3e1bee6d 100644 --- a/reactos/lib/crtdll/ctype/isgraph.c +++ b/reactos/lib/crtdll/ctype/isgraph.c @@ -4,5 +4,11 @@ #undef isgraph int isgraph(int c) { - return 0; + return _isctype(c,_GRAPH); +} + +#undef iswgraph +int iswgraph(int c) +{ + return iswctype(c,_GRAPH); } diff --git a/reactos/lib/crtdll/ctype/islower.c b/reactos/lib/crtdll/ctype/islower.c index 99e9eea98a0..122e7d09e16 100644 --- a/reactos/lib/crtdll/ctype/islower.c +++ b/reactos/lib/crtdll/ctype/islower.c @@ -4,5 +4,10 @@ #undef islower int islower(int c) { - return (c >= 'a' && c <= 'z'); + return _isctype((unsigned char)c,_LOWER); } + +int iswlower(int c) +{ + return iswctype((unsigned short)c,_LOWER); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/ctype/isprint.c b/reactos/lib/crtdll/ctype/isprint.c index 2e899744237..1f7b467852f 100644 --- a/reactos/lib/crtdll/ctype/isprint.c +++ b/reactos/lib/crtdll/ctype/isprint.c @@ -4,5 +4,10 @@ #undef isprint int isprint(int c) { - return c; + return _isctype((unsigned char)c,_PRINT); } + +int iswprint(int c) +{ + return iswctype((unsigned short)c,_PRINT); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/ctype/ispunct.c b/reactos/lib/crtdll/ctype/ispunct.c index b3e8399c7fd..152cb52f5fe 100644 --- a/reactos/lib/crtdll/ctype/ispunct.c +++ b/reactos/lib/crtdll/ctype/ispunct.c @@ -4,5 +4,11 @@ #undef ispunct int ispunct(int c) { - return (c == '.'); + return _isctype(c,_PUNCT); +} + +#undef iswpunct +int iswpunct(int c) +{ + return iswctype(c,_PUNCT); } diff --git a/reactos/lib/crtdll/ctype/isspace.c b/reactos/lib/crtdll/ctype/isspace.c index 605a86ebaa6..b884c2c0f90 100644 --- a/reactos/lib/crtdll/ctype/isspace.c +++ b/reactos/lib/crtdll/ctype/isspace.c @@ -1,8 +1,22 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/ctype/isspace.c + * PURPOSE: Test for a space character + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Created + */ #include #undef isspace int isspace(int c) { - return ( c == ' ' || c == '\t' ); + return _isctype((unsigned char)c,_SPACE); +} + +#undef iswspace +int iswspace(int c) +{ + return iswctype((unsigned short)c,_SPACE); } diff --git a/reactos/lib/crtdll/ctype/isupper.c b/reactos/lib/crtdll/ctype/isupper.c index 2b1c09f0514..a6a5db8509a 100644 --- a/reactos/lib/crtdll/ctype/isupper.c +++ b/reactos/lib/crtdll/ctype/isupper.c @@ -4,5 +4,10 @@ #undef isupper int isupper(int c) { - return (c >= 'A' && c <= 'Z' ); + return _isctype(c,_UPPER); +} + +int iswupper(int c) +{ + return iswctype(c,_UPPER); } diff --git a/reactos/lib/crtdll/ctype/isxdigit.c b/reactos/lib/crtdll/ctype/isxdigit.c index 3123107eae4..8c4c3090d3b 100644 --- a/reactos/lib/crtdll/ctype/isxdigit.c +++ b/reactos/lib/crtdll/ctype/isxdigit.c @@ -4,5 +4,12 @@ #undef isxdigit int isxdigit(int c) { - return (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || ( c >= '0' && c >= '9' ); + return _isctype(c,_HEX); } + +#undef iswxdigit +int iswxdigit(int c) +{ + return iswctype(c,_HEX); +} + diff --git a/reactos/lib/crtdll/ctype/toascii.c b/reactos/lib/crtdll/ctype/toascii.c index b7d4a6e9fb1..b19b799f854 100644 --- a/reactos/lib/crtdll/ctype/toascii.c +++ b/reactos/lib/crtdll/ctype/toascii.c @@ -2,13 +2,8 @@ #include -#undef toascii -int toascii(int c) -{ - return (c); -} int __toascii(int c) { - return (c); + return ((unsigned)(c) & 0x7F ); } diff --git a/reactos/lib/crtdll/ctype/tolower.c b/reactos/lib/crtdll/ctype/tolower.c index 760a8b98253..80d8cd0506d 100644 --- a/reactos/lib/crtdll/ctype/tolower.c +++ b/reactos/lib/crtdll/ctype/tolower.c @@ -5,3 +5,21 @@ int tolower(int c) { return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c; } +#undef towlower +wchar_t towlower(wchar_t c) +{ + return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c; +} + +int _tolower(int c) +{ + return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c; +} + +wchar_t _towlower(wchar_t c) +{ + return (c >= 'A' && c <= 'Z') ? c - ( 'A' - 'a' ) : c; +} + + + diff --git a/reactos/lib/crtdll/ctype/toupper.c b/reactos/lib/crtdll/ctype/toupper.c index c0eaefbb8a7..693b12dd2ab 100644 --- a/reactos/lib/crtdll/ctype/toupper.c +++ b/reactos/lib/crtdll/ctype/toupper.c @@ -6,3 +6,18 @@ int toupper(int c) { return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; } +#undef towupper +int towupper(int c) +{ + return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; +} + +int _toupper(int c) +{ + return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; +} + +int _towupper(int c) +{ + return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; +} diff --git a/reactos/lib/crtdll/float/clearfp.c b/reactos/lib/crtdll/float/clearfp.c new file mode 100644 index 00000000000..5b490f208eb --- /dev/null +++ b/reactos/lib/crtdll/float/clearfp.c @@ -0,0 +1,13 @@ +#include + +unsigned int _clearfp (void) +{ + +unsigned short __res = _statusfp(); + +__asm__ __volatile__ ( + "fclex \n\t" + ); + return __res; +} + diff --git a/reactos/lib/crtdll/float/cntrlfp.c b/reactos/lib/crtdll/float/cntrlfp.c new file mode 100644 index 00000000000..6167bed9aa5 --- /dev/null +++ b/reactos/lib/crtdll/float/cntrlfp.c @@ -0,0 +1,37 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ + +#include + +unsigned int _controlfp (unsigned int unNew, unsigned int unMask) +{ + return _control87(unNew,unMask); +} + +unsigned int _control87 (unsigned int unNew, unsigned int unMask) +{ + +register unsigned int __res; +__asm__ __volatile__ ( + "pushl %%eax \n\t" /* make room on stack */ + "fstcw (%%esp) \n\t" + "fwait \n\t" + "popl %%eax \n\t" + "andl $0xffff, %%eax \n\t" /* OK; we have the old value ready */ + + "movl %1, %%ecx \n\t" + "notl %%ecx \n\t" + "andl %%eax, %%ecx \n\t" /* the bits we want to keep */ + + "movl %2, %%edx \n\t" + "andl %1, %%edx \n\t" /* the bits we want to change */ + + "orl %%ecx, %%edx\n\t" /* the new value */ + "pushl %%edx \n\t" + "fldcw (%%esp) \n\t" + "popl %%edx \n\t" + + + :"=a" (__res):"c" (unNew),"d" (unMask):"ax", "dx", "cx"); + + return __res; +} diff --git a/reactos/lib/crtdll/float/fpreset.c b/reactos/lib/crtdll/float/fpreset.c index 384ecfcd7a7..76acba8b841 100644 --- a/reactos/lib/crtdll/float/fpreset.c +++ b/reactos/lib/crtdll/float/fpreset.c @@ -1,7 +1,7 @@ #include -void _fpreset( void ) +void _fpreset (void) { + __asm__ __volatile__("fninit\n\t"); return; -} - +} \ No newline at end of file diff --git a/reactos/lib/crtdll/float/statfp.c b/reactos/lib/crtdll/float/statfp.c new file mode 100644 index 00000000000..0786a7e0dc2 --- /dev/null +++ b/reactos/lib/crtdll/float/statfp.c @@ -0,0 +1,14 @@ +#include + +unsigned int _statusfp (void) +{ + +register unsigned short __res; + +__asm__ __volatile__ ( + "fstsw %0 \n\t" +// "movzwl %ax, %eax" + :"=a" (__res) + ); + return __res; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/io/chmod.c b/reactos/lib/crtdll/io/chmod.c index 67f3fd1f571..ff5d6966db2 100644 --- a/reactos/lib/crtdll/io/chmod.c +++ b/reactos/lib/crtdll/io/chmod.c @@ -4,7 +4,7 @@ int _chmod(const char *filename, int func) { - DWROD FileAttributes = 0; + DWORD FileAttributes = 0; if ( func == _S_IREAD ) FileAttributes &= FILE_ATTRIBUTE_READONLY; if ( ((func & _S_IREAD) == _S_IREAD) && ((func & _S_IWRITE) == _S_IWRITE) ) diff --git a/reactos/lib/crtdll/io/commit.c b/reactos/lib/crtdll/io/commit.c index 3320b75d2c1..5c353ca883a 100644 --- a/reactos/lib/crtdll/io/commit.c +++ b/reactos/lib/crtdll/io/commit.c @@ -1,7 +1,10 @@ #include #include -unsigned int _commit(int _fd) +int _commit(int _fd) { - return FlushFileBuffers(_get_osfhandle(_fd)) ? 0 : GetLastError(); + if (! FlushFileBuffers(_get_osfhandle(_fd)) ) + return -1; + + return 0; } diff --git a/reactos/lib/crtdll/io/eof.c b/reactos/lib/crtdll/io/eof.c index 622ec48c553..385f5eda2bb 100644 --- a/reactos/lib/crtdll/io/eof.c +++ b/reactos/lib/crtdll/io/eof.c @@ -3,5 +3,17 @@ int _eof( int _fd ) { + int cur_pos = _lseek(_fd, 0, SEEK_CUR); + int end_pos = _filelength( _fd ); + if ( cur_pos == -1 || end_pos == -1) + return -1; + + if ( cur_pos == end_pos ) + return 1; + return 0; + + + + } diff --git a/reactos/lib/crtdll/io/open.c b/reactos/lib/crtdll/io/open.c index 5aba4441b5b..e17f5378b8e 100644 --- a/reactos/lib/crtdll/io/open.c +++ b/reactos/lib/crtdll/io/open.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries - * FILE: lib/crtdll/conio/cputs.c + * FILE: lib/crtdll/io/open.c * PURPOSE: Opens a file and translates handles to fileno * PROGRAMER: Boudewijn Dekker * UPDATE HISTORY: @@ -36,10 +36,6 @@ char __is_text_file(FILE *p) { - -int __fileno_alloc(HANDLE hFile, int mode); - - int _open(const char *_path, int _oflag,...) { @@ -133,7 +129,7 @@ __fileno_alloc(HANDLE hFile, int mode) for(i=minfno;i #include +#include + int _pipe(int _fildes[2], unsigned int size, int mode ) -{ - return -1; +{ + HANDLE hReadPipe, hWritePipe; + + if ( !CreatePipe(&hReadPipe,&hWritePipe,NULL,size)) + return -1; + + _fildes[0] = __fileno_alloc(hReadPipe, mode); + _fildes[1] = __fileno_alloc(hWritePipe, mode); + + return 0; } diff --git a/reactos/lib/crtdll/makefile b/reactos/lib/crtdll/makefile index a2df591107f..02dbbd3bd09 100644 --- a/reactos/lib/crtdll/makefile +++ b/reactos/lib/crtdll/makefile @@ -2,16 +2,18 @@ all: crtdll.a -CTYPE_OBJECTS = ctype/ct_flags.o ctype/ct_lower.o ctype/ct_upper.o ctype/isalnum.o \ +CTYPE_OBJECTS = ctype/isalnum.o \ ctype/isalpha.o ctype/isascii.o ctype/iscntrl.o ctype/isdigit.o ctype/isgraph.o \ ctype/islower.o ctype/isprint.o ctype/ispunct.o ctype/isspace.o ctype/isupper.o \ - ctype/isxdigit.o ctype/toascii.o ctype/tolower.o ctype/toupper.o + ctype/isxdigit.o ctype/toascii.o ctype/tolower.o ctype/toupper.o\ + ctype/iscsym.o ctype/isctype.o CONIO_OBJECTS = conio/cputs.o conio/getch.o conio/getche.o conio/putch.o conio/ungetch.o DIRECT_OBJECTS = direct/chdir.o direct/chdrive.o direct/getcwd.o direct/getdrive.o \ direct/rmdir.o direct/mkdir.o direct/getdfree.o + MISC_OBJECTS = misc/sleep.o misc/getargs.o misc/crtfmode.o misc/crtglob.o STRING_OBJECTS = string/memchr.o string/memcmp.o string/strcat.o \ @@ -46,7 +48,9 @@ STDIO_OBJECTS = stdio/getenv.o stdio/doprnt.o stdio/doscan.o stdio/filbuf.o \ IO_OBJECTS = io/access.o io/close.o io/create.o io/dup.o io/dup2.o io/find.o io/isatty.o io/lseek.o \ - io/open.o io/read.o io/setmode.o io/unlink.o io/write.o io/fmode.o io/mktemp.o + io/open.o io/read.o io/setmode.o io/unlink.o io/write.o io/fmode.o io/mktemp.o\ + io/chmod.o io/chsize.o io/commit.o io/locking.o io/pipe.o io/sopen.o io/filelen.o\ + io/umask.o io/tell.o io/eof.o STDLIB_OBJECTS = stdlib/abort.o stdlib/abs.o stdlib/atexit.o stdlib/atof.o stdlib/atoi.o stdlib/atold.o \ stdlib/bsearch.o stdlib/div.o stdlib/errno.o stdlib/exit.o \ @@ -55,22 +59,30 @@ STDLIB_OBJECTS = stdlib/abort.o stdlib/abs.o stdlib/atexit.o stdlib/atof.o stdli stdlib/rand.o stdlib/senv.o stdlib/splitp.o stdlib/strtod.o stdlib/strtol.o \ stdlib/strtoul.o stdlib/strtold.o -PROCESS_OBJECTS = process/spawnl.o process/spawnlp.o process/spawnlpe.o process/spawnvpe.o process/spawnvp.o \ +SIGNAL_OBJECTS = signal/signal.o + +PROCESS_OBJECTS = process/cwait.o process/dll.o process/spawnl.o process/spawnlp.o process/spawnlpe.o process/spawnvpe.o process/spawnvp.o \ process/spawnv.o process/spawnve.o process/spawnle.o process/execl.o process/execlp.o process/execlpe.o \ process/execvpe.o process/execvp.o process/execv.o process/execle.o TIME_OBJECTS = time/ctime.o time/difftime.o time/strftime.o -FLOAT_OBJECTS = float/fpreset.o +FLOAT_OBJECTS = float/fpreset.o float/clearfp.o float/cntrlfp.o float/statfp.o SYS_STAT_OBJECTS = sys_stat/fstat.o sys_stat/stat.o +MATH_OBJECTS = math/acos.o math/acosh.o math/asin.o math/asinh.o math/atan.o math/atan2.o\ + math/atanh.o math/ceil.o math/cos.o math/cosh.o math/exp.o math/fabs.o\ + math/floor.o math/fmod.o math/frexp.o math/huge_val.o math/hypot.o\ + math/ldexp.o math/log.o math/log10.o math/modf.o math/modfl.o math/pow.o\ + math/pow10.o math/pow2.o math/sin.o math/sinh.o math/sqrt.o math/tan.o\ + math/tanh.o OBJECTS = $(CTYPE_OBJECTS) $(CONIO_OBJECTS) $(DIRECT_OBJECTS) $(MISC_OBJECTS) \ $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) \ - $(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) $(FLOAT_OBJECTS) \ - $(SYS_STAT_OBJECTS) + $(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) \ + $(SYS_STAT_OBJECTS) $(SIGNAL_OBJECTS) $(MATH_OBJECTS) $(FLOAT_OBJECTS) crtdll.a: $(OBJECTS) diff --git a/reactos/lib/crtdll/math/acos.S b/reactos/lib/crtdll/math/acos.S new file mode 100644 index 00000000000..67624bc76ea --- /dev/null +++ b/reactos/lib/crtdll/math/acos.S @@ -0,0 +1,22 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .text +LC0: + .double 0d1.00000000000000000000e+00 + + .globl _acos +_acos: + fldl 4(%esp) + fld1 + fsubp %st(0),%st(1) + fsqrt + + fldl 4(%esp) + fld1 + faddp %st(0),%st(1) + fsqrt + + fpatan + + fld %st(0) + faddp + ret diff --git a/reactos/lib/crtdll/math/acosh.c b/reactos/lib/crtdll/math/acosh.c new file mode 100644 index 00000000000..6e13bbe6ec6 --- /dev/null +++ b/reactos/lib/crtdll/math/acosh.c @@ -0,0 +1,8 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double +acosh(double x) +{ + return log(x + sqrt(x*x - 1)); +} diff --git a/reactos/lib/crtdll/math/asin.S b/reactos/lib/crtdll/math/asin.S new file mode 100644 index 00000000000..ee04df6de05 --- /dev/null +++ b/reactos/lib/crtdll/math/asin.S @@ -0,0 +1,14 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .globl _asin +_asin: + fldl 4(%esp) + fld %st(0) + fmulp + fld1 + fsubp + fsqrt + fldl 4(%esp) + fxch %st(1) + fpatan + ret + diff --git a/reactos/lib/crtdll/math/asinh.c b/reactos/lib/crtdll/math/asinh.c new file mode 100644 index 00000000000..e27e20da7ed --- /dev/null +++ b/reactos/lib/crtdll/math/asinh.c @@ -0,0 +1,9 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double +asinh(double x) +{ + return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x); +} + diff --git a/reactos/lib/crtdll/math/atan.S b/reactos/lib/crtdll/math/atan.S new file mode 100644 index 00000000000..7858c76f695 --- /dev/null +++ b/reactos/lib/crtdll/math/atan.S @@ -0,0 +1,8 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .globl _atan +_atan: + fldl 4(%esp) + fld1 + fpatan + ret + diff --git a/reactos/lib/crtdll/math/atan2.S b/reactos/lib/crtdll/math/atan2.S new file mode 100644 index 00000000000..40e6332b30d --- /dev/null +++ b/reactos/lib/crtdll/math/atan2.S @@ -0,0 +1,35 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +.data + .align 2 +nan: + .long 0xffffffff + .byte 0xff + .byte 0xff + .byte 0xff + .byte 0x7f + +.text + .globl _atan2 +_atan2: + fldl 4(%esp) + fldl 12(%esp) + ftst + fnstsw %ax + sahf + jne doit + fxch %st(1) + ftst + fnstsw %ax + sahf + je isanan + fxch %st(1) +doit: + fpatan + ret +isanan: + movl $1,_errno + fstp %st(0) + fstp %st(0) + fldl nan + ret + diff --git a/reactos/lib/crtdll/math/atanh.c b/reactos/lib/crtdll/math/atanh.c new file mode 100644 index 00000000000..8335dc78b3a --- /dev/null +++ b/reactos/lib/crtdll/math/atanh.c @@ -0,0 +1,8 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double +atanh(double x) +{ + return log((1+x)/(1-x)) / 2.0; +} diff --git a/reactos/lib/crtdll/math/ceil.S b/reactos/lib/crtdll/math/ceil.S new file mode 100644 index 00000000000..baa0923bd25 --- /dev/null +++ b/reactos/lib/crtdll/math/ceil.S @@ -0,0 +1,24 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ + .globl _ceil +_ceil: + pushl %ebp + movl %esp,%ebp + subl $8,%esp /* -4 = old CW, -2 = new CW */ + + fstcw -4(%ebp) + fwait + movw -4(%ebp),%ax + andw $0xf3ff,%ax + orw $0x0800,%ax + movw %ax,-2(%ebp) + fldcww -2(%ebp) + + fldl 8(%ebp) + frndint + + fldcww -4(%ebp) + + movl %ebp,%esp + popl %ebp + ret + diff --git a/reactos/lib/crtdll/math/cos.S b/reactos/lib/crtdll/math/cos.S new file mode 100644 index 00000000000..97b7418eace --- /dev/null +++ b/reactos/lib/crtdll/math/cos.S @@ -0,0 +1,16 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +L0: + .quad 0xffffffffffffffff + + .globl _cos +_cos: + fldl 4(%esp) + fcos + fstsw + sahf + jnp L1 + fstp %st(0) + fldl L0 +L1: + ret + diff --git a/reactos/lib/crtdll/math/cosh.c b/reactos/lib/crtdll/math/cosh.c new file mode 100644 index 00000000000..c2cca978ace --- /dev/null +++ b/reactos/lib/crtdll/math/cosh.c @@ -0,0 +1,8 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double cosh(double x) +{ + const double ebig = exp(fabs(x)); + return (ebig + 1.0/ebig) / 2.0; +} diff --git a/reactos/lib/crtdll/math/exp.S b/reactos/lib/crtdll/math/exp.S new file mode 100644 index 00000000000..d02cde075d8 --- /dev/null +++ b/reactos/lib/crtdll/math/exp.S @@ -0,0 +1,32 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .data +LCW1: + .word 0 +LCW2: + .word 0 +LC0: + .double 0d1.0e+00 + + .text + + .globl _exp +_exp: + fldl 4(%esp) + fldl2e + fmulp + fstcww LCW1 + fstcww LCW2 + fwait + andw $0xf3ff,LCW2 + orw $0x0400,LCW2 + fldcww LCW2 + fldl %st(0) + frndint + fldcww LCW1 + fxch %st(1) + fsub %st(1),%st + f2xm1 + faddl LC0 + fscale + fstp %st(1) + ret diff --git a/reactos/lib/crtdll/math/fabs.S b/reactos/lib/crtdll/math/fabs.S new file mode 100644 index 00000000000..0189dbaf61c --- /dev/null +++ b/reactos/lib/crtdll/math/fabs.S @@ -0,0 +1,6 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .globl _fabs +_fabs: + fldl 4(%esp) + fabs + ret diff --git a/reactos/lib/crtdll/math/floor.S b/reactos/lib/crtdll/math/floor.S new file mode 100644 index 00000000000..beaf00d7d63 --- /dev/null +++ b/reactos/lib/crtdll/math/floor.S @@ -0,0 +1,24 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ + .globl _floor +_floor: + pushl %ebp + movl %esp,%ebp + subl $8,%esp /* -4 = old CW, -2 = new CW */ + + fstcw -4(%ebp) + fwait + movw -4(%ebp),%ax + andw $0xf3ff,%ax + orw $0x0400,%ax + movw %ax,-2(%ebp) + fldcww -2(%ebp) + + fldl 8(%ebp) + frndint + + fldcww -4(%ebp) + + movl %ebp,%esp + popl %ebp + ret + diff --git a/reactos/lib/crtdll/math/fmod.S b/reactos/lib/crtdll/math/fmod.S new file mode 100644 index 00000000000..82eb419ecfb --- /dev/null +++ b/reactos/lib/crtdll/math/fmod.S @@ -0,0 +1,29 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .data +LCW1: + .word 0 + .align 4 + + .text + + .globl _fmod +_fmod: + fldl 4(%esp) + fldl 12(%esp) + ftst + fnstsw %ax + fxch %st(1) + sahf + jnz next + fstpl %st(0) + jmp out +next: + fpreml + fnstsw %ax + sahf + jpe next + fstpl %st(1) +out: + ret + + diff --git a/reactos/lib/crtdll/math/frexp.c b/reactos/lib/crtdll/math/frexp.c new file mode 100644 index 00000000000..913f16f06bd --- /dev/null +++ b/reactos/lib/crtdll/math/frexp.c @@ -0,0 +1,26 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double +frexp(double x, int *exptr) +{ + union { + double d; + unsigned char c[8]; + } u; + + u.d = x; + /* + * The format of the number is: + * Sign, 12 exponent bits, 51 mantissa bits + * The exponent is 1023 biased and there is an implicit zero. + * We get the exponent from the upper bits and set the exponent + * to 0x3fe (1022). + */ + *exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022; + u.c[7] &= 0x80; + u.c[7] |= 0x3f; + u.c[6] &= 0x0f; + u.c[6] |= 0xe0; + return u.d; +} diff --git a/reactos/lib/crtdll/math/huge_val.c b/reactos/lib/crtdll/math/huge_val.c new file mode 100644 index 00000000000..2fb55f2d7f7 --- /dev/null +++ b/reactos/lib/crtdll/math/huge_val.c @@ -0,0 +1,4 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double_t _HUGE_dll = { 0x00000, 0x00000, 0x7ff, 0x0 }; diff --git a/reactos/lib/crtdll/math/hypot.c b/reactos/lib/crtdll/math/hypot.c new file mode 100644 index 00000000000..9d0de607ca4 --- /dev/null +++ b/reactos/lib/crtdll/math/hypot.c @@ -0,0 +1,100 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +/* + * hypot() function for DJGPP. + * + * hypot() computes sqrt(x^2 + y^2). The problem with the obvious + * naive implementation is that it might fail for very large or + * very small arguments. For instance, for large x or y the result + * might overflow even if the value of the function should not, + * because squaring a large number might trigger an overflow. For + * very small numbers, their square might underflow and will be + * silently replaced by zero; this won't cause an exception, but might + * have an adverse effect on the accuracy of the result. + * + * This implementation tries to avoid the above pitfals, without + * inflicting too much of a performance hit. + * + */ + +#include +#include +#include + +/* Approximate square roots of DBL_MAX and DBL_MIN. Numbers + between these two shouldn't neither overflow nor underflow + when squared. */ +#define __SQRT_DBL_MAX 1.3e+154 +#define __SQRT_DBL_MIN 2.3e-162 + +double +hypot(double x, double y) +{ + double abig = fabs(x), asmall = fabs(y); + double ratio; + + /* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */ + if (abig < asmall) + { + double temp = abig; + + abig = asmall; + asmall = temp; + } + + /* Trivial case. */ + if (asmall == 0.) + return abig; + + /* Scale the numbers as much as possible by using its ratio. + For example, if both ABIG and ASMALL are VERY small, then + X^2 + Y^2 might be VERY inaccurate due to loss of + significant digits. Dividing ASMALL by ABIG scales them + to a certain degree, so that accuracy is better. */ + + if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX) + return abig * sqrt(1.0 + ratio*ratio); + else + { + /* Slower but safer algorithm due to Moler and Morrison. Never + produces any intermediate result greater than roughly the + larger of X and Y. Should converge to machine-precision + accuracy in 3 iterations. */ + + double r = ratio*ratio, t, s, p = abig, q = asmall; + + do { + t = 4. + r; + if (t == 4.) + break; + s = r / t; + p += 2. * s * p; + q *= s; + r = (q / p) * (q / p); + } while (1); + + return p; + } +} + +#ifdef TEST + +#include + +int +main(void) +{ + printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.)); + printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150)); + printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306)); + printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n", + hypot(3.e-320, 4.e-320)); + printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n", + hypot(0.7*DBL_MAX, 0.7*DBL_MAX)); + printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0)); + printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX)); + printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX)); + + return 0; +} + +#endif diff --git a/reactos/lib/crtdll/math/ldexp.c b/reactos/lib/crtdll/math/ldexp.c new file mode 100644 index 00000000000..818cab7578a --- /dev/null +++ b/reactos/lib/crtdll/math/ldexp.c @@ -0,0 +1,32 @@ +/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +#include + +double +ldexp(double v, int e) +{ + double two = 2.0; + + if (e < 0) + { + e = -e; /* This just might overflow on two-complement machines. */ + if (e < 0) return 0.0; + while (e > 0) + { + if (e & 1) v /= two; + two *= two; + e >>= 1; + } + } + else if (e > 0) + { + while (e > 0) + { + if (e & 1) v *= two; + two *= two; + e >>= 1; + } + } + return v; +} + diff --git a/reactos/lib/crtdll/math/log.S b/reactos/lib/crtdll/math/log.S new file mode 100644 index 00000000000..b45a9778635 --- /dev/null +++ b/reactos/lib/crtdll/math/log.S @@ -0,0 +1,7 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .globl _log +_log: + fldln2 + fldl 4(%esp) + fyl2x + ret diff --git a/reactos/lib/crtdll/math/log10.S b/reactos/lib/crtdll/math/log10.S new file mode 100644 index 00000000000..91b50ee5f50 --- /dev/null +++ b/reactos/lib/crtdll/math/log10.S @@ -0,0 +1,7 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .globl _log10 +_log10: + fldlg2 + fldl 4(%esp) + fyl2x + ret diff --git a/reactos/lib/crtdll/math/modf.S b/reactos/lib/crtdll/math/modf.S new file mode 100644 index 00000000000..db78db48edb --- /dev/null +++ b/reactos/lib/crtdll/math/modf.S @@ -0,0 +1,33 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .text + .globl _modf +_modf: + pushl %ebp + movl %esp,%ebp + subl $16,%esp + pushl %ebx + fnstcw -4(%ebp) + fwait + movw -4(%ebp),%ax + orw $0x0c3f,%ax + movw %ax,-8(%ebp) + fldcw -8(%ebp) + fwait + fldl 8(%ebp) + frndint + fstpl -16(%ebp) + fwait + movl -16(%ebp),%edx + movl -12(%ebp),%ecx + movl 16(%ebp),%ebx + movl %edx,(%ebx) + movl %ecx,4(%ebx) + fldl 8(%ebp) + fsubl -16(%ebp) + leal -20(%ebp),%esp + fclex + fldcw -4(%ebp) + fwait + popl %ebx + leave + ret diff --git a/reactos/lib/crtdll/math/modfl.S b/reactos/lib/crtdll/math/modfl.S new file mode 100644 index 00000000000..2257fee3e68 --- /dev/null +++ b/reactos/lib/crtdll/math/modfl.S @@ -0,0 +1,22 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .text + .globl ___modfl +___modfl: + pushl %ebp + movl %esp,%ebp + subl $4,%esp + fldt 8(%ebp) + movl 20(%ebp),%eax + fnstcw -2(%ebp) + movw -2(%ebp),%dx + orb $0x0c,%dh + movw %dx,-4(%ebp) + fldcw -4(%ebp) + fld %st(0) + frndint + fldcw -2(%ebp) + fld %st(0) + fstpt (%eax) + fsubrp %st,%st(1) + leave + ret diff --git a/reactos/lib/crtdll/math/pow.S b/reactos/lib/crtdll/math/pow.S new file mode 100644 index 00000000000..7a0da7c1539 --- /dev/null +++ b/reactos/lib/crtdll/math/pow.S @@ -0,0 +1,86 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .data +yint: + .word 0,0 +LCW1: + .word 0 +LCW2: + .word 0 + + .text +LC0: + .double 0d1.0e+00 + +frac: + fstcww LCW1 + fstcww LCW2 + fwait + andw $0xf3ff,LCW2 + orw $0x0400,LCW2 + fldcww LCW2 + fldl %st(0) + frndint + fldcww LCW1 + fxch %st(1) + fsub %st(1),%st + ret + +Lpow2: + call frac + f2xm1 + faddl LC0 + fscale + fstp %st(1) + ret + + .globl _pow +_pow: + fldl 12(%esp) + fldl 4(%esp) + ftst + fnstsww %ax + sahf + jbe xltez + fyl2x + jmp Lpow2 +xltez: + jb xltz + fstp %st(0) + ftst + fnstsww %ax + sahf + ja ygtz + jb error + fstp %st(0) + fld1l + fchs +error: + fsqrt + ret +ygtz: + fstp %st(0) + fldzl + ret +xltz: + fabs + fxch %st(1) + call frac + ftst + fnstsww %ax + fstp %st(0) + sahf + je yisint + fstp %st(0) + fchs + jmp error +yisint: + fistl yint + fxch %st(1) + fyl2x + call Lpow2 + andl $1,yint + jz yeven + fchs +yeven: + ret + diff --git a/reactos/lib/crtdll/math/pow10.S b/reactos/lib/crtdll/math/pow10.S new file mode 100644 index 00000000000..3a2236d9fb7 --- /dev/null +++ b/reactos/lib/crtdll/math/pow10.S @@ -0,0 +1,32 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .data +LCW1: + .word 0 +LCW2: + .word 0 +LC0: + .double 0d1.0e+00 + + .text + + .globl ___pow10 +___pow10: + fldl 4(%esp) + fldl2t + fmulp + fstcww LCW1 + fstcww LCW2 + fwait + andw $0xf3ff,LCW2 + orw $0x0400,LCW2 + fldcww LCW2 + fldl %st(0) + frndint + fldcww LCW1 + fxch %st(1) + fsub %st(1),%st + f2xm1 + faddl LC0 + fscale + fstp %st(1) + ret diff --git a/reactos/lib/crtdll/math/pow2.S b/reactos/lib/crtdll/math/pow2.S new file mode 100644 index 00000000000..1a747a86636 --- /dev/null +++ b/reactos/lib/crtdll/math/pow2.S @@ -0,0 +1,30 @@ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ + .data +LCW1: + .word 0 +LCW2: + .word 0 +LC0: + .double 0d1.0e+00 + + .text + + .globl ___pow2 +___pow2: + fldl 4(%esp) + fstcww LCW1 + fstcww LCW2 + fwait + andw $0xf3ff,LCW2 + orw $0x0400,LCW2 + fldcww LCW2 + fldl %st(0) + frndint + fldcww LCW1 + fxch %st(1) + fsub %st(1),%st + f2xm1 + faddl LC0 + fscale + fstp %st(1) + ret diff --git a/reactos/lib/crtdll/math/sin.S b/reactos/lib/crtdll/math/sin.S new file mode 100644 index 00000000000..862f9add557 --- /dev/null +++ b/reactos/lib/crtdll/math/sin.S @@ -0,0 +1,16 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +L0: + .quad 0xffffffffffffffff + + .globl _sin +_sin: + fldl 4(%esp) + fsin + fstsw + sahf + jnp L1 + fstp %st(0) + fldl L0 +L1: + ret + diff --git a/reactos/lib/crtdll/math/sinh.c b/reactos/lib/crtdll/math/sinh.c new file mode 100644 index 00000000000..d00e2803e17 --- /dev/null +++ b/reactos/lib/crtdll/math/sinh.c @@ -0,0 +1,16 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double sinh(double x) +{ + if(x >= 0.0) + { + const double epos = exp(x); + return (epos - 1.0/epos) / 2.0; + } + else + { + const double eneg = exp(-x); + return (1.0/eneg - eneg) / 2.0; + } +} diff --git a/reactos/lib/crtdll/math/sqrt.S b/reactos/lib/crtdll/math/sqrt.S new file mode 100644 index 00000000000..ff8066df796 --- /dev/null +++ b/reactos/lib/crtdll/math/sqrt.S @@ -0,0 +1,6 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ + .globl _sqrt +_sqrt: + fldl 4(%esp) + fsqrt + ret diff --git a/reactos/lib/crtdll/math/tan.S b/reactos/lib/crtdll/math/tan.S new file mode 100644 index 00000000000..8b629d09a6e --- /dev/null +++ b/reactos/lib/crtdll/math/tan.S @@ -0,0 +1,17 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +L0: + .quad 0xffffffffffffffff + + .globl _tan +_tan: + fldl 4(%esp) + fptan + fstsw + fstp %st(0) + sahf + jnp L1 +/* fstp %st(0) - if exception, there is nothing on the stack */ + fldl L0 +L1: + ret + diff --git a/reactos/lib/crtdll/math/tanh.c b/reactos/lib/crtdll/math/tanh.c new file mode 100644 index 00000000000..c2eb9663199 --- /dev/null +++ b/reactos/lib/crtdll/math/tanh.c @@ -0,0 +1,17 @@ +/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include + +double tanh(double x) +{ + if (x > 50) + return 1; + else if (x < -50) + return -1; + else + { + const double ebig = exp(x); + const double esmall = 1.0/ebig; + return (ebig - esmall) / (ebig + esmall); + } +} + diff --git a/reactos/lib/crtdll/stdio/clearerr.c b/reactos/lib/crtdll/stdio/clearerr.c index da87ede740f..9742967e751 100644 --- a/reactos/lib/crtdll/stdio/clearerr.c +++ b/reactos/lib/crtdll/stdio/clearerr.c @@ -2,7 +2,11 @@ #include #include -#undef clearerr +#ifdef clearerr +#undef clearerr +void clearerr(FILE *stream); +#endif + void clearerr(FILE *f) { diff --git a/reactos/lib/crtdll/stdio/doscan.c b/reactos/lib/crtdll/stdio/doscan.c index 0246644d423..503d2544a14 100644 --- a/reactos/lib/crtdll/stdio/doscan.c +++ b/reactos/lib/crtdll/stdio/doscan.c @@ -6,12 +6,12 @@ #include #include -long double -_atold(const char *ascii); - +//long double +//atold(const char *ascii); +#define atold atof // dubious variable -int _fltused = 0; +//static int _fltused = 0; int _doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), @@ -58,6 +58,12 @@ _doscan(FILE *iop, const char *fmt, void **argp) return(_doscan_low(iop, fgetc, ungetc, fmt, argp)); } +int +_dowscan(FILE *iop, const wchar_t *fmt, void **argp) +{ + return(_doscan_low(iop, fgetwc, ungetwc, fmt, argp)); +} + int _doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), const char *fmt, void **argp) @@ -290,7 +296,7 @@ _innum(int **ptr, int type, int len, int size, FILE *iop, break; case (FLOAT<<4) | LONGDOUBLE: - **(long double **)ptr = _atold(numbuf); + **(long double **)ptr = atold(numbuf); break; case (INT<<4) | SHORT: diff --git a/reactos/lib/crtdll/stdio/fdopen.c b/reactos/lib/crtdll/stdio/fdopen.c index a19f3a8a8ba..a5055c93de2 100644 --- a/reactos/lib/crtdll/stdio/fdopen.c +++ b/reactos/lib/crtdll/stdio/fdopen.c @@ -1,6 +1,6 @@ #include -FILE *fdopen(int handle, char *mode) +FILE *_fdopen(int handle, char *mode) { FILE *file; int rw; @@ -52,4 +52,4 @@ FILE *fdopen(int handle, char *mode) - \ No newline at end of file + diff --git a/reactos/lib/crtdll/stdio/feof.c b/reactos/lib/crtdll/stdio/feof.c index e9d8122c324..ed17212e2db 100644 --- a/reactos/lib/crtdll/stdio/feof.c +++ b/reactos/lib/crtdll/stdio/feof.c @@ -2,8 +2,11 @@ #include #include +#ifdef feof #undef feof -int +feof(FILE *stream); +#endif + feof(FILE *stream) { return stream->_flag & _IOEOF; diff --git a/reactos/lib/crtdll/stdio/ferror.c b/reactos/lib/crtdll/stdio/ferror.c index 5727f47ed76..8fe3416b46a 100644 --- a/reactos/lib/crtdll/stdio/ferror.c +++ b/reactos/lib/crtdll/stdio/ferror.c @@ -2,7 +2,11 @@ #include #include +#ifdef ferror #undef ferror +ferror(FILE *stream); +#endif + int ferror(FILE *stream) { diff --git a/reactos/lib/crtdll/stdio/fgetc.c b/reactos/lib/crtdll/stdio/fgetc.c index 1d6f413bebc..97f5fa319b7 100644 --- a/reactos/lib/crtdll/stdio/fgetc.c +++ b/reactos/lib/crtdll/stdio/fgetc.c @@ -1,3 +1,13 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/stdio/fgetc.c + * PURPOSE: Get a character string from stdin + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Appropriated for Reactos + 25/02/99: Added fgetwc + */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include #include @@ -7,3 +17,9 @@ fgetc(FILE *f) { return getc(f); } + +int +fgetwc(FILE *f) +{ + return getc(f); +} diff --git a/reactos/lib/crtdll/stdio/fgetpos.c b/reactos/lib/crtdll/stdio/fgetpos.c index fb3c3c19cbb..0214cf671a9 100644 --- a/reactos/lib/crtdll/stdio/fgetpos.c +++ b/reactos/lib/crtdll/stdio/fgetpos.c @@ -10,6 +10,6 @@ fgetpos(FILE *stream, fpos_t *pos) *pos = (fpos_t)ftell(stream); return 0; } - errno = EFAULT; + //errno = EFAULT; return 1; } diff --git a/reactos/lib/crtdll/stdio/fputc.c b/reactos/lib/crtdll/stdio/fputc.c index 6dd5e9b58f8..8307d49a62e 100644 --- a/reactos/lib/crtdll/stdio/fputc.c +++ b/reactos/lib/crtdll/stdio/fputc.c @@ -7,3 +7,9 @@ fputc(int c, FILE *fp) { return putc(c, fp); } + +int +fputwc(int c, FILE *fp) +{ + return putc(c, fp); +} diff --git a/reactos/lib/crtdll/stdio/fscanf.c b/reactos/lib/crtdll/stdio/fscanf.c index 0a9365f0995..b6249e415d6 100644 --- a/reactos/lib/crtdll/stdio/fscanf.c +++ b/reactos/lib/crtdll/stdio/fscanf.c @@ -13,3 +13,14 @@ fscanf(FILE *f, const char *fmt, ...) va_end(a); return r; } + +int +fwscanf(FILE *f, const wchar_t *fmt, ...) +{ + int r; + va_list a=0; + va_start(a, fmt); + r = _dowscan(f, fmt,(void *) a); + va_end(a); + return r; +} diff --git a/reactos/lib/crtdll/stdio/fsetpos.c b/reactos/lib/crtdll/stdio/fsetpos.c index ce5c1f84881..9798af92682 100644 --- a/reactos/lib/crtdll/stdio/fsetpos.c +++ b/reactos/lib/crtdll/stdio/fsetpos.c @@ -10,6 +10,6 @@ fsetpos(FILE *stream, fpos_t *pos) fseek(stream, (long)(*pos), SEEK_SET); return 0; } - errno = EFAULT; + //errno = EFAULT; return 1; } diff --git a/reactos/lib/crtdll/stdio/getc.c b/reactos/lib/crtdll/stdio/getc.c index 02018a2355d..5e3c3c87c60 100644 --- a/reactos/lib/crtdll/stdio/getc.c +++ b/reactos/lib/crtdll/stdio/getc.c @@ -15,3 +15,5 @@ int getc(FILE *f) return -1; return c; } + + diff --git a/reactos/lib/crtdll/stdio/gets.c b/reactos/lib/crtdll/stdio/gets.c index cccdf637213..7c84f13026c 100644 --- a/reactos/lib/crtdll/stdio/gets.c +++ b/reactos/lib/crtdll/stdio/gets.c @@ -1,3 +1,12 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/stdio/gets.c + * PURPOSE: Get a character string from stdin + * PROGRAMER: DJ Delorie + * UPDATE HISTORY: + * 28/12/98: Appropriated for Reactos + */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include diff --git a/reactos/lib/crtdll/stdio/perror.c b/reactos/lib/crtdll/stdio/perror.c index 7e55f7521b3..119ea13d828 100644 --- a/reactos/lib/crtdll/stdio/perror.c +++ b/reactos/lib/crtdll/stdio/perror.c @@ -4,6 +4,10 @@ #include +#ifdef perror +#undef perror +void perror(const char *s); +#endif void perror(const char *s) diff --git a/reactos/lib/crtdll/stdio/popen.c b/reactos/lib/crtdll/stdio/popen.c index eb08468b4d6..e2bfbd5a4e4 100644 --- a/reactos/lib/crtdll/stdio/popen.c +++ b/reactos/lib/crtdll/stdio/popen.c @@ -4,15 +4,8 @@ #include #include #include -//#include #include - - -int __fileno_alloc(HANDLE hFile, int mode); - - - FILE * _popen (const char *cm, const char *md) /* program name, pipe mode */ { @@ -36,10 +29,10 @@ _popen (const char *cm, const char *md) /* program name, pipe mode */ if ( *md == 'r' ) { - pf = _fdopen( __fileno_alloc(hReadPipe, O_RDONLY) , "r" ); + pf = _fdopen( __fileno_alloc(hReadPipe, _fmode) , "r" ); } else { - pf = _fdopen( __fileno_alloc(hWritePipe, _O_WRONLY) , "w" ); + pf = _fdopen( __fileno_alloc(hWritePipe, _fmode) , "w" ); } pf->name_to_remove = SpawnedProcess; diff --git a/reactos/lib/crtdll/stdio/scanf.c b/reactos/lib/crtdll/stdio/scanf.c index b907273084e..d3c5cb77fdd 100644 --- a/reactos/lib/crtdll/stdio/scanf.c +++ b/reactos/lib/crtdll/stdio/scanf.c @@ -13,3 +13,15 @@ scanf(const char *fmt, ...) va_end(a); return r; } + +int +wscanf(const wchar_t *fmt, ...) +{ + int r; + va_list a=0; + va_start(a, fmt); + r = _dowscan(stdin, fmt, a); + va_end(a); + return r; +} + diff --git a/reactos/lib/crtdll/stdio/sscanf.c b/reactos/lib/crtdll/stdio/sscanf.c index a2f5651080d..6b0d5832498 100644 --- a/reactos/lib/crtdll/stdio/sscanf.c +++ b/reactos/lib/crtdll/stdio/sscanf.c @@ -24,3 +24,24 @@ sscanf(const char *str, const char *fmt, ...) va_end(a); return r; } + +int +swscanf(const wchar_t *str, const wchar_t *fmt, ...) +{ + int r; + va_list a=0; + FILE _strbuf; + + va_start(a, fmt); + + _strbuf._flag = _IOREAD|_IOSTRG; + _strbuf._ptr = (char *)str; + _strbuf._base = (char *)str; + _strbuf._cnt = 0; + while (*str++) + _strbuf._cnt++; + _strbuf._bufsiz = _strbuf._cnt; + r = _dowscan(&_strbuf, fmt, a); + va_end(a); + return r; +} diff --git a/reactos/lib/crtdll/stdio/stdhnd.c b/reactos/lib/crtdll/stdio/stdhnd.c index a1af9a912b5..1cc788ce9a1 100644 --- a/reactos/lib/crtdll/stdio/stdhnd.c +++ b/reactos/lib/crtdll/stdio/stdhnd.c @@ -4,7 +4,7 @@ -FILE _iob[] = +FILE _crtdll_iob[] = { // stdin { @@ -37,3 +37,5 @@ FILE _iob[] = 4, 0,0,NULL } }; + +FILE (*__imp__iob)[] = &_crtdll_iob; diff --git a/reactos/lib/crtdll/stdio/stdiohk.c b/reactos/lib/crtdll/stdio/stdiohk.c index db059c2df76..cccdea817ce 100644 --- a/reactos/lib/crtdll/stdio/stdiohk.c +++ b/reactos/lib/crtdll/stdio/stdiohk.c @@ -1,7 +1,7 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include -//#include + static void fcloseall_helper(FILE *f) {