From 7349aab051ad6ee0b6d0cf9c51d4d7ed6ad7bb78 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Sat, 25 Nov 2000 02:11:59 +0000 Subject: [PATCH] - Add math calls: scalb, fpclass, nextafter, logb, _CI* - Add futime, utime, purecall, getpid --- dlls/crtdll/crtdll.h | 23 +++++ dlls/crtdll/crtdll.spec | 46 ++++----- dlls/crtdll/crtdll_main.c | 206 ++++++++++++++++++++++++++++++++++++++ dlls/crtdll/file.c | 58 ++++++++++- 4 files changed, 308 insertions(+), 25 deletions(-) diff --git a/dlls/crtdll/crtdll.h b/dlls/crtdll/crtdll.h index 8f4caa690c..b900ec0da0 100644 --- a/dlls/crtdll/crtdll.h +++ b/dlls/crtdll/crtdll.h @@ -71,6 +71,18 @@ #define _FREEENTRY 0 #define _USEDENTRY 1 +/* fpclass constants */ +#define _FPCLASS_SNAN 1 +#define _FPCLASS_QNAN 2 +#define _FPCLASS_NINF 4 +#define _FPCLASS_NN 8 +#define _FPCLASS_ND 16 +#define _FPCLASS_NZ 32 +#define _FPCLASS_PZ 64 +#define _FPCLASS_PD 128 +#define _FPCLASS_PN 256 +#define _FPCLASS_PINF 512 + /* CRTDLL Globals */ extern INT CRTDLL_doserrno; extern INT CRTDLL_errno; @@ -170,6 +182,12 @@ typedef struct _heapinfo int _useflag; } _HEAPINFO; +struct _utimbuf +{ + time_t actime; + time_t modtime; +}; + typedef VOID (*sig_handler_type)(VOID); typedef VOID (*new_handler_type)(VOID); @@ -251,6 +269,7 @@ INT __cdecl CTRDLL__creat( LPCSTR path, INT flags ); INT __cdecl CRTDLL__eof( INT fd ); LONG __cdecl CRTDLL__tell(INT fd); INT __cdecl CRTDLL__umask(INT umask); +INT __cdecl CRTDLL__utime(LPCSTR path, struct _utimbuf *t); INT __cdecl CRTDLL__unlink( LPCSTR pathname ); INT __cdecl CRTDLL_rename( LPCSTR oldpath,LPCSTR newpath ); int __cdecl CRTDLL__stat( LPCSTR filename, struct _stat * buf ); @@ -261,6 +280,7 @@ INT __cdecl CRTDLL__setmode( INT fh,INT mode ); INT __cdecl CRTDLL_remove( LPCSTR path ); INT __cdecl CRTDLL__commit( INT fd ); INT __cdecl CRTDLL__fstat( int file, struct _stat* buf ); +INT __cdecl CRTDLL__futime( INT fd, struct _utimbuf *t ); HANDLE __cdecl CRTDLL__get_osfhandle( INT fd ); /* CRTDLL_main.c */ @@ -276,6 +296,7 @@ UINT __cdecl CRTDLL__rotl( UINT x,INT shift ); DWORD __cdecl CRTDLL__lrotl( DWORD x,INT shift ); DWORD __cdecl CRTDLL__lrotr( DWORD x,INT shift ); DWORD __cdecl CRTDLL__rotr( UINT x,INT shift ); +double __cdecl CRTDLL__scalb( double x, LONG y ); INT __cdecl CRTDLL__mbsicmp( unsigned char *x,unsigned char *y ); INT __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args ); VOID __cdecl CRTDLL_longjmp( jmp_buf env, int val ); @@ -316,10 +337,12 @@ UINT __cdecl CRTDLL__control87( UINT, UINT ); UINT __cdecl CRTDLL__controlfp( UINT, UINT ); double __cdecl CRTDLL__copysign(double x, double sign); INT __cdecl CRTDLL__finite( double d ); +INT __cdecl CRTDLL__fpclass( double d ); VOID __cdecl CRTDLL__fpreset( void ); INT __cdecl CRTDLL__isnan( double d ); LPVOID __cdecl CRTDLL__lsearch( LPVOID match, LPVOID start, LPUINT array_size, UINT elem_size, comp_func cf ); +VOID __cdecl CRTDLL__purecall( VOID ); /* CRTDLL_mem.c */ LPVOID __cdecl CRTDLL_new( DWORD size ); diff --git a/dlls/crtdll/crtdll.spec b/dlls/crtdll/crtdll.spec index 8d227a783c..f90bb9c21f 100644 --- a/dlls/crtdll/crtdll.spec +++ b/dlls/crtdll/crtdll.spec @@ -11,22 +11,22 @@ debug_channels (crtdll) @ cdecl ??2@YAPAXI@Z(long) CRTDLL_new @ cdecl ??3@YAXPAX@Z(long) CRTDLL_delete @ cdecl ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z(ptr) CRTDLL_set_new_handler -@ stub _CIacos -@ stub _CIasin -@ stub _CIatan -@ stub _CIatan2 -@ stub _CIcos -@ stub _CIcosh -@ stub _CIexp -@ stub _CIfmod -@ stub _CIlog -@ stub _CIlog10 +@ cdecl _CIacos() CRTDLL__CIacos +@ cdecl _CIasin() CRTDLL__CIasin +@ cdecl _CIatan() CRTDLL__CIatan +@ cdecl _CIatan2() CRTDLL__CIatan2 +@ cdecl _CIcos() CRTDLL__CIcos +@ cdecl _CIcosh() CRTDLL__CIcosh +@ cdecl _CIexp() CRTDLL__CIexp +@ cdecl _CIfmod() CRTDLL__CIfmod +@ cdecl _CIlog() CRTDLL__CIlog +@ cdecl _CIlog10() CRTDLL__CIlog10 @ forward _CIpow ntdll._CIpow -@ stub _CIsin -@ stub _CIsinh -@ stub _CIsqrt -@ stub _CItan -@ stub _CItanh +@ cdecl _CIsin() CRTDLL__CIsin +@ cdecl _CIsinh() CRTDLL__CIsinh +@ cdecl _CIsqrt() CRTDLL__CIsqrt +@ cdecl _CItan() CRTDLL__CItan +@ cdecl _CItanh() CRTDLL__CItanh @ stub _HUGE_dll @ stub _XcptFilter @ cdecl __GetMainArgs(ptr ptr ptr long) CRTDLL__GetMainArgs @@ -112,7 +112,7 @@ debug_channels (crtdll) @ cdecl _flsbuf(long ptr) CRTDLL__flsbuf @ cdecl _flushall() CRTDLL__flushall @ extern _fmode_dll CRTDLL_fmode_dll -@ stub _fpclass +@ cdecl _fpclass(double) CRTDLL__fpclass @ stub _fpieee_flt @ cdecl _fpreset() CRTDLL__fpreset @ cdecl _fputchar(long) CRTDLL__fputchar @@ -122,7 +122,7 @@ debug_channels (crtdll) @ cdecl _ftime(ptr) CRTDLL__ftime @ forward _ftol ntdll._ftol @ cdecl _fullpath(ptr str long) CRTDLL__fullpath -@ stub _futime +@ cdecl _futime(long ptr) CRTDLL__futime @ stub _gcvt @ cdecl _get_osfhandle(long) CRTDLL__get_osfhandle @ stub _getch @@ -133,7 +133,7 @@ debug_channels (crtdll) @ forward _getdllprocaddr kernel32.GetProcAddress @ cdecl _getdrive() CRTDLL__getdrive @ forward _getdrives kernel32.GetLogicalDrives -@ stub _getpid +@ forward _getpid kernel32.GetCurrentProcessId @ stub _getsystime @ stub _getw @ cdecl _global_unwind2(ptr) CRTDLL__global_unwind2 @@ -182,7 +182,7 @@ debug_channels (crtdll) @ cdecl _loaddll(str) CRTDLL__loaddll @ cdecl _local_unwind2(ptr long) CRTDLL__local_unwind2 @ stub _locking -@ stub _logb +@ cdecl _logb(double) logb @ cdecl _lrotl (long long) CRTDLL__lrotl @ cdecl _lrotr (long long) CRTDLL__lrotr @ cdecl _lsearch(ptr ptr long long ptr) CRTDLL__lsearch @@ -244,7 +244,7 @@ debug_channels (crtdll) @ cdecl _mkdir(str) CRTDLL__mkdir @ stub _mktemp @ cdecl _msize(ptr) CRTDLL__msize -@ stub _nextafter +@ cdecl _nextafter(double double) nextafter @ cdecl _onexit(ptr) CRTDLL__onexit @ cdecl _open(str long) CRTDLL__open @ cdecl _open_osfhandle(long long) CRTDLL__open_osfhandle @@ -258,7 +258,7 @@ debug_channels (crtdll) @ stub _pgmptr_dll @ stub _pipe @ stub _popen -@ stub _purecall +@ cdecl _purecall() CRTDLL__purecall @ stub _putch @ stub _putenv @ stub _putw @@ -268,7 +268,7 @@ debug_channels (crtdll) @ stub _rmtmp @ cdecl _rotl (long long) CRTDLL__rotl @ cdecl _rotr (long long) CRTDLL__rotr -@ stub _scalb +@ cdecl _scalb (double long) CRTDLL__scalb @ stub _searchenv @ stub _seterrormode @ cdecl _setjmp (ptr) CRTDLL__setjmp @@ -324,7 +324,7 @@ debug_channels (crtdll) @ stub _ungetch @ cdecl _unlink(str) CRTDLL__unlink @ cdecl _unloaddll(long) CRTDLL__unloaddll -@ stub _utime +@ cdecl _utime(str ptr) CRTDLL__utime @ cdecl _vsnprintf(ptr long ptr ptr) vsnprintf @ stub _vsnwprintf @ cdecl _wcsdup(wstr) CRTDLL__wcsdup diff --git a/dlls/crtdll/crtdll_main.c b/dlls/crtdll/crtdll_main.c index a939b202bc..d544cf3a15 100644 --- a/dlls/crtdll/crtdll_main.c +++ b/dlls/crtdll/crtdll_main.c @@ -130,6 +130,156 @@ void __CRTDLL__set_errno(ULONG err) } } +#if defined(__GNUC__) && defined(__i386__) +#define FPU_DOUBLE(var) double var; \ + __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : ) +#define FPU_DOUBLES(var1,var2) double var1,var2; \ + __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \ + __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : ) +#else +#define FPU_DOUBLE(var) double var = quiet_nan(); \ + FIXME(":not implemented\n"); +#define FPU_DOUBLES(var1,var2) double var1,var2; \ + var1=var2=quiet_nan(); FIXME(":not implemented\n") +#endif + +/********************************************************************* + * _CIacos (CRTDLL.004) + */ +double __cdecl CRTDLL__CIacos(void) +{ + FPU_DOUBLE(x); + return acos(x); +} + + +/********************************************************************* + * _CIasin (CRTDLL.005) + */ +double __cdecl CRTDLL__CIasin(void) +{ + FPU_DOUBLE(x); + return asin(x); +} + + +/********************************************************************* + * _CIatan (CRTDLL.006) + */ +double __cdecl CRTDLL__CIatan(void) +{ + FPU_DOUBLE(x); + return atan(x); +} + +/********************************************************************* + * _CIatan2 (CRTDLL.007) + */ +double __cdecl CRTDLL__CIatan2(void) +{ + FPU_DOUBLES(x,y); + return atan2(x,y); +} + + +/********************************************************************* + * _CIcos (CRTDLL.008) + */ +double __cdecl CRTDLL__CIcos(void) +{ + FPU_DOUBLE(x); + return cos(x); +} + +/********************************************************************* + * _CIcosh (CRTDLL.009) + */ +double __cdecl CRTDLL__CIcosh(void) +{ + FPU_DOUBLE(x); + return cosh(x); +} + +/********************************************************************* + * _CIexp (CRTDLL.010) + */ +double __cdecl CRTDLL__CIexp(void) +{ + FPU_DOUBLE(x); + return exp(x); +} + +/********************************************************************* + * _CIfmod (CRTDLL.011) + */ +double __cdecl CRTDLL__CIfmod(void) +{ + FPU_DOUBLES(x,y); + return fmod(x,y); +} + +/********************************************************************* + * _CIlog (CRTDLL.012) + */ +double __cdecl CRTDLL__CIlog(void) +{ + FPU_DOUBLE(x); + return log(x); +} + +/********************************************************************* + * _CIlog10 (CRTDLL.013) + */ +double __cdecl CRTDLL__CIlog10(void) +{ + FPU_DOUBLE(x); + return log10(x); +} + +/********************************************************************* + * _CIsin (CRTDLL.015) + */ +double __cdecl CRTDLL__CIsin(void) +{ + FPU_DOUBLE(x); + return sin(x); +} + +/********************************************************************* + * _CIsinh (CRTDLL.016) + */ +double __cdecl CRTDLL__CIsinh(void) +{ + FPU_DOUBLE(x); + return sinh(x); +} + +/********************************************************************* + * _CIsqrt (CRTDLL.017) + */ +double __cdecl CRTDLL__CIsqrt(void) +{ + FPU_DOUBLE(x); + return sqrt(x); +} + +/********************************************************************* + * _CItan (CRTDLL.018) + */ +double __cdecl CRTDLL__CItan(void) +{ + FPU_DOUBLE(x); + return tan(x); +} + +/********************************************************************* + * _CItanh (CRTDLL.019) + */ +double __cdecl CRTDLL__CItanh(void) +{ + FPU_DOUBLE(x); + return tanh(x); +} /********************************************************************* * _GetMainArgs (CRTDLL.022) @@ -211,6 +361,37 @@ LPSTR * __cdecl CRTDLL__GetMainArgs(LPDWORD argc,LPSTR **argv, } +/********************************************************************* + * _fpclass (CRTDLL.105) + * + * Return the FP classification of d. + */ +INT __cdecl CRTDLL__fpclass(double d) +{ + switch (fpclassify( d )) + { + case FP_NAN: return _FPCLASS_QNAN; + case FP_INFINITE: + if (signbit(d)) + return _FPCLASS_NINF; + return _FPCLASS_PINF; + case FP_SUBNORMAL: + if (signbit(d)) + return _FPCLASS_ND; + return _FPCLASS_PD; + case FP_ZERO: + if (signbit(d)) + return _FPCLASS_NZ; + return _FPCLASS_PZ; + case FP_NORMAL: + default: + if (signbit(d)) + return _FPCLASS_NN; + return _FPCLASS_PN; + } +} + + /********************************************************************* * _initterm (CRTDLL.135) */ @@ -325,6 +506,19 @@ DWORD __cdecl CRTDLL__rotr(UINT x,INT shift) } +/********************************************************************* + * _scalb (CRTDLL.259) + * + * Return x*2^y. + */ +double __cdecl CRTDLL__scalb(double x, LONG y) +{ + /* Note - Can't forward directly as libc expects y as double */ + double y2 = (double)y; + return scalb( x, y2 ); +} + + /********************************************************************* * vswprintf (CRTDLL.501) */ @@ -1000,3 +1194,15 @@ INT __cdecl CRTDLL__isnan(double d) */ return isnan(d)?1:0; } + + +/********************************************************************* + * _purecall (CRTDLL.249) + * + * Abort program after pure virtual function call. + */ +VOID __cdecl CRTDLL__purecall(VOID) +{ + CRTDLL__amsg_exit( 6025 ); +} + diff --git a/dlls/crtdll/file.c b/dlls/crtdll/file.c index e48118a1ed..02b4c461bb 100644 --- a/dlls/crtdll/file.c +++ b/dlls/crtdll/file.c @@ -193,7 +193,7 @@ INT __cdecl CRTDLL__access(LPCSTR filename, INT mode) { DWORD attr = GetFileAttributesA(filename); - if (attr == -1) + if (attr == 0xffffffff) { if (!filename) { @@ -502,6 +502,41 @@ int __cdecl CRTDLL__fstat(int fd, struct _stat* buf) } +/********************************************************************* + * _futime (CRTDLL.115) + * + * Set the file access/modification times on an open file. + */ +INT __cdecl CRTDLL__futime(INT fd, struct _utimbuf *t) +{ + HANDLE hand = __CRTDLL__fdtoh(fd); + FILETIME at, wt; + + if (!t) + { + time_t currTime; + CRTDLL_time(&currTime); + RtlSecondsSince1970ToTime( currTime, &at ); + memcpy( &wt, &at, sizeof(wt) ); + } + else + { + RtlSecondsSince1970ToTime( t->actime, &at ); + if (t->actime == t->modtime) + memcpy( &wt, &at, sizeof(wt) ); + else + RtlSecondsSince1970ToTime( t->modtime, &wt ); + } + + if (!SetFileTime( hand, NULL, &at, &wt )) + { + __CRTDLL__set_errno(GetLastError()); + return -1 ; + } + return 0; +} + + /********************************************************************* * _get_osfhandle (CRTDLL.117) * @@ -564,7 +599,7 @@ INT __cdecl CRTDLL__isatty(INT fd) */ LONG __cdecl CRTDLL__lseek( INT fd, LONG offset, INT whence) { - LONG ret; + DWORD ret; HANDLE hand = __CRTDLL__fdtoh(fd); TRACE(":fd (%d) handle (%d)\n",fd,hand); @@ -863,6 +898,25 @@ INT __cdecl CRTDLL__umask(INT umask) } +/********************************************************************* + * _utime (CRTDLL.314) + * + * Set the file access/modification times on a file. + */ +INT __cdecl CRTDLL__utime(LPCSTR path, struct _utimbuf *t) +{ + INT fd = CRTDLL__open( path, _O_WRONLY | _O_BINARY ); + + if (fd > 0) + { + INT retVal = CRTDLL__futime(fd, t); + CRTDLL__close(fd); + return retVal; + } + return -1; +} + + /********************************************************************* * _unlink (CRTDLL.315) *