diff --git a/reactos/lib/crtdll/conio/cgets.c b/reactos/lib/crtdll/conio/cgets.c new file mode 100644 index 00000000000..3e225dff0dc --- /dev/null +++ b/reactos/lib/crtdll/conio/cgets.c @@ -0,0 +1,64 @@ +#include + + +char * +_cgets(char *string) +{ + unsigned len = 0; + unsigned int maxlen_wanted; + char *sp; + int c; + /* + * Be smart and check for NULL pointer. + * Don't know wether TURBOC does this. + */ + if (!string) + return(NULL); + maxlen_wanted = (unsigned int)((unsigned char)string[0]); + sp = &(string[2]); + /* + * Should the string be shorter maxlen_wanted including or excluding + * the trailing '\0' ? We don't take any risk. + */ + while(len < maxlen_wanted-1) + { + c=getch(); + /* + * shold we check for backspace here? + * TURBOC does (just checked) but doesn't in cscanf (thats harder + * or even impossible). We do the same. + */ + if (c == '\b') + { + if (len > 0) + { + cputs("\b \b"); /* go back, clear char on screen with space + and go back again */ + len--; + sp[len] = '\0'; /* clear the character in the string */ + } + } + else if (c == '\r') + { + sp[len] = '\0'; + break; + } + else if (c == 0) + { + /* special character ends input */ + sp[len] = '\0'; + ungetch(c); /* keep the char for later processing */ + break; + } + else + { + sp[len] = putch(c); + len++; + } + } + sp[maxlen_wanted-1] = '\0'; + string[1] = (char)((unsigned char)len); + return(sp); +} + + diff --git a/reactos/lib/crtdll/io/find.c b/reactos/lib/crtdll/io/find.c index 2015fef82fe..5010cf15f4a 100644 --- a/reactos/lib/crtdll/io/find.c +++ b/reactos/lib/crtdll/io/find.c @@ -2,10 +2,6 @@ #include #include -#if 0 - -//UnixTimeToFileTime -//FileTimeToUnixTime /* * DOS file system functions * @@ -18,7 +14,7 @@ void UnixTimeToFileTime( time_t unix_time, FILETIME *filetime, DWORD remainder ) time_t FileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder ); -long _findfirst(char *_name, struct _finddata_t *result) +int _findfirst(const char *_name, struct _finddata_t *result) { WIN32_FIND_DATA FindFileData; char dir[MAX_PATH]; @@ -32,7 +28,7 @@ long _findfirst(char *_name, struct _finddata_t *result) } else strcpy(dir,_name); - hFindFile = FindFirstFile( dir, &FindFileData ); + hFindFile = FindFirstFileA( dir, &FindFileData ); result->attrib = FindFileData.dwFileAttributes; @@ -44,7 +40,7 @@ long _findfirst(char *_name, struct _finddata_t *result) return hFindFile; } -int _findnext(long handle, struct _finddata_t *result) +int _findnext(int handle, struct _finddata_t *result) { WIN32_FIND_DATA FindFileData; if (handle == -1 ) @@ -61,7 +57,7 @@ int _findnext(long handle, struct _finddata_t *result) strncpy(result->name,&FindFileData.cFileName,260); return 0; } -int _findclose(long handle) +int _findclose(int handle) { return FindClose(handle); } @@ -252,4 +248,4 @@ time_t FileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder ) } -#endif + diff --git a/reactos/lib/crtdll/misc/GetArgs.c b/reactos/lib/crtdll/misc/GetArgs.c index b6e6f5da59d..cd581898e89 100644 --- a/reactos/lib/crtdll/misc/GetArgs.c +++ b/reactos/lib/crtdll/misc/GetArgs.c @@ -50,13 +50,13 @@ int __GetMainArgs(int *argc,char ***argv,char **env,int flag) cmdline = GetCommandLineA(); afterlastspace=0; - dprintf("cmdline '%s'\n",cmdline); + //dprintf("cmdline '%s'\n",cmdline); while (cmdline[i]) { if (cmdline[i]==' ') { - dprintf("cmdline '%s'\n",cmdline); + // dprintf("cmdline '%s'\n",cmdline); __argc++; cmdline[i]='\0'; __argv[__argc-1] = strdup( cmdline+afterlastspace); @@ -90,7 +90,7 @@ int __GetMainArgs(int *argc,char ***argv,char **env,int flag) return 0; } -int _chkstk() +int _chkstk(void) { return 0; } diff --git a/reactos/lib/crtdll/stdio/popen.c b/reactos/lib/crtdll/stdio/popen.c new file mode 100644 index 00000000000..eb08468b4d6 --- /dev/null +++ b/reactos/lib/crtdll/stdio/popen.c @@ -0,0 +1,64 @@ + +#include +#include +#include +#include +#include +//#include +#include + + + +int __fileno_alloc(HANDLE hFile, int mode); + + + +FILE * +_popen (const char *cm, const char *md) /* program name, pipe mode */ +{ + FILE *pf; + HANDLE hReadPipe, hWritePipe; + HANDLE SpawnedProcess; + STARTUPINFO StartupInfo; + PROCESS_INFORMATION ProcessInformation; + if ( !CreatePipe(&hReadPipe,&hWritePipe,NULL,1024,)) + return NULL; + + StartupInfo.cb = sizeof(STARTUPINFO); + if ( md == "r" ) { + StartupInfo.hStdOutput = hWritePipe; + } + else if ( md == "w" ) { + StartupInfo.hStdInput = hReadPipe; + } + + SpawnedProcess = CreateProcess("cmd.exe",cm,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&StartupInfo,&ProcessInformation ); + + + if ( *md == 'r' ) { + pf = _fdopen( __fileno_alloc(hReadPipe, O_RDONLY) , "r" ); + } + else { + pf = _fdopen( __fileno_alloc(hWritePipe, _O_WRONLY) , "w" ); + } + + pf->name_to_remove = SpawnedProcess; + + return pf; + + +} +FILE* _wpopen (const wchar_t* szPipeName, const wchar_t* szMode) +{ + return NULL; +} + +int +pclose (FILE *pp) +{ + + fclose(pp); + if (!TerminateProcess(pp->name_to_remove,0)) + return -1; + return 0; +} diff --git a/reactos/lib/crtdll/stdio/rmtmp.c b/reactos/lib/crtdll/stdio/rmtmp.c new file mode 100644 index 00000000000..883c4919713 --- /dev/null +++ b/reactos/lib/crtdll/stdio/rmtmp.c @@ -0,0 +1,50 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/crtdll/stdio/rmtmp.c + * PURPOSE: remove temporary files in current directory + * PROGRAMMER: Boudewijn ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 19/01/99 + * NOTE Not tested. + */ +extern __file_rec *__file_rec_list; + +int _rmtmp( void ) +{ +/* +loop files and check for name_to_remove +*/ + __file_rec *fr = __file_rec_list; + __file_rec **last_fr = &__file_rec_list; + + int total_closed; + int i = 0; + char temp_name[260]; + + /* Try to find an empty slot */ + while (fr) + { + last_fr = &(fr->next); + + /* If one of the existing slots is available, return it */ + for (i=0; icount; i++) { + if (fr->files[i]->_name_to_remove != NULL) { + if ( access(fr->files[i]->_name_to_remove) ) { + strcpy(temp_name,fr->files[i]->_name_to_remove); + fclose(fr->files[i]); + remove(temp_name); + total_closed++; + } + } + } + + /* If this one is full, go to the next */ + if (fr->count == __FILE_REC_MAX) + fr = fr->next; + else + /* it isn't full, we can add to it */ + break; + } + return total_closed; +} \ No newline at end of file diff --git a/reactos/lib/crtdll/stdlib/errno.c b/reactos/lib/crtdll/stdlib/errno.c index ac6f7266165..6b10425fdd6 100644 --- a/reactos/lib/crtdll/stdlib/errno.c +++ b/reactos/lib/crtdll/stdlib/errno.c @@ -1,13 +1,18 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ +#include #include -#undef errno -int errno; -int _doserrno; +int __crtdll_errno; - -int _errno(void) +int *_errno(void) { - return errno; + __crtdll_errno = GetLastError(); + return &__crtdll_errno; +} + +int *__dos_errno(void) +{ + __crtdll_errno = GetLastError(); + return &__crtdll_errno; } diff --git a/reactos/lib/crtdll/stdlib/strtol.c b/reactos/lib/crtdll/stdlib/strtol.c index aec08d1f477..14861a3dd7a 100644 --- a/reactos/lib/crtdll/stdlib/strtol.c +++ b/reactos/lib/crtdll/stdlib/strtol.c @@ -82,7 +82,7 @@ strtol(const char *nptr, char **endptr, int base) if (any < 0) { acc = neg ? LONG_MIN : LONG_MAX; - errno = ERANGE; +// errno = ERANGE; } else if (neg) acc = -acc; @@ -168,7 +168,7 @@ wcstol(const wchar_t *nptr, wchar_t **endptr, int base) if (any < 0) { acc = neg ? LONG_MIN : LONG_MAX; - errno = ERANGE; + // errno = ERANGE; } else if (neg) acc = -acc; diff --git a/reactos/lib/crtdll/stdlib/strtoul.c b/reactos/lib/crtdll/stdlib/strtoul.c index 9638aaefe1d..dfe6f8542d1 100644 --- a/reactos/lib/crtdll/stdlib/strtoul.c +++ b/reactos/lib/crtdll/stdlib/strtoul.c @@ -65,7 +65,7 @@ strtoul(const char *nptr, char **endptr, int base) if (any < 0) { acc = ULONG_MAX; - errno = ERANGE; + // errno = ERANGE; } else if (neg) acc = -acc; @@ -128,7 +128,7 @@ wcstoul(const wchar_t *nptr, wchar_t **endptr, int base) if (any < 0) { acc = ULONG_MAX; - errno = ERANGE; + // errno = ERANGE; } else if (neg) acc = -acc;