From b3c424cd406c89f68221d89d20471552465ce7ed Mon Sep 17 00:00:00 2001 From: Boudewijn Dekker Date: Mon, 22 Mar 1999 20:57:12 +0000 Subject: [PATCH] Changes and improved mingw32 compile svn path=/trunk/; revision=330 --- reactos/lib/crtdll/conio/getch.c | 7 +-- reactos/lib/crtdll/conio/kbhit.c | 15 +++++ reactos/lib/crtdll/ctype/toupper.c | 5 +- reactos/lib/crtdll/direct/getdfree.c | 3 +- reactos/lib/crtdll/io/access.c | 21 +++++-- reactos/lib/crtdll/io/close.c | 9 +-- reactos/lib/crtdll/io/commit.c | 14 +++++ reactos/lib/crtdll/io/dup.c | 7 +-- reactos/lib/crtdll/io/read.c | 7 +-- reactos/lib/crtdll/io/unlink.c | 7 +-- reactos/lib/crtdll/io/write.c | 8 +-- reactos/lib/crtdll/makefile | 10 ++-- reactos/lib/crtdll/misc/GetArgs.c | 79 +++++++++++++-------------- reactos/lib/crtdll/process/execl.c | 7 +-- reactos/lib/crtdll/process/execle.c | 4 +- reactos/lib/crtdll/process/execlp.c | 8 +-- reactos/lib/crtdll/process/execv.c | 10 ++-- reactos/lib/crtdll/process/execvp.c | 10 ++-- reactos/lib/crtdll/process/execvpe.c | 10 +--- reactos/lib/crtdll/process/spawnl.c | 2 +- reactos/lib/crtdll/process/spawnle.c | 4 +- reactos/lib/crtdll/process/spawnlp.c | 7 +-- reactos/lib/crtdll/process/spawnlpe.c | 4 +- reactos/lib/crtdll/process/spawnv.c | 6 +- reactos/lib/crtdll/process/spawnve.c | 5 +- reactos/lib/crtdll/process/spawnvp.c | 3 +- reactos/lib/crtdll/process/spawnvpe.c | 14 +---- reactos/lib/crtdll/stdio/fopen.c | 7 +-- reactos/lib/crtdll/stdio/fputc.c | 3 +- reactos/lib/crtdll/stdio/fputs.c | 3 +- reactos/lib/crtdll/stdio/freopen.c | 5 +- reactos/lib/crtdll/stdio/fsetpos.c | 7 ++- reactos/lib/crtdll/stdio/getc.c | 3 +- reactos/lib/crtdll/stdio/putc.c | 3 +- reactos/lib/crtdll/stdio/puts.c | 6 +- reactos/lib/crtdll/stdlib/bsearch.c | 4 +- reactos/lib/crtdll/stdlib/errno.c | 6 +- reactos/lib/crtdll/stdlib/qsort.c | 3 +- reactos/lib/crtdll/stdlib/strtol.c | 4 +- reactos/lib/crtdll/stdlib/strtoul.c | 7 ++- reactos/lib/crtdll/sys_stat/fstat.c | 2 +- reactos/lib/crtdll/time/clock.c | 34 ++++++++++++ reactos/lib/crtdll/time/ctime.c | 30 +--------- reactos/lib/crtdll/time/strftime.c | 17 +----- reactos/lib/crtdll/time/time.c | 41 +++++++------- 45 files changed, 227 insertions(+), 244 deletions(-) create mode 100644 reactos/lib/crtdll/io/commit.c create mode 100644 reactos/lib/crtdll/time/clock.c diff --git a/reactos/lib/crtdll/conio/getch.c b/reactos/lib/crtdll/conio/getch.c index 5da123465ce..5a1b4cc8913 100644 --- a/reactos/lib/crtdll/conio/getch.c +++ b/reactos/lib/crtdll/conio/getch.c @@ -10,14 +10,11 @@ #include #include #include +#include extern int char_avail; extern int ungot_char; -int getch( void ) -{ - return _getch(); -} int _getch(void) @@ -32,7 +29,7 @@ _getch(void) } else { - ReadConsoleA(filehnd(stdin->_file), &c,1,&NumberOfCharsRead ,NULL); + ReadConsoleA(_get_osfhandle(stdin->_file), &c,1,&NumberOfCharsRead ,NULL); } if ( c == 10 ) diff --git a/reactos/lib/crtdll/conio/kbhit.c b/reactos/lib/crtdll/conio/kbhit.c index 50b185f7d36..d8a61021ff9 100644 --- a/reactos/lib/crtdll/conio/kbhit.c +++ b/reactos/lib/crtdll/conio/kbhit.c @@ -1,3 +1,18 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/conio/kbhit.c + * PURPOSE: Checks for keyboard hits + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Created + */ + +#include +#include + + +// FIXME PeekCosoleInput returns more than keyboard hits int _kbhit(void) { diff --git a/reactos/lib/crtdll/ctype/toupper.c b/reactos/lib/crtdll/ctype/toupper.c index 693b12dd2ab..096af42e76e 100644 --- a/reactos/lib/crtdll/ctype/toupper.c +++ b/reactos/lib/crtdll/ctype/toupper.c @@ -1,5 +1,6 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include +#include #undef toupper int toupper(int c) @@ -7,7 +8,7 @@ int toupper(int c) return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; } #undef towupper -int towupper(int c) +wchar_t towupper(wchar_t c) { return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; } @@ -17,7 +18,7 @@ int _toupper(int c) return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; } -int _towupper(int c) +wchar_t _towupper(wchar_t c) { return (c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c; } diff --git a/reactos/lib/crtdll/direct/getdfree.c b/reactos/lib/crtdll/direct/getdfree.c index 0b1d538b2d3..e86f76117ec 100644 --- a/reactos/lib/crtdll/direct/getdfree.c +++ b/reactos/lib/crtdll/direct/getdfree.c @@ -13,7 +13,8 @@ unsigned int _getdiskfree(unsigned int _drive, struct _diskfree_t *_diskspace) if ( _diskspace == NULL ) return 0; - if ( !GetDiskFreeSpaceA(RootPathName,&_diskspace->sectors_per_cluster,&_diskspace->bytes_per_sector,&_diskspace->avail_clusters,&_diskspace->total_clusters ) ) + if ( !GetDiskFreeSpaceA(RootPathName,(LPDWORD)&_diskspace->sectors_per_cluster,(LPDWORD)&_diskspace->bytes_per_sector, + (LPDWORD )&_diskspace->avail_clusters,(LPDWORD )&_diskspace->total_clusters ) ) return 0; return _diskspace->avail_clusters; } diff --git a/reactos/lib/crtdll/io/access.c b/reactos/lib/crtdll/io/access.c index 725f7795ebb..8395761e999 100644 --- a/reactos/lib/crtdll/io/access.c +++ b/reactos/lib/crtdll/io/access.c @@ -1,12 +1,21 @@ #include #include -#define F_OK 0x01 -#define R_OK 0x02 -#define W_OK 0x04 -#define X_OK 0x08 -#define D_OK 0x10 - +#ifndef F_OK + #define F_OK 0x01 +#endif +#ifndef R_OK + #define R_OK 0x02 +#endif +#ifndef W_OK + #define W_OK 0x04 +#endif +#ifndef X_OK + #define X_OK 0x08 +#endif +#ifndef D_OK + #define D_OK 0x10 +#endif int _access( const char *_path, int _amode ) { diff --git a/reactos/lib/crtdll/io/close.c b/reactos/lib/crtdll/io/close.c index d51a7f0a923..2865179c3ed 100644 --- a/reactos/lib/crtdll/io/close.c +++ b/reactos/lib/crtdll/io/close.c @@ -1,16 +1,11 @@ #include #include -//#include +#include -int close(int _fd) -{ - return _close(_fd); -} - int _close(int _fd) { - CloseHandle(filehnd(_fd)); + CloseHandle(_get_osfhandle(_fd)); return __fileno_close(_fd); } diff --git a/reactos/lib/crtdll/io/commit.c b/reactos/lib/crtdll/io/commit.c new file mode 100644 index 00000000000..3afcc14c1a5 --- /dev/null +++ b/reactos/lib/crtdll/io/commit.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +int _commit(int _fd) +{ + if (! FlushFileBuffers(_get_osfhandle(_fd)) ) { + __set_errno(EBADF); + return -1; + } + + return 0; +} diff --git a/reactos/lib/crtdll/io/dup.c b/reactos/lib/crtdll/io/dup.c index ef19d4975b7..19c91632ad6 100644 --- a/reactos/lib/crtdll/io/dup.c +++ b/reactos/lib/crtdll/io/dup.c @@ -1,13 +1,8 @@ #include #include -#undef dup -int dup( int handle ) -{ - return _dup(handle); -} int _dup( int handle ) { - return _open_osfhandle(filehnd(handle), 0666); + return _open_osfhandle(_get_osfhandle(handle), 0666); } diff --git a/reactos/lib/crtdll/io/read.c b/reactos/lib/crtdll/io/read.c index c8a6ee35bcc..5dc92ed1f5c 100644 --- a/reactos/lib/crtdll/io/read.c +++ b/reactos/lib/crtdll/io/read.c @@ -10,15 +10,10 @@ #include #include -size_t read(int _fd, void *_buf, size_t _nbyte) -{ - return _read(_fd,_buf,_nbyte); -} size_t _read(int _fd, void *_buf, size_t _nbyte) { size_t _rbyte; - if ( !ReadFile(filehnd(_fd),_buf,_nbyte,&_rbyte,NULL) ) { - printf("%d\n",GetLastError()); + if ( !ReadFile(_get_osfhandle(_fd),_buf,_nbyte,&_rbyte,NULL) ) { return -1; } diff --git a/reactos/lib/crtdll/io/unlink.c b/reactos/lib/crtdll/io/unlink.c index d8ac7c29917..de50275a28a 100644 --- a/reactos/lib/crtdll/io/unlink.c +++ b/reactos/lib/crtdll/io/unlink.c @@ -10,14 +10,11 @@ #include #include -int unlink( const char *filename ) -{ - return _unlink(filename); -} + int _unlink( const char *filename ) { - if ( !DeleteFile(filename) ) + if ( !DeleteFileA(filename) ) return -1; return 0; } diff --git a/reactos/lib/crtdll/io/write.c b/reactos/lib/crtdll/io/write.c index 5572b60f620..df9b11eda45 100644 --- a/reactos/lib/crtdll/io/write.c +++ b/reactos/lib/crtdll/io/write.c @@ -10,16 +10,12 @@ #include #include -int write(int _fd, const void *_buf,int _nbyte) -{ - return _write(_fd,_buf,_nbyte); -} + size_t _write(int _fd, const void *_buf, size_t _nbyte) { size_t _wbyte; - if ( !WriteFile(filehnd(_fd),_buf,_nbyte,&_wbyte,NULL) ) { - printf("%d\n",GetLastError()); + if ( !WriteFile(_get_osfhandle(_fd),_buf,_nbyte,&_wbyte,NULL) ) { return -1; } return _wbyte; diff --git a/reactos/lib/crtdll/makefile b/reactos/lib/crtdll/makefile index 471814ca94f..81370b95e12 100644 --- a/reactos/lib/crtdll/makefile +++ b/reactos/lib/crtdll/makefile @@ -16,7 +16,7 @@ DIRECT_OBJECTS = direct/chdir.o direct/chdrive.o direct/getcwd.o direct/getdrive direct/rmdir.o direct/mkdir.o direct/getdfree.o -MISC_OBJECTS = misc/sleep.o misc/getargs.o misc/crtfmode.o misc/crtglob.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 \ string/strchr.o string/strcmp.o string/strcoll.o \ @@ -54,12 +54,12 @@ IO_OBJECTS = io/access.o io/close.o io/create.o io/dup.o io/dup2.o io/find.o io/ 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 \ +STDLIB_OBJECTS = stdlib/abort.o stdlib/abs.o stdlib/atexit.o stdlib/atof.o stdlib/atoi.o \ + stdlib/bsearch.o stdlib/div.o stdlib/errno.o stdlib/Exit.o \ stdlib/fullpath.o stdlib/labs.o stdlib/ldiv.o stdlib/llabs.o stdlib/lldiv.o \ stdlib/makepath.o stdlib/malloc.o stdlib/putenv.o stdlib/qsort.o \ stdlib/rand.o stdlib/senv.o stdlib/splitp.o stdlib/strtod.o stdlib/strtol.o \ - stdlib/strtoul.o stdlib/strtold.o + stdlib/strtoul.o SIGNAL_OBJECTS = signal/signal.o @@ -67,7 +67,7 @@ PROCESS_OBJECTS = process/cwait.o process/dll.o process/spawnl.o process/spawnlp 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 +TIME_OBJECTS = time/ctime.o time/difftime.o time/strftime.o time/time.o time/clock.o FLOAT_OBJECTS = float/fpreset.o float/clearfp.o float/cntrlfp.o float/statfp.o float/logb.o diff --git a/reactos/lib/crtdll/misc/GetArgs.c b/reactos/lib/crtdll/misc/GetArgs.c index b6e6f5da59d..6e2ed31031a 100644 --- a/reactos/lib/crtdll/misc/GetArgs.c +++ b/reactos/lib/crtdll/misc/GetArgs.c @@ -2,15 +2,19 @@ #include #include - -char *acmdln_dll; -unsigned int commode_dll; +#undef _acmdln_dll +char *_acmdln_dll; +#undef _commode_dll +unsigned int _commode_dll; -unsigned int fmode_dll; -unsigned int winmajor_dll; -unsigned int winminor_dll; -unsigned int winver_dll; -unsigned int osver_dll; +#undef _winmajor_dll +unsigned int _winmajor_dll; +#undef _winminor_dll +unsigned int _winminor_dll; +#undef _winver_dll +unsigned int _winver_dll; +#undef _osver_dll +unsigned int _osver_dll; #undef __argv #undef __argc @@ -19,51 +23,46 @@ char *xargv[1024]; char **__argv = xargv; int __argc = 0; -unsigned int *__argc_dll = &__argc; +int *__argc_dll = &__argc; char ***__argv_dll = &__argv; -char *xenv; + +#undef _environ char **_environ; +#undef _environ_dll char *** _environ_dll = &_environ; -#undef environ -char **environ; + int __GetMainArgs(int *argc,char ***argv,char **env,int flag) { - char *cmdline; int i,afterlastspace; DWORD version; - // acmdln_dll = cmdline = strdup( GetCommandLineA() ); + _acmdln_dll = GetCommandLineA(); version = GetVersion(); - osver_dll = version >> 16; - winminor_dll = version & 0xFF; - winmajor_dll = (version>>8) & 0xFF; - winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8); + _osver_dll = version >> 16; + _winminor_dll = version & 0xFF; + _winmajor_dll = (version>>8) & 0xFF; + _winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8); /* missing threading init */ i=0; - cmdline = GetCommandLineA(); afterlastspace=0; - dprintf("cmdline '%s'\n",cmdline); - while (cmdline[i]) - { - if (cmdline[i]==' ') - { - dprintf("cmdline '%s'\n",cmdline); + while (_acmdln_dll[i]) { + if (_acmdln_dll[i]==' ') { __argc++; - cmdline[i]='\0'; - __argv[__argc-1] = strdup( cmdline+afterlastspace); + _acmdln_dll[i]='\0'; + __argv[__argc-1] = strdup(_acmdln_dll+afterlastspace); i++; - while (cmdline[i]==' ') + while (_acmdln_dll[i]==' ') i++; - if (cmdline[i]) + if (_acmdln_dll[i]) afterlastspace=i; } else @@ -74,23 +73,21 @@ int __GetMainArgs(int *argc,char ***argv,char **env,int flag) __argc++; - cmdline[i]='\0'; - __argv[__argc-1] = strdup( cmdline+afterlastspace); + _acmdln_dll[i]='\0'; + __argv[__argc-1] = strdup(_acmdln_dll+afterlastspace); HeapValidate(GetProcessHeap(),0,NULL); - - *argc = __argc; - *argv = __argv; - - -// xenv = GetEnvironmentStringsA(); - _environ = &xenv; + + _environ = (char **)GetEnvironmentStringsA();; _environ_dll = &_environ; - environ = &xenv; - env = &xenv; + + argc = __argc_dll; + argv = __argv_dll; + env = _environ_dll; + return 0; } -int _chkstk() +int _chkstk(void) { return 0; } diff --git a/reactos/lib/crtdll/process/execl.c b/reactos/lib/crtdll/process/execl.c index f971024031f..779d8e3e944 100644 --- a/reactos/lib/crtdll/process/execl.c +++ b/reactos/lib/crtdll/process/execl.c @@ -1,10 +1,9 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include +#include -extern char *const *_environ; - -int execl(const char *path, const char *argv0, ...) +int _execl(const char *path, const char *argv0, ...) { - return spawnve(P_OVERLAY, path, (char *const*)&argv0, _environ); + return _spawnve(P_OVERLAY, path, (char *const*)&argv0, _environ); } diff --git a/reactos/lib/crtdll/process/execle.c b/reactos/lib/crtdll/process/execle.c index c68ec0f0868..485c758f776 100644 --- a/reactos/lib/crtdll/process/execle.c +++ b/reactos/lib/crtdll/process/execle.c @@ -10,8 +10,8 @@ u.ccp = *++ptr; \ ptr = u.ccpp; -int execle(const char *path, const char *argv0, ... /*, const char **envp */) +int _execle(const char *path, const char *argv0, ... /*, const char **envp */) { scan_ptr(); - return spawnve(P_OVERLAY, path, (char *const *)&argv0, (char *const *)ptr); + return _spawnve(P_OVERLAY, path, (char *const *)&argv0, (char *const *)ptr); } diff --git a/reactos/lib/crtdll/process/execlp.c b/reactos/lib/crtdll/process/execlp.c index 45c11924729..b25fe9d38fc 100644 --- a/reactos/lib/crtdll/process/execlp.c +++ b/reactos/lib/crtdll/process/execlp.c @@ -1,11 +1,9 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include +#include - -extern char * const *_environ; - -int execlp(const char *path, const char *argv0, ...) +int _execlp(const char *path, const char *argv0, ...) { - return spawnvpe(P_OVERLAY, path, (char * const *)&argv0, _environ); + return _spawnvpe(P_OVERLAY, path, (char * const *)&argv0, _environ); } diff --git a/reactos/lib/crtdll/process/execv.c b/reactos/lib/crtdll/process/execv.c index 893cf85533a..123b69f699d 100644 --- a/reactos/lib/crtdll/process/execv.c +++ b/reactos/lib/crtdll/process/execv.c @@ -1,11 +1,9 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -//#include -//#include + #include +#include -extern char * const *_environ; - -int execv(const char *path, const char * const *argv) +int _execv(const char *path, const char * const *argv) { - return spawnve(P_OVERLAY, path, argv, _environ); + return _spawnve(P_OVERLAY, path, argv, _environ); } diff --git a/reactos/lib/crtdll/process/execvp.c b/reactos/lib/crtdll/process/execvp.c index cdaad875545..b1f15d8090d 100644 --- a/reactos/lib/crtdll/process/execvp.c +++ b/reactos/lib/crtdll/process/execvp.c @@ -1,11 +1,9 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -//#include +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details *///#include //#include #include +#include -extern char *const *_environ; - -int execvp(const char *path,const char * const argv[]) +int _execvp(const char *path,const char * const argv[]) { - return spawnvpe(P_OVERLAY, path, argv, _environ); + return _spawnvpe(P_OVERLAY, path, argv, _environ); } diff --git a/reactos/lib/crtdll/process/execvpe.c b/reactos/lib/crtdll/process/execvpe.c index 7dc668bb1e1..df000454262 100644 --- a/reactos/lib/crtdll/process/execvpe.c +++ b/reactos/lib/crtdll/process/execvpe.c @@ -3,13 +3,9 @@ #include -int execvpe(const char *path,const char * const argv[],const char * const envp[]) -{ - return spawnvpe(P_OVERLAY, path, argv, envp); -} - - int _execvpe(const char *path,const char * const argv[],const char * const envp[]) { - return spawnvpe(P_OVERLAY, path, argv, envp); + return _spawnvpe(P_OVERLAY, path, argv, envp); } + + diff --git a/reactos/lib/crtdll/process/spawnl.c b/reactos/lib/crtdll/process/spawnl.c index 0397fb90413..b0ecf0b248b 100644 --- a/reactos/lib/crtdll/process/spawnl.c +++ b/reactos/lib/crtdll/process/spawnl.c @@ -4,7 +4,7 @@ extern char **_environ; -int spawnl(int mode, const char *path, const char *argv0, ...) +int _spawnl(int mode, const char *path, const char *argv0, ...) { return spawnve(mode, path, (char * const *)&argv0, _environ); } diff --git a/reactos/lib/crtdll/process/spawnle.c b/reactos/lib/crtdll/process/spawnle.c index 157caad1fe5..ff582a81304 100644 --- a/reactos/lib/crtdll/process/spawnle.c +++ b/reactos/lib/crtdll/process/spawnle.c @@ -9,8 +9,8 @@ u.ccp = *++ptr; \ ptr = u.ccpp; -int spawnle(int mode, const char *path, const char *argv0, ... /*, const char **envp */) +int _spawnle(int mode, const char *path, const char *argv0, ... /*, const char **envp */) { scan_ptr(); - return spawnve(mode, path, (char * const *)&argv0, (char * const *)ptr); + return _spawnve(mode, path, (char * const *)&argv0, (char * const *)ptr); } diff --git a/reactos/lib/crtdll/process/spawnlp.c b/reactos/lib/crtdll/process/spawnlp.c index 8813e5cf3a3..568cf8784fe 100644 --- a/reactos/lib/crtdll/process/spawnlp.c +++ b/reactos/lib/crtdll/process/spawnlp.c @@ -1,10 +1,9 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include +#include -extern char **_environ; - -int spawnlp(int mode, const char *path, const char *argv0, ...) +int _spawnlp(int mode, const char *path, const char *argv0, ...) { - return spawnvpe(mode, path, (char * const *)&argv0, (char * const *)_environ); + return _spawnvpe(mode, path, (char * const *)&argv0, (char * const *)_environ); } diff --git a/reactos/lib/crtdll/process/spawnlpe.c b/reactos/lib/crtdll/process/spawnlpe.c index 908e2f4bc24..a4eb9167b44 100644 --- a/reactos/lib/crtdll/process/spawnlpe.c +++ b/reactos/lib/crtdll/process/spawnlpe.c @@ -8,8 +8,8 @@ u.ccp = *++ptr; \ ptr = u.ccpp; -int spawnlpe(int mode, const char *path, const char *argv0, ... /*, const char **envp */) +int _spawnlpe(int mode, const char *path, const char *argv0, ... /*, const char **envp */) { scan_ptr(); - return spawnvpe(mode, path, (char * const *)&argv0, (char * const *)ptr); + return _spawnvpe(mode, path, (char * const *)&argv0, (char * const *)ptr); } diff --git a/reactos/lib/crtdll/process/spawnv.c b/reactos/lib/crtdll/process/spawnv.c index a41b777fff2..71d7403a202 100644 --- a/reactos/lib/crtdll/process/spawnv.c +++ b/reactos/lib/crtdll/process/spawnv.c @@ -1,10 +1,10 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include +#include -extern char **_environ; -int spawnv(int mode, const char *path,const char *const argv[]) +int _spawnv(int mode, const char *path,const char *const argv[]) { - return spawnve(mode, path, (char * const *)argv, _environ); + return _spawnve(mode, path, (char * const *)argv, _environ); } diff --git a/reactos/lib/crtdll/process/spawnve.c b/reactos/lib/crtdll/process/spawnve.c index c848475154f..86c83d573b9 100644 --- a/reactos/lib/crtdll/process/spawnve.c +++ b/reactos/lib/crtdll/process/spawnve.c @@ -3,9 +3,10 @@ #include #include + int _p_overlay = 2; -int spawnve(int mode, const char *path,const char *const argv[],const char *const envp[]) +int _spawnve(int mode, const char *path,const char *const argv[],const char *const envp[]) { char ApplicationName[MAX_PATH]; @@ -35,7 +36,7 @@ int spawnve(int mode, const char *path,const char *const argv[],const char *cons if (mode == P_OVERLAY) - exit(i); + _exit(i); // _P_NOWAIT or _P_NOWAITO return ProcessInformation.hProcess; diff --git a/reactos/lib/crtdll/process/spawnvp.c b/reactos/lib/crtdll/process/spawnvp.c index 34b39ccba75..98f0625a1e7 100644 --- a/reactos/lib/crtdll/process/spawnvp.c +++ b/reactos/lib/crtdll/process/spawnvp.c @@ -1,8 +1,7 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include - -extern char **_environ; +#include int spawnvp(int mode, const char *path,const char *const argv[]) { diff --git a/reactos/lib/crtdll/process/spawnvpe.c b/reactos/lib/crtdll/process/spawnvpe.c index 4ba9a2ec148..7620543870d 100644 --- a/reactos/lib/crtdll/process/spawnvpe.c +++ b/reactos/lib/crtdll/process/spawnvpe.c @@ -4,20 +4,10 @@ #include -int spawnvpe(int mode, const char *path,const char *const argv[],const char *const envp[]) +int _spawnvpe(int mode, const char *path,const char *const argv[],const char *const envp[]) { char rpath[300]; - union {const char * const *cpcp; char **cpp; } u; - u.cpcp = envp; -/* - if (!__dosexec_find_on_path(path, u.cpp, rpath)) - { - errno = ENOENT; - return -1; - } - else -*/ - return spawnve(mode, rpath, argv, envp); + return spawnve(mode, rpath, argv, envp); } diff --git a/reactos/lib/crtdll/stdio/fopen.c b/reactos/lib/crtdll/stdio/fopen.c index a2121282968..40ee5b7d24d 100644 --- a/reactos/lib/crtdll/stdio/fopen.c +++ b/reactos/lib/crtdll/stdio/fopen.c @@ -1,17 +1,14 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -//#include + #include #include #include #include -//#include #include -//#include -//#include + FILE * __alloc_file(void); -extern int _fmode; FILE * fopen(const char *file, const char *mode) diff --git a/reactos/lib/crtdll/stdio/fputc.c b/reactos/lib/crtdll/stdio/fputc.c index 8307d49a62e..82315c44267 100644 --- a/reactos/lib/crtdll/stdio/fputc.c +++ b/reactos/lib/crtdll/stdio/fputc.c @@ -1,5 +1,6 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include +#include #include int @@ -9,7 +10,7 @@ fputc(int c, FILE *fp) } int -fputwc(int c, FILE *fp) +fputwc(wchar_t c, FILE *fp) { return putc(c, fp); } diff --git a/reactos/lib/crtdll/stdio/fputs.c b/reactos/lib/crtdll/stdio/fputs.c index 60b030b4b33..8bb3d7ab5d6 100644 --- a/reactos/lib/crtdll/stdio/fputs.c +++ b/reactos/lib/crtdll/stdio/fputs.c @@ -1,6 +1,7 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include #include +#include #include int @@ -35,7 +36,7 @@ fputs(const char *s, FILE *f) return(r); */ int r = 0; - if ( !WriteFile(filehnd(f->_file),s,strlen(s),&r,NULL) ) + if ( !WriteFile(_get_osfhandle(f->_file),s,strlen(s),&r,NULL) ) return -1; return r; diff --git a/reactos/lib/crtdll/stdio/freopen.c b/reactos/lib/crtdll/stdio/freopen.c index 6940e852764..2eb39b2d82b 100644 --- a/reactos/lib/crtdll/stdio/freopen.c +++ b/reactos/lib/crtdll/stdio/freopen.c @@ -1,13 +1,12 @@ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -//#include + #include #include #include -//#include #include #include -extern int _fmode; + FILE * freopen(const char *file, const char *mode, FILE *f) diff --git a/reactos/lib/crtdll/stdio/fsetpos.c b/reactos/lib/crtdll/stdio/fsetpos.c index 1511e188a04..491b9ad46c3 100644 --- a/reactos/lib/crtdll/stdio/fsetpos.c +++ b/reactos/lib/crtdll/stdio/fsetpos.c @@ -1,15 +1,16 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include #include +#include int -fsetpos(FILE *stream, const fpos_t *pos) +fsetpos(FILE *stream, fpos_t *pos) { if (stream && pos) { fseek(stream, (long)(*pos), SEEK_SET); return 0; } - //errno = EFAULT; - return 1; + __set_errno(EFAULT); + return -1; } diff --git a/reactos/lib/crtdll/stdio/getc.c b/reactos/lib/crtdll/stdio/getc.c index fa976d4e6f9..c283ff684f6 100644 --- a/reactos/lib/crtdll/stdio/getc.c +++ b/reactos/lib/crtdll/stdio/getc.c @@ -3,12 +3,11 @@ #include #include -#undef getc int getc(FILE *f) { int c; DWORD NumberOfBytesRead; - if ( !ReadFile(filehnd(f->_file),&c, 1, &NumberOfBytesRead, NULL) ) + if ( !ReadFile(_get_osfhandle(f->_file),&c, 1, &NumberOfBytesRead, NULL) ) return -1; if ( NumberOfBytesRead == 0 ) return -1; diff --git a/reactos/lib/crtdll/stdio/putc.c b/reactos/lib/crtdll/stdio/putc.c index 7db1d620ab1..78317a766e9 100644 --- a/reactos/lib/crtdll/stdio/putc.c +++ b/reactos/lib/crtdll/stdio/putc.c @@ -3,7 +3,6 @@ #include #include -#undef putc int putc(int c, FILE *fp) { @@ -21,7 +20,7 @@ int putc(int c, FILE *fp) } return(_flsbuf(c,fp)); } - if ( !WriteFile(filehnd(fp->_file),&c,1,&r,NULL) ) + if ( !WriteFile(_get_osfhandle(fp->_file),&c,1,&r,NULL) ) return -1; return r; diff --git a/reactos/lib/crtdll/stdio/puts.c b/reactos/lib/crtdll/stdio/puts.c index 6df4b63a4e3..6bc80111502 100644 --- a/reactos/lib/crtdll/stdio/puts.c +++ b/reactos/lib/crtdll/stdio/puts.c @@ -1,6 +1,8 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include +#include #include +#include #undef putchar int @@ -14,8 +16,8 @@ puts(const char *s) return putchar('\n'); */ int r = 0; - if ( !WriteFile(filehnd(stdout->_file),s,strlen(s),&r,NULL) ) + if ( !WriteFile(_get_osfhandle(stdout->_file),s,strlen(s),&r,NULL) ) return -1; - return putchar('\n');; + return putchar('\n'); } diff --git a/reactos/lib/crtdll/stdlib/bsearch.c b/reactos/lib/crtdll/stdlib/bsearch.c index 5d6b5d64128..d6a5bac6108 100644 --- a/reactos/lib/crtdll/stdlib/bsearch.c +++ b/reactos/lib/crtdll/stdlib/bsearch.c @@ -1,11 +1,11 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -// #include void * -bsearch(const void *key, const void *base, size_t nelem, +bsearch(const void *key, const void *base0, size_t nelem, size_t size, int (*cmp)(const void *ck, const void *ce)) { + char *base = (char *)base0; int lim, cmpval; void *p; diff --git a/reactos/lib/crtdll/stdlib/errno.c b/reactos/lib/crtdll/stdlib/errno.c index e3c72ca7c93..0463b943b81 100644 --- a/reactos/lib/crtdll/stdlib/errno.c +++ b/reactos/lib/crtdll/stdlib/errno.c @@ -1,3 +1,4 @@ +#include #include #undef errno @@ -6,6 +7,9 @@ int errno; #undef _doserrno int _doserrno; +#undef _fpecode +int fpecode; + int *_errno(void) { return &errno; @@ -22,7 +26,7 @@ int __set_errno (int error) int * __fpecode ( void ) { - return NULL; + return &fpecode; } int* __doserrno(void) diff --git a/reactos/lib/crtdll/stdlib/qsort.c b/reactos/lib/crtdll/stdlib/qsort.c index 456834ffe74..a65c6b58a4a 100644 --- a/reactos/lib/crtdll/stdlib/qsort.c +++ b/reactos/lib/crtdll/stdlib/qsort.c @@ -171,9 +171,8 @@ qst(char *base, char *max) * with qst(), and then a cleanup insertion sort ourselves. Sound simple? * It's not... */ - void -qsort(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *)) +qsort(const void *base0, size_t n, size_t size, _pfunccmp_t compar) { char *base = (char *)base0; char c, *i, *j, *lo, *hi; diff --git a/reactos/lib/crtdll/stdlib/strtol.c b/reactos/lib/crtdll/stdlib/strtol.c index 362f9bcce2e..51a25222d96 100644 --- a/reactos/lib/crtdll/stdlib/strtol.c +++ b/reactos/lib/crtdll/stdlib/strtol.c @@ -3,7 +3,7 @@ #include #include #include - +#include long strtol(const char *nptr, char **endptr, int base) @@ -81,7 +81,7 @@ strtol(const char *nptr, char **endptr, int base) if (any < 0) { acc = neg ? LONG_MIN : LONG_MAX; - errno = ERANGE; + __set_errno(ERANGE); } else if (neg) acc = -acc; diff --git a/reactos/lib/crtdll/stdlib/strtoul.c b/reactos/lib/crtdll/stdlib/strtoul.c index d62bd5366b0..d076d07f35d 100644 --- a/reactos/lib/crtdll/stdlib/strtoul.c +++ b/reactos/lib/crtdll/stdlib/strtoul.c @@ -3,7 +3,8 @@ #include #include #include -#include +#include + /* * Convert a string to an unsigned long integer. @@ -65,11 +66,11 @@ strtoul(const char *nptr, char **endptr, int base) if (any < 0) { acc = ULONG_MAX; - errno = ERANGE; + __set_errno(ERANGE); } else if (neg) acc = -acc; if (endptr != 0) - *endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *); + *endptr = any ? (char *)s - 1 : (char *)nptr; return acc; } diff --git a/reactos/lib/crtdll/sys_stat/fstat.c b/reactos/lib/crtdll/sys_stat/fstat.c index dc7b05455bb..d8deb06828c 100644 --- a/reactos/lib/crtdll/sys_stat/fstat.c +++ b/reactos/lib/crtdll/sys_stat/fstat.c @@ -20,7 +20,7 @@ fstat(int handle, struct stat *statbuf) return -1; } - if ( !GetFileInformationByHandle(filehnd(handle),&FileInformation) ) + if ( !GetFileInformationByHandle(_get_osfhandle(handle),&FileInformation) ) return -1; statbuf->st_ctime = FileTimeToUnixTime( &FileInformation.ftCreationTime,NULL); statbuf->st_atime = FileTimeToUnixTime( &FileInformation.ftLastAccessTime,NULL); diff --git a/reactos/lib/crtdll/time/clock.c b/reactos/lib/crtdll/time/clock.c new file mode 100644 index 00000000000..3814ebcee95 --- /dev/null +++ b/reactos/lib/crtdll/time/clock.c @@ -0,0 +1,34 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/time/clock.c + * PURPOSE: Get elapsed time + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Created + */ + +#include +#include + +// should be replace by a call to RtltimeToSecondsSince70 +time_t FileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder ); + +clock_t clock ( void ) +{ + FILETIME CreationTime; + FILETIME ExitTime; + FILETIME KernelTime; + FILETIME UserTime; + + FILETIME SystemTime; + DWORD Remainder; + + if ( !GetProcessTimes(-1,&CreationTime,&ExitTime,&KernelTime,&UserTime ) ) + return -1; + + if ( !GetSystemTimeAsFileTime(&SystemTime) ) + return -1; + + return FileTimeToUnixTime( &SystemTime,&Remainder ) - FileTimeToUnixTime( &CreationTime,&Remainder ); +} \ No newline at end of file diff --git a/reactos/lib/crtdll/time/ctime.c b/reactos/lib/crtdll/time/ctime.c index b16b38fe783..b00098f4d95 100644 --- a/reactos/lib/crtdll/time/ctime.c +++ b/reactos/lib/crtdll/time/ctime.c @@ -37,24 +37,8 @@ static char sccsid[] = "@(#)ctime.c 5.23 (Berkeley) 6/22/90"; */ -#ifndef _TM_DEFINED -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; - char *tm_zone; - int tm_gmtoff; -}; -#define _TM_DEFINED -#endif -//#include + #include #include #include @@ -63,11 +47,8 @@ struct tm { #include #include -//#include #include "tzfile.h" -//#include - #include #include "posixrul.h" @@ -1422,12 +1403,5 @@ mktime(struct tm * tmp) } -time_t -time(time_t *t) -{ - SYSTEMTIME SystemTime; - GetLocalTime(&SystemTime); - - -} + diff --git a/reactos/lib/crtdll/time/strftime.c b/reactos/lib/crtdll/time/strftime.c index 32c6973950a..252448e0984 100644 --- a/reactos/lib/crtdll/time/strftime.c +++ b/reactos/lib/crtdll/time/strftime.c @@ -1,21 +1,6 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include -#ifndef _TM_DEFINED -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; - char *tm_zone; - int tm_gmtoff; -}; -#define _TM_DEFINED -#endif + #include diff --git a/reactos/lib/crtdll/time/time.c b/reactos/lib/crtdll/time/time.c index 4ff00485a74..f682a7c0caa 100644 --- a/reactos/lib/crtdll/time/time.c +++ b/reactos/lib/crtdll/time/time.c @@ -1,30 +1,27 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#ifndef _TM_DEFINED -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; - char *tm_zone; - int tm_gmtoff; -}; -#define _TM_DEFINED -#endif +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/conio/time.c + * PURPOSE: Get system time + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 28/12/98: Created + */ -#include #include +#include +// should be replace by a call to RtltimeToSecondsSince70 +// and moved to a header + +time_t FileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder ); time_t time(time_t *t) { - SYSTEMTIME SystemTime; - GetLocalTime(&SystemTime); - - + FILETIME SystemTime; + DWORD Remainder; + GetSystemTimeAsFileTime(&SystemTime); + return FileTimeToUnixTime( &SystemTime,&Remainder ); } +