diff --git a/reactos/lib/crtdll/misc/amsg.c b/reactos/lib/crtdll/misc/amsg.c index dd991c9cf86..3ea80ee9122 100644 --- a/reactos/lib/crtdll/misc/amsg.c +++ b/reactos/lib/crtdll/misc/amsg.c @@ -1,5 +1,15 @@ +/* + * 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 +#include int _aexit_rtn_dll(int exitcode) { @@ -8,7 +18,7 @@ int _aexit_rtn_dll(int exitcode) void _amsg_exit (int errnum) { - fprintf(stdout,strerror(errnum)); + fprintf(stderr,strerror(errnum)); _aexit_rtn_dll(-1); } diff --git a/reactos/lib/crtdll/process/_cwait.c b/reactos/lib/crtdll/process/_cwait.c index a437c756a2e..df93d52b3d0 100644 --- a/reactos/lib/crtdll/process/_cwait.c +++ b/reactos/lib/crtdll/process/_cwait.c @@ -1,3 +1,12 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/process/cwait.c + * PURPOSE: Waits for a process to exit + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 04/03/99: Created + */ #include #include #include diff --git a/reactos/lib/crtdll/process/_system.c b/reactos/lib/crtdll/process/_system.c index 64f6af59d68..98bd05b39a0 100644 --- a/reactos/lib/crtdll/process/_system.c +++ b/reactos/lib/crtdll/process/_system.c @@ -1,18 +1,83 @@ -#include +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/process/system.c + * PURPOSE: Excutes a shell command + * PROGRAMER: Boudewijn Dekker + * UPDATE HISTORY: + * 04/03/99: Created + */ #include #include #include +#include int system(const char *command) { - char CmdLine[MAX_PATH]; - char *comspec = getenv("COMSPEC"); - if ( comspec == NULL ) - comspec = "cmd.exe"; - strcpy(CmdLine,comspec); - strcat(CmdLine," /C "); - if ( !WinExec(CmdLine,SW_SHOWNORMAL) < 31 ) - return -1; + char szCmdLine[MAX_PATH]; + char *szComSpec; + - return 0; + PROCESS_INFORMATION ProcessInformation; + STARTUPINFO StartupInfo; + + int nStatus; + + szComSpec = getenv("COMSPEC"); + +// system should return 0 if command is null and the shell is found + + if ( command == NULL ) { + if ( szComspec == NULL ) + return 0; + else + return -1; + } + + + +// should return 127 or 0 ( MS ) if the shell is not found +// __set_errno(ENOENT); + + if ( szComSpec == NULL ) + szComSpec = "cmd.exe"; + + + + strcpy(szCmdLine," /C "); + + strncat(szCmdLine,command,MAX_PATH-5); + +//check for a too long argument E2BIG + +//command file has invalid format ENOEXEC + + + StartupInfo.cb = sizeof(STARTUPINFO); + StartupInfo.lpReserved= NULL; + StartupInfo.dwFlags = 0; + StartupInfo.wShowWindow = SW_SHOWDEFAULT; + StartupInfo.lpReserved2 = NULL; + StartupInfo.cbReserved2 = 0; + +// According to ansi standards the new process should ignore SIGINT and SIGQUIT +// In order to disable ctr-c the process is created with CREATE_NEW_PROCESS_GROUP, +// thus SetConsoleCtrlHandler(NULL,TRUE) is made on behalf of the new process. + + +//SIGCHILD should be blocked aswell + + if ( CreateProcessA(szComSpec,szCmdLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,NULL,&StartupInfo,&ProcessInformation) == FALSE) { + return -1; + } + + +// system should wait untill the calling process is finished + + _cwait(&nStatus,(int)ProcessInformation.hProcess,0); + +// free the comspec [ if the COMSPEC == NULL provision is removed + // free(szComSpec); + + return nStatus; } diff --git a/reactos/lib/crtdll/stdio/fflush.c b/reactos/lib/crtdll/stdio/fflush.c index 353ebafb162..6d7197d1bea 100644 --- a/reactos/lib/crtdll/stdio/fflush.c +++ b/reactos/lib/crtdll/stdio/fflush.c @@ -1,3 +1,12 @@ +/* + * 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 + */ /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ diff --git a/reactos/lib/crtdll/stdio/fopen.c b/reactos/lib/crtdll/stdio/fopen.c index b145c5938fc..ee416820693 100644 --- a/reactos/lib/crtdll/stdio/fopen.c +++ b/reactos/lib/crtdll/stdio/fopen.c @@ -6,6 +6,7 @@ #include #include +//might change fopen(file,mode) -> fsopen(file,mode,_SH_DENYNO); FILE * __alloc_file(void); diff --git a/reactos/lib/crtdll/stdio/fsopen.c b/reactos/lib/crtdll/stdio/fsopen.c index ff2e8b0127d..9c1481929c6 100644 --- a/reactos/lib/crtdll/stdio/fsopen.c +++ b/reactos/lib/crtdll/stdio/fsopen.c @@ -1,3 +1,12 @@ +/* + * 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 + */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include @@ -5,6 +14,7 @@ #include #include #include +#include FILE * __alloc_file(void); @@ -16,6 +26,8 @@ FILE* _fsopen(const char *file, const char *mode, int shflag) int fd, rw, oflags = 0; char tbchar; + int shf; + if (file == 0) return 0; if (mode == 0) @@ -53,14 +65,19 @@ FILE* _fsopen(const char *file, const char *mode, int shflag) oflags |= (_fmode & (O_TEXT|O_BINARY)); -//_SH_COMPAT Sets Compatibility mode for 16-bit applications -//_SH_DENYNO Permits read and write access -//_SH_DENYRD Denies read access to file -//_SH_DENYRW Denies read and write access to file -//_SH_DENYWR Denies write access to file - - fd = _open(file, oflags, shflag); + if ( shflag == _SH_DENYNO ) + shf = _S_IREAD | _S_IWRITE; + else if( shflag == _SH_DENYRD ) + shf = _S_IWRITE; + else if( shflag == _SH_DENYRW ) + shf = 0; + else if( shflag == _SH_DENYWR ) + shf = _S_IREAD; + else + shf = _S_IREAD | _S_IWRITE; + + fd = _open(file, oflags, shf); if (fd < 0) return NULL;