diff --git a/reactos/dll/win32/crtdll/crtdll.def b/reactos/dll/win32/crtdll/crtdll.def index 6a3c0ff01b8..7c0199eb0dd 100644 --- a/reactos/dll/win32/crtdll/crtdll.def +++ b/reactos/dll/win32/crtdll/crtdll.def @@ -309,8 +309,8 @@ _setjmp _setmode _setsystime _sleep -_snprintf=crt__snprintf -_snwprintf=crt__snwprintf +_snprintf +_snwprintf _sopen _spawnl _spawnle @@ -499,7 +499,7 @@ setvbuf signal sin=NTDLL.sin sinh -sprintf=crt_sprintf +sprintf sqrt=NTDLL.sqrt srand sscanf @@ -525,7 +525,7 @@ strtol=NTDLL.strtol strtoul strtoull strxfrm -swprintf=crt_swprintf +swprintf swscanf system tan=NTDLL.tan diff --git a/reactos/dll/win32/crtdll/dllmain.c b/reactos/dll/win32/crtdll/dllmain.c index 4f41f358e26..a97de0cc312 100644 --- a/reactos/dll/win32/crtdll/dllmain.c +++ b/reactos/dll/win32/crtdll/dllmain.c @@ -2,7 +2,7 @@ * * dllmain.c * - * ReactOS MSVCRT.DLL Compatibility Library + * ReactOS CRTDLL.DLL Compatibility Library * * THIS SOFTWARE IS NOT COPYRIGHTED * @@ -14,10 +14,6 @@ * DISCLAMED. This includes but is not limited to warrenties of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * $Revision: 1.24 $ - * $Author: mf $ - * $Date: 2005-01-06 14:58:04 +0100 (Thu, 06 Jan 2005) $ - * */ #include @@ -32,8 +28,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(crtdll); /* EXTERNAL PROTOTYPES ********************************************************/ -//void __fileno_init(void); -extern BOOL __fileno_init(void); extern int BlockEnvToEnvironA(void); extern int BlockEnvToEnvironW(void); extern void FreeEnvironment(char **environment); @@ -136,8 +130,6 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) hHeap = HeapCreate(0, 100000, 0); if (hHeap == NULL) return FALSE; - if (!__fileno_init()) - return FALSE; /* create tls stuff */ if (!CreateThreadData()) @@ -159,6 +151,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) /* FIXME: Initialization of the WINE code */ msvcrt_init_mt_locks(); + msvcrt_init_io(); setlocale(0, "C"); //_setmbcp(_MB_CP_LOCALE); @@ -174,8 +167,9 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) case DLL_PROCESS_DETACH://0 //TRACE("Detach %d\n", nAttachCount); - /* FIXME: more cleanup... */ - _fcloseall(); + /* Deinit of the WINE code */ + msvcrt_free_io(); + msvcrt_free_mt_locks(); _atexit_cleanup(); /* destroy tls stuff */ diff --git a/reactos/dll/win32/msvcrt/dllmain.c b/reactos/dll/win32/msvcrt/dllmain.c index ca835f2612a..ebc67729b47 100644 --- a/reactos/dll/win32/msvcrt/dllmain.c +++ b/reactos/dll/win32/msvcrt/dllmain.c @@ -30,8 +30,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); /* EXTERNAL PROTOTYPES ********************************************************/ -//void __fileno_init(void); -extern BOOL __fileno_init(void); extern int BlockEnvToEnvironA(void); extern int BlockEnvToEnvironW(void); extern void FreeEnvironment(char **environment); @@ -76,8 +74,6 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) hHeap = HeapCreate(0, 100000, 0); if (hHeap == NULL) return FALSE; - if (!__fileno_init()) - return FALSE; /* create tls stuff */ if (!CreateThreadData()) @@ -99,6 +95,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) /* Initialization of the WINE code */ msvcrt_init_mt_locks(); + msvcrt_init_io(); setlocale(0, "C"); //_setmbcp(_MB_CP_LOCALE); @@ -116,9 +113,13 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) //DPRINT1("Detach %d\n", nAttachCount); //DPRINT("Detach\n"); /* FIXME: more cleanup... */ - _fcloseall(); + /* Deinit of the WINE code */ + msvcrt_free_io(); + msvcrt_free_mt_locks(); + _atexit_cleanup(); + /* destroy tls stuff */ DestroyThreadData(); diff --git a/reactos/dll/win32/msvcrt/msvcrt.def b/reactos/dll/win32/msvcrt/msvcrt.def index 4eeec831703..325551888cf 100644 --- a/reactos/dll/win32/msvcrt/msvcrt.def +++ b/reactos/dll/win32/msvcrt/msvcrt.def @@ -497,9 +497,9 @@ EXPORTS _setmode @490 _setsystime @491 _sleep @492 - _snprintf=crt__snprintf @493 + _snprintf @493 ; _snscanf @494 - _snwprintf=crt__snwprintf @495 + _snwprintf @495 ; _snwscanf @496 _sopen @497 _spawnl @498 @@ -761,7 +761,7 @@ EXPORTS putc @754 putchar @755 puts @756 - putwc @757 + putwc=fputwc @757 putwchar=_fputwchar @758 qsort=ntdll.qsort @759 raise @760 @@ -777,7 +777,7 @@ EXPORTS signal @770 sin=ntdll.sin @771 sinh @772 - sprintf=crt_sprintf @773 + sprintf @773 sqrt=ntdll.sqrt @774 srand @775 sscanf @776 @@ -802,7 +802,7 @@ EXPORTS strtol=ntdll.strtol @795 strtoul=ntdll.strtoul @796 strxfrm @797 - swprintf=crt_swprintf @798 + swprintf @798 swscanf @799 system @800 tan=ntdll.tan @801 diff --git a/reactos/include/crt/stdio.h b/reactos/include/crt/stdio.h index 90011fed757..b32edaf8da3 100644 --- a/reactos/include/crt/stdio.h +++ b/reactos/include/crt/stdio.h @@ -30,9 +30,16 @@ /* Flags for the iobuf structure */ -#define _IOREAD 1 /* currently reading */ -#define _IOWRT 2 /* currently writing */ -#define _IORW 0x0080 /* opened as "r+w" */ +#define _IOREAD 0x0001 /* currently reading */ +#define _IOWRT 0x0002 /* currently writing */ +#define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */ +#define _IOEOF 0x0010 /* EOF reached on read */ +#define _IOERR 0x0020 /* I/O error from system */ +#define _IOSTRG 0x0040 /* Strange or no file descriptor */ +#define _IORW 0x0080 /* opened as "r+w" */ +#ifdef _POSIX_SOURCE +# define _IOAPPEND 0x0200 +#endif /* @@ -87,13 +94,6 @@ #define _IOLBF 0x0040 /* line buffered */ #define _IONBF 0x0004 /* not buffered */ -#define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */ -#define _IOEOF 0x0010 /* EOF reached on read */ -#define _IOERR 0x0020 /* I/O error from system */ -#define _IOSTRG 0x0040 /* Strange or no file descriptor */ -#ifdef _POSIX_SOURCE -# define _IOAPPEND 0x0200 -#endif /* * The buffer size as used by setbuf such that it is equivalent to * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ). @@ -456,7 +456,7 @@ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*); _CRTIMP wint_t __cdecl __MINGW_NOTHROW putwc (wint_t, FILE*); _CRTIMP int __cdecl __MINGW_NOTHROW _putws (const wchar_t*); _CRTIMP wint_t __cdecl __MINGW_NOTHROW putwchar (wint_t); -_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfdopen(int, wchar_t *); +_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfdopen(int, const wchar_t *); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfopen (const wchar_t*, const wchar_t*); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfreopen (const wchar_t*, const wchar_t*, FILE*); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfsopen (const wchar_t*, const wchar_t*, int); diff --git a/reactos/lib/sdk/crt/README.txt b/reactos/lib/sdk/crt/README.txt index 457352e96c6..3ab5606ffdb 100644 --- a/reactos/lib/sdk/crt/README.txt +++ b/reactos/lib/sdk/crt/README.txt @@ -1,13 +1,10 @@ -This file contains information about the status the MSVCRT runtime in ReactOS. +Big chunks of this CRT library are taken from Wine's msvcrt implementation, +you can find a list of synced files in README.WINE file. -Please note that all of the MSVCRT.DLL runtime sources are license GPL unless -otherwise noted. The sources from WINE are dual licensed GPL/LGPL. -If you update a function in the ~/wine directory please send a patch to wine-patches@winehq.com - -TODO List: -Implement the remaining functions that are commented out in the .def file -Update source code headers for the license information. -Complete the W32API conversion for all source files. -Write a decent regression test suite. -Convert all C++ style comments to C style comments. -???? +Notes: +1. When syncing, omit MSVCRT_ prefix where possible, Wine has to keep this +because they are linking with *both* original crt, and ms crt implementation. +ReactOS has the only CRT, so no need to make distinct functions. +2. ReactOS compiles two versions of the CRT library, one for usermode +(called just "crt"), and one version for kernelmode usage (called "libcntpr"). +In order to separate the code, you can use #ifdef _LIBCNT_ for libcntpr code. \ No newline at end of file diff --git a/reactos/lib/sdk/crt/conio/cputs.c b/reactos/lib/sdk/crt/conio/cputs.c index cc34736c2ca..4a781e5e3c7 100644 --- a/reactos/lib/sdk/crt/conio/cputs.c +++ b/reactos/lib/sdk/crt/conio/cputs.c @@ -1,23 +1,35 @@ /* - * COPYRIGHT: See COPYING in the top level directory + * COPYRIGHT: LGPL - See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/msvcrt/conio/cputs.c * PURPOSE: Writes a character to stdout - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created + * PROGRAMER: Aleksey Bragin */ #include +extern FDINFO *fdesc; + /* * @implemented */ int _cputs(const char *_str) { +#if 0 + DWORD count; + int retval = EOF; + + LOCK_CONSOLE; + if (WriteConsoleA(console_out, str, strlen(str), &count, NULL) + && count == 1) + retval = 0; + UNLOCK_CONSOLE; + return retval; +#else int len = strlen(_str); DWORD written = 0; - if (!WriteFile( fdinfo(stdout->_file)->hFile ,_str,len,&written,NULL)) + if (!WriteFile( fdesc[stdout->_file].hFile ,_str,len,&written,NULL)) return -1; return 0; +#endif } diff --git a/reactos/lib/sdk/crt/crt.rbuild b/reactos/lib/sdk/crt/crt.rbuild index 12b8df32cef..126f574b41a 100644 --- a/reactos/lib/sdk/crt/crt.rbuild +++ b/reactos/lib/sdk/crt/crt.rbuild @@ -76,46 +76,6 @@ - - access.c - chmod.c - chsize.c - close.c - commit.c - creat.c - dup.c - dup2.c - eof.c - filelen.c - fileleni.c - find.c - fmode.c - isatty.c - locking.c - lseek.c - lseeki64.c - mktemp.c - open.c - pipe.c - read.c - setmode.c - sopen.c - stubs.c - tell.c - telli64.c - umask.c - unlink.c - utime.c - waccess.c - wchmod.c - wcreat.c - wfind.c - wmktemp.c - wopen.c - write.c - wunlink.c - wutime.c - locale.c @@ -272,79 +232,20 @@ xcptinfo.c - allocfil.c - clearerr.c - fclose.c - fdopen.c - feof.c - ferror.c - fflush.c - fgetc.c - fgetchar.c - fgetpos.c - fgets.c - fgetws.c - filbuf.c + access.c file.c - fileno.c - flsbuf.c - fopen.c - fprintf.c - fputc.c - fputchar.c - fputs.c - fputws.c - fread.c - freopen.c - fseek.c - fsetpos.c - fsopen.c - ftell.c - fwalk.c - fwprintf.c - fwrite.c - getc.c - getchar.c - gets.c - getw.c + find.c + fmode.c + lnx_sprintf.c + lnx_vfprintf.c + lnx_vfwprint.c + lnx_vsprintf.c + lnx_vswprintf.c perror.c popen.c - printf.c - putc.c - putchar.c - puts.c - putw.c - putwchar.c - remove.c - rename.c - rewind.c - rmtmp.c - setbuf.c - setvbuf.c - sprintf.c - swprintf.c - stdhnd.c - tempnam.c - tmpfile.c - tmpnam.c - ungetc.c - ungetwc.c - vfprintf.c - vfwprint.c - vprintf.c - vsprintf.c - vswprintf.c - vwprintf.c - wfdopen.c - wfopen.c - wfreopen.c - wfsopen.c + waccess.c + wfind.c wpopen.c - wprintf.c - wremove.c - wrename.c - wtempnam.c - wtmpnam.c _exit.c @@ -440,17 +341,12 @@ strtoull.c strupr.c strxfrm.c - wcstod.c wcstombs.c wctomb.c wsplitp.c + wcs.c - fstat.c - fstati64.c - futime.c - stat.c - wstat.c systime.c @@ -470,13 +366,9 @@ wcscoll.c wcscspn.c - wcsdup.c wcsicmp.c wcslwr.c wcsnicmp.c - wcspbrk.c - wcsrev.c - wcsset.c wcsspn.c wcsstr.c wcstok.c diff --git a/reactos/lib/sdk/crt/include/internal/file.h b/reactos/lib/sdk/crt/include/internal/file.h index 1205a9488c8..9a5c2440f3f 100644 --- a/reactos/lib/sdk/crt/include/internal/file.h +++ b/reactos/lib/sdk/crt/include/internal/file.h @@ -37,22 +37,17 @@ #define WRITE_STREAM(f) ((((f)->_flag & _IOWRT) == _IOWRT)) #define READ_STREAM(f) ((((f)->_flag & _IOREAD) == _IOREAD)) -char __validfp(FILE*); int __set_errno(int err); int __set_doserrno(int error); void* filehnd(int fn); char __is_text_file(FILE*); -int alloc_fd(void* hFile, char mode); int _doprnt(const char* fmt, va_list args, FILE *); int _doscan(FILE* iop, const char* fmt, va_list argp); int __fileno_dup2(int handle1, int handle2); char __fileno_getmode(int _fd); int __fileno_setmode(int _fd, int _newmode); -void free_fd(int _fd); void sigabort_handler(int sig); -char split_oflags(int oflags); -unsigned create_io_inherit_block(STARTUPINFOA* si); void UnixTimeToFileTime(time_t unix_time, FILETIME* filetime, DWORD remainder); time_t FileTimeToUnixTime(const FILETIME* filetime, DWORD *remainder); @@ -106,14 +101,12 @@ typedef struct _FDINFO /* get fdinfo ptr. from an fd */ #define fdinfo(i) (fdinfo_bucket(i) + fdinfo_bucket_entry_idx(i)) -extern FDINFO* __pioinfo[]; - +//extern FDINFO* __pioinfo[]; void _dosmaperr(unsigned long oserrcode); -FILE* __alloc_file(void); @@ -128,8 +121,6 @@ int access_dirW(const wchar_t *_path); -void _fwalk(void (*func)(FILE*)); // not exported - #undef MB_CUR_MAX diff --git a/reactos/lib/sdk/crt/include/internal/printf.h b/reactos/lib/sdk/crt/include/internal/printf.h new file mode 100644 index 00000000000..b38392461db --- /dev/null +++ b/reactos/lib/sdk/crt/include/internal/printf.h @@ -0,0 +1,22 @@ +#ifndef _CRT_PRINTF_H +#define _CRT_PRINTF_H + + +/* Implementation of a printf appropriated from Linux kernel */ + +int lnx_sprintf(char *str, const char *fmt, ...); +int lnx__vsprintf(char *str, const char *fmt, va_list ap); +int lnx__vswprintf(wchar_t *str, const wchar_t *fmt, va_list ap); +int lnx__vsnprintf(char *str, size_t maxlen, const char *fmt, va_list ap); +int lnx__vsnwprintf(wchar_t *str, size_t maxlen, const char *fmt, va_list ap); +int lnx_vfprintf(FILE* f, const char* fmt, va_list ap); +int lnx_vfwprintf(FILE *f, const wchar_t *fmt, va_list ap); +#ifdef _UNICODE +#define lnx_vftprintf lnx_vfwprintf +#define lnx__vstprintf lnx__vswprintf +#else +#define lnx_vftprintf lnx_vfprintf +#define lnx__vstprintf lnx__vsprintf +#endif + +#endif /* _CRT_PRINTF_H */ diff --git a/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h b/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h index f28dff77984..25fa5346b7f 100644 --- a/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h +++ b/reactos/lib/sdk/crt/include/internal/wine/msvcrt.h @@ -129,6 +129,8 @@ extern void msvcrt_free_args(void); extern void msvcrt_init_signals(void); extern void msvcrt_free_signals(void); +extern unsigned create_io_inherit_block(WORD*, BYTE**); + #define MSVCRT__OUT_TO_DEFAULT 0 #define MSVCRT__REPORT_ERRMODE 3 diff --git a/reactos/lib/sdk/crt/io/chmod.c b/reactos/lib/sdk/crt/io/chmod.c deleted file mode 100644 index c6d612be2cb..00000000000 --- a/reactos/lib/sdk/crt/io/chmod.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include -#include -#include - -#define mode_t int - -#define MK_STR(s) #s - -#ifdef _UNICODE - #define sT "S" -#else - #define sT "s" -#endif - -/* - * @implemented - */ -int _tchmod(const _TCHAR* filename, mode_t mode) -{ - DWORD FileAttributes = 0; - BOOLEAN Set = FALSE; - - TRACE(MK_STR(_tchmod)"('%"sT"', %x)\n", filename, mode); - - FileAttributes = GetFileAttributes(filename); - if ( FileAttributes == INVALID_FILE_ATTRIBUTES ) { - _dosmaperr(GetLastError()); - return -1; - } - - if ( mode == 0 ) - return -1; - - if (mode & _S_IWRITE) { - if (FileAttributes & FILE_ATTRIBUTE_READONLY) { - FileAttributes &= ~FILE_ATTRIBUTE_READONLY; - Set = TRUE; - } - } else { - if (!(FileAttributes & FILE_ATTRIBUTE_READONLY)) { - FileAttributes |= FILE_ATTRIBUTE_READONLY; - Set = TRUE; - } - } - if (Set && SetFileAttributes(filename, FileAttributes) == FALSE) { - _dosmaperr(GetLastError()); - return -1; - } - return 0; -} diff --git a/reactos/lib/sdk/crt/io/chsize.c b/reactos/lib/sdk/crt/io/chsize.c deleted file mode 100644 index d2132d5ce4e..00000000000 --- a/reactos/lib/sdk/crt/io/chsize.c +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int _chsize(int _fd, long size) -{ - TRACE("_chsize(fd %d, size %d)\n", _fd, size); - long location = _lseek(_fd, 0, SEEK_CUR); - if (location == -1) return -1; - if (_lseek(_fd, size, 0) == -1) - return -1; - if (!SetEndOfFile((HANDLE)_get_osfhandle(_fd))) - return -1; - _lseek(_fd, location, SEEK_SET); - return 0; -} diff --git a/reactos/lib/sdk/crt/io/close.c b/reactos/lib/sdk/crt/io/close.c deleted file mode 100644 index 9f9af294d86..00000000000 --- a/reactos/lib/sdk/crt/io/close.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - - -/* - * @implemented - */ -int _close(int _fd) -{ - TRACE("_close(%i)", _fd); - - if (_fd == -1) - return(-1); - if (!CloseHandle((HANDLE)_get_osfhandle(_fd))) - { - WARN(":failed-last error (%d)\n",GetLastError()); - _dosmaperr(GetLastError()); - return -1; - } - free_fd(_fd); - return(0); -} diff --git a/reactos/lib/sdk/crt/io/commit.c b/reactos/lib/sdk/crt/io/commit.c deleted file mode 100644 index b939cd98ac3..00000000000 --- a/reactos/lib/sdk/crt/io/commit.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -/* - * @implemented - */ -int _commit(int _fd) -{ - if (! FlushFileBuffers((HANDLE)_get_osfhandle(_fd)) ) { - __set_errno(EBADF); - return -1; - } - - return 0; -} diff --git a/reactos/lib/sdk/crt/io/creat.c b/reactos/lib/sdk/crt/io/creat.c deleted file mode 100644 index 1617da41df9..00000000000 --- a/reactos/lib/sdk/crt/io/creat.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include - - - -/* - * @implemented - */ -int _creat(const char* filename, int mode) -{ - TRACE("_creat('%s', mode %x)\n", filename, mode); - return _open(filename,_O_CREAT|_O_TRUNC,mode); -} diff --git a/reactos/lib/sdk/crt/io/dup.c b/reactos/lib/sdk/crt/io/dup.c deleted file mode 100644 index 7231309ac08..00000000000 --- a/reactos/lib/sdk/crt/io/dup.c +++ /dev/null @@ -1,38 +0,0 @@ -#include - -/* - * @implemented - */ -int _dup(int handle) -{ - HANDLE hFile; - HANDLE hProcess = GetCurrentProcess(); - BOOL result; - int fd; - int mode; - - hFile = (HANDLE)_get_osfhandle(handle); - if (hFile == INVALID_HANDLE_VALUE) { - __set_errno(EBADF); - return -1; - } - mode = __fileno_getmode(handle); - result = DuplicateHandle(hProcess, - hFile, - hProcess, - &hFile, - 0, - mode & FNOINHERIT ? FALSE : TRUE, - DUPLICATE_SAME_ACCESS); - if (result == FALSE) { - _dosmaperr(GetLastError()); - return -1; - } - - fd = alloc_fd(hFile, mode); - if (fd < 0) - { - CloseHandle(hFile); - } - return fd; -} diff --git a/reactos/lib/sdk/crt/io/dup2.c b/reactos/lib/sdk/crt/io/dup2.c deleted file mode 100644 index c77c1131755..00000000000 --- a/reactos/lib/sdk/crt/io/dup2.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -/* - * @implemented - */ -int _dup2(int handle1, int handle2) -{ - return __fileno_dup2(handle1, handle2); -} diff --git a/reactos/lib/sdk/crt/io/eof.c b/reactos/lib/sdk/crt/io/eof.c deleted file mode 100644 index 026e7203479..00000000000 --- a/reactos/lib/sdk/crt/io/eof.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include - -/* - * @implemented - */ -int _eof(int _fd) -{ - __int64 cur_pos = _lseeki64(_fd, 0, SEEK_CUR); - __int64 end_pos = _lseeki64(_fd, 0, SEEK_END); - if ( cur_pos == -1 || end_pos == -1) - return -1; - - if (cur_pos == end_pos) - return 1; - - return 0; -} diff --git a/reactos/lib/sdk/crt/io/filelen.c b/reactos/lib/sdk/crt/io/filelen.c deleted file mode 100644 index 71489ecfc6e..00000000000 --- a/reactos/lib/sdk/crt/io/filelen.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -/* - * @implemented - */ -long _filelength(int _fd) -{ - DWORD len = GetFileSize((HANDLE)_get_osfhandle(_fd), NULL); - if (len == INVALID_FILE_SIZE) { - DWORD oserror = GetLastError(); - if (oserror != 0) { - _dosmaperr(oserror); - return -1L; - } - } - return (long)len; -} diff --git a/reactos/lib/sdk/crt/io/fileleni.c b/reactos/lib/sdk/crt/io/fileleni.c deleted file mode 100644 index cbcbde503a0..00000000000 --- a/reactos/lib/sdk/crt/io/fileleni.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -/* - * @implemented - */ -__int64 _filelengthi64(int _fd) -{ - DWORD lo_length, hi_length; - - lo_length = GetFileSize((HANDLE)_get_osfhandle(_fd), &hi_length); - if (lo_length == INVALID_FILE_SIZE) { - DWORD oserror = GetLastError(); - if (oserror != 0) { - _dosmaperr(oserror); - return (__int64)-1; - } - } - return((((__int64)hi_length) << 32) + lo_length); -} diff --git a/reactos/lib/sdk/crt/io/isatty.c b/reactos/lib/sdk/crt/io/isatty.c deleted file mode 100644 index 894e9536595..00000000000 --- a/reactos/lib/sdk/crt/io/isatty.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - - -/* - * @implemented - */ -int _isatty(int fd) -{ - HANDLE hFile = fdinfo(fd)->hFile; - if (hFile == INVALID_HANDLE_VALUE) - return 0; - return GetFileType(hFile) == FILE_TYPE_CHAR ? 1 : 0; -} diff --git a/reactos/lib/sdk/crt/io/locking.c b/reactos/lib/sdk/crt/io/locking.c deleted file mode 100644 index 3d8d7b5ebad..00000000000 --- a/reactos/lib/sdk/crt/io/locking.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -/* - * @implemented - */ -int _locking(int _fd, int mode, long nbytes) -{ - long offset = _lseek(_fd, 0L, 1); - if (offset == -1L) - return -1; - if (!LockFile((HANDLE)_get_osfhandle(_fd),offset,0,nbytes,0)) { - _dosmaperr(GetLastError()); - return -1; - } - - return 0; -} diff --git a/reactos/lib/sdk/crt/io/lseek.c b/reactos/lib/sdk/crt/io/lseek.c deleted file mode 100644 index 1a5c0e6d820..00000000000 --- a/reactos/lib/sdk/crt/io/lseek.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -/* - * @implemented - */ -long _lseek(int _fildes, long _offset, int _whence) -{ - DWORD newpos = SetFilePointer((HANDLE)fdinfo(_fildes)->hFile, _offset, NULL, _whence); - if (newpos == INVALID_SET_FILE_POINTER) { - DWORD oserror = GetLastError(); - if (oserror != 0) { - _dosmaperr(oserror); - return -1L; - } - } - return newpos; -} diff --git a/reactos/lib/sdk/crt/io/lseeki64.c b/reactos/lib/sdk/crt/io/lseeki64.c deleted file mode 100644 index f5265a731de..00000000000 --- a/reactos/lib/sdk/crt/io/lseeki64.c +++ /dev/null @@ -1,39 +0,0 @@ -#include - -//#define SETFILEPOINTEREX_AVAILABLE - -/* - * @implemented - */ -__int64 _lseeki64(int _fildes, __int64 _offset, int _whence) -{ -#ifdef SETFILEPOINTEREX_AVAILABLE - LARGE_INTEGER new_pos; - LARGE_INTEGER offset; - offset.QuadPart = _offset; - -// if (invalid_filehnd(_fildes)) { -// __set_errno ( EBADF ); -// return -1L; -// } - if (SetFilePointerEx((HANDLE)fdinfo(_fildes)->hFile, offset, &new_pos, _whence)) { - } else { - _dosmaperr(error); - return -1L; - } - return new_pos.QuadPart; -#else - //ULONG lo_pos; - //DWORD hi_pos = 0; // must equal 0 or -1 if supplied, -1 for negative 32 seek value - //lo_pos = SetFilePointer((HANDLE)filehnd(_fildes), _offset, &hi_pos, _whence); - //return((((__int64)hi_pos) << 32) + lo_pos); - - LARGE_INTEGER offset; - offset.QuadPart = _offset; - - offset.u.LowPart = SetFilePointer((HANDLE)fdinfo(_fildes)->hFile, - offset.u.LowPart, &offset.u.HighPart, _whence); - return ((((__int64)offset.u.HighPart) << 32) + offset.u.LowPart); - -#endif /*SETFILEPOINTEREX_AVAILABLE*/ -} diff --git a/reactos/lib/sdk/crt/io/mktemp.c b/reactos/lib/sdk/crt/io/mktemp.c deleted file mode 100644 index e3e6ec273ec..00000000000 --- a/reactos/lib/sdk/crt/io/mktemp.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/mktemp.c - * PURPOSE: Makes a temp file based on a template - * PROGRAMER: DJ Delorie - Ariadne - * UPDATE HISTORY: - * 28/12/98: Appropriated for the Reactos Kernel - */ - -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ - -#include - -/* - * @implemented - */ -char* _mktemp(char* _template) -{ - static int count = 0; - char *cp, *dp; - int i, len, xcount, loopcnt; - - TRACE("_mktemp('%s')\n", _template); - len = strlen (_template); - cp = _template + len; - - xcount = 0; - while (xcount < 6 && cp > _template && cp[-1] == 'X') - xcount++, cp--; - - if (xcount) { - dp = cp; - while (dp > _template && dp[-1] != '/' && dp[-1] != '\\' && dp[-1] != ':') - dp--; - - /* Keep the first characters of the template, but turn the rest into - Xs. */ - while (cp > dp + 8 - xcount) { - *--cp = 'X'; - xcount = (xcount >= 6) ? 6 : 1 + xcount; - } - - /* If dots occur too early -- squash them. */ - while (dp < cp) { - if (*dp == '.') *dp = 'a'; - dp++; - } - - /* Try to add ".tmp" to the filename. Truncate unused Xs. */ - if (cp + xcount + 3 < _template + len) - strcpy (cp + xcount, ".tmp"); - else - cp[xcount] = 0; - - /* This loop can run up to 2<<(5*6) times, or about 10^9 times. */ - for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) { - int c = count++; - for (i = 0; i < xcount; i++, c >>= 5) - cp[i] = "abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f]; - if (_access(_template,0) == -1) - return _template; - } - } - - /* Failure: truncate the template and return NULL. */ - *_template = 0; - return 0; -} diff --git a/reactos/lib/sdk/crt/io/open.c b/reactos/lib/sdk/crt/io/open.c deleted file mode 100644 index fb4b50813b5..00000000000 --- a/reactos/lib/sdk/crt/io/open.c +++ /dev/null @@ -1,597 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/open.c - * PURPOSE: Opens a file and translates handles to fileno - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ -/* - * Some stuff taken from active perl: perl\win32.c (ioinfo stuff) - * - * (c) 1995 Microsoft Corporation. All rights reserved. - * Developed by hip communications inc., http://info.hip.com/info/ - * Portions (c) 1993 Intergraph Corporation. All rights reserved. - * - * You may distribute under the terms of either the GNU General Public - * License or the Artistic License, as specified in the README file. - */ -/* - * Some functions taken from/based on wine\dlls\msvcrt\file.c: - * split_oflags - * _open_osfhandle - * many more... - * - * Copyright 1996,1998 Marcus Meissner - * Copyright 1996 Jukka Iivonen - * Copyright 1997,2000 Uwe Bonnes - * Copyright 2000 Jon Griffiths - * Copyright 2004 Eric Pouech - * Copyright 2004 Juan Lang - */ - -// rember to interlock the allocation of fileno when making this thread safe - -// possibly store extra information at the handle - -#include - -#if !defined(NDEBUG) && defined(DBG) -#include -#endif - -#include -#include -#include - - -FDINFO first_bucket[FDINFO_ENTRIES_PER_BUCKET]; -FDINFO* __pioinfo[FDINFO_BUCKETS] = {first_bucket}; - - -/* This critical section protects the tables MSVCRT_fdesc and MSVCRT_fstreams, - * and their related indexes, MSVCRT_fdstart, MSVCRT_fdend, - * and MSVCRT_stream_idx, from race conditions. - * It doesn't protect against race conditions manipulating the underlying files - * or flags; doing so would probably be better accomplished with per-file - * protection, rather than locking the whole table for every change. - */ -static CRITICAL_SECTION g_file_cs; -#define LOCK_FILES() do { EnterCriticalSection(&g_file_cs); } while (0) -#define UNLOCK_FILES() do { LeaveCriticalSection(&g_file_cs); } while (0) - -///////////////////////////////////////// - -static int g_fdstart = 3; /* first unallocated fd */ -static int g_fdend = 3; /* highest allocated fd */ - -/* - * INTERNAL - */ - /* -static __inline FD_INFO* fdinfo(int fd) -{ - FD_INFO* bucket = __pioinfo[fd >> FDINFO_ENTRIES_PER_BUCKET_SHIFT]; - if (!bucket){ - bucket = alloc_init_bucket(fd); - } - return bucket + (fd & (FDINFO_ENTRIES_PER_BUCKET - 1)); -} -*/ - - -/* - * INTERNAL - */ -__inline BOOL is_valid_fd(int fd) -{ - BOOL b = (fd >= 0 && fd < g_fdend && (fdinfo(fd)->fdflags & FOPEN)); - - if (!b){ - if (fd >= 0 && fd < g_fdend) - { - ERR("not valid fd %i, g_fdend %i, fdinfo %x, bucket %x, fdflags %x\n", - fd,g_fdend,fdinfo(fd),fdinfo_bucket(fd),fdinfo(fd)->fdflags); - } - else - { - ERR("not valid fd %i, g_fdend %i\n",fd,g_fdend); - } - - } - - return b; -} - -/* - * INTERNAL - */ -char split_oflags(int oflags) -{ - char fdflags = 0; - - if (oflags & _O_APPEND) fdflags |= FAPPEND; - - if (oflags & _O_BINARY) ; - else if (oflags & _O_TEXT) fdflags |= FTEXT; - else if (_fmode& _O_BINARY) ; - else fdflags |= FTEXT; /* default to TEXT*/ - - if (oflags & _O_NOINHERIT) fdflags |= FNOINHERIT; - - if (oflags & ~(_O_BINARY|_O_TEXT|_O_APPEND|_O_TRUNC| - _O_EXCL|_O_CREAT|_O_RDWR|_O_WRONLY| - _O_TEMPORARY|_O_NOINHERIT)) - ERR(":unsupported oflags 0x%04x\n",oflags); - - return fdflags; -} - - - -/* - * INTERNAL - */ -char __is_text_file(FILE* p) -{ - if ( p == NULL || fdinfo_bucket((p)->_file) == NULL ) - return FALSE; - return (!((p)->_flag&_IOSTRG) && (fdinfo((p)->_file)->fdflags & FTEXT)); -} - - -/********************************************************************* - * _open (MSVCRT.@) - */ -int CDECL _open( const char *path, int flags, ... ) -{ - va_list ap; - - if (flags & O_CREAT) - { - int pmode; - va_start(ap, flags); - pmode = va_arg(ap, int); - va_end(ap); - return _sopen( path, flags, SH_DENYNO, pmode ); - } - else - return _sopen( path, flags, SH_DENYNO); -} - - - - -/* - * INTERNAL - */ -static void init_bucket(FDINFO* entry) -{ - int i; - - for(i=0; - i < FDINFO_ENTRIES_PER_BUCKET; - i++, entry++) - { - entry->hFile = INVALID_HANDLE_VALUE; - entry->fdflags = 0; - entry->pipechar = LF; - entry->lockinitflag = 0; - } -} - -/* - * INTERNAL - */ -static BOOL alloc_init_bucket(int fd) -{ - fdinfo_bucket(fd) = malloc(FDINFO_ENTRIES_PER_BUCKET * sizeof(FDINFO)); - if (!fdinfo_bucket(fd)) return FALSE; - - init_bucket(fdinfo_bucket(fd)); - - return TRUE; -} - - - - -/* - * INTERNAL - * Allocate an fd slot from a Win32 HANDLE, starting from fd - * caller must hold the files lock - */ -static int alloc_fd_from(HANDLE hand, char flag, int fd) -{ - - if (fd >= FDINFO_ENTRIES) - { - ERR("files exhausted!\n"); - return -1; - } - - if (!fdinfo_bucket(fd)) - { - if (!alloc_init_bucket(fd)){ - //errno = ENOMEM - return -1; - } - } - - fdinfo(fd)->hFile = hand; - fdinfo(fd)->fdflags = FOPEN | (flag & (FNOINHERIT | FAPPEND | FTEXT)); - fdinfo(fd)->pipechar = LF; - fdinfo(fd)->lockinitflag = 0; - //fdinfo(fd)->lock - - /* locate next free slot */ - if (fd == g_fdstart && fd == g_fdend) - { - g_fdstart = g_fdend + 1; - } - else - { -#if 0 /* alternate (untested) impl. maybe a tiny bit faster? -Gunnar */ - int i, bidx; - - for (bidx = fdinfo_bucket_idx(g_fdstart); bidx < FDINFO_BUCKETS && __pioinfo[bidx]; bidx++) - { - for (i = fdinfo_bucket_entry_idx(g_fdstart); - g_fdstart < g_fdend && fdinfo(g_fdstart)->fdflags & FOPEN && i < FDINFO_BUCKET_ENTRIES; - i++) - { - g_fdstart++; - } - } -#else - - while (g_fdstart < g_fdend && - fdinfo_bucket(g_fdstart) && - (fdinfo(g_fdstart)->fdflags & FOPEN)) - { - g_fdstart++; - } -#endif - } - - /* update last fd in use */ - if (fd >= g_fdend) - g_fdend = fd + 1; - - /* alloc more fdinfo buckets by demand. - * FIXME: should we dealloc buckets when they become unused also? */ - if (!fdinfo_bucket(g_fdstart) && g_fdstart < FDINFO_ENTRIES) - { - alloc_init_bucket(g_fdstart); - } - - TRACE("fdstart is %d, fdend is %d\n", g_fdstart, g_fdend); - - switch (fd) - { - case 0: SetStdHandle(STD_INPUT_HANDLE, hand); break; - case 1: SetStdHandle(STD_OUTPUT_HANDLE, hand); break; - case 2: SetStdHandle(STD_ERROR_HANDLE, hand); break; - } - - return fd; -} - - -/* - * INTERNAL: Allocate an fd slot from a Win32 HANDLE - */ -int alloc_fd(HANDLE hand, char flag) -{ - int ret; - - LOCK_FILES(); - -// TRACE(":handle (%p) allocating fd (%d)\n",hand,MSVCRT_fdstart); - ret = alloc_fd_from(hand, flag, g_fdstart); - - UNLOCK_FILES(); - return ret; -} - - - -/* - * INTERNAL - */ -char __fileno_getmode(int fd) -{ - if (!is_valid_fd(fd)) { - __set_errno(EBADF); - return -1; - } - return fdinfo(fd)->fdflags; - -} - -/* - * INTERNAL - */ -void free_fd(int fd) -{ - LOCK_FILES(); - - - fdinfo(fd)->hFile = INVALID_HANDLE_VALUE; - fdinfo(fd)->fdflags = 0; - - if (fd < 3) /* don't use 0,1,2 for user files */ - { - switch (fd) - { - case 0: SetStdHandle(STD_INPUT_HANDLE, NULL); break; - case 1: SetStdHandle(STD_OUTPUT_HANDLE, NULL); break; - case 2: SetStdHandle(STD_ERROR_HANDLE, NULL); break; - } - } - else - { - if (fd == g_fdend - 1) - g_fdend--; - - if (fd < g_fdstart) - g_fdstart = fd; - } - - - UNLOCK_FILES(); -} - -/* - * @implemented - */ -int _open_osfhandle(long osfhandle, int oflags) -{ - /* - PREV: - The _open_osfhandle() function in MSVCRT is expected to take the absence - of either _O_TEXT or _O_BINARY to mean _O_BINARY. Currently it defaults to - _O_TEXT. - - An example of this is MFC's CStdioFile::Open in binary mode - it passes flags - of 0 when it wants to write a binary file - under WINE we do text mode conversions! - - The attached patch ensures that _O_BINARY is set if neither is set in the passed-in -flags. - - - * file, so set the write flag. It also only sets _O_TEXT if it wants - * text - it never sets _O_BINARY. - */ - /* FIXME: handle more flags */ -/* - flags |= MSVCRT__IOREAD|MSVCRT__IOWRT; - if ( !( flags & _O_TEXT ) ) flags |= _O_BINARY; - - fd = msvcrt_alloc_fd((HANDLE)hand,flags); - TRACE(":handle (%ld) fd (%d) flags 0x%08x\n",hand,fd, flags); -*/ - /* MSVCRT__O_RDONLY (0) always matches, so set the read flag - * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the - * file, so set the write flag. It also only sets MSVCRT__O_TEXT if it wants - * text - it never sets MSVCRT__O_BINARY. - */ - /* FIXME: handle more flags */ - /* - LAG TEST SOM TESTER UT ALT DETTE flag tingern - */ - if (!(oflags & (_O_BINARY | _O_TEXT)) && (_fmode & _O_BINARY)) - oflags |= _O_BINARY; - else - oflags |= _O_TEXT; - - return alloc_fd((HANDLE)osfhandle, split_oflags(oflags)); -} - -/* - * @implemented - */ -long _get_osfhandle(int fd) -{ - TRACE("_get_osfhandle(%i)",fd); - - if (!is_valid_fd(fd)) { - return( -1 ); - } - return( (long)fdinfo(fd)->hFile ); -} - - - -/* - * INTERNAL - */ -int __fileno_dup2(int handle1, int handle2) -{ - HANDLE hProcess; - BOOL result; - - if (handle1 >= FDINFO_ENTRIES || handle1 < 0 || handle2 >= FDINFO_ENTRIES || handle2 < 0) { - __set_errno(EBADF); - return -1; - } -// if (_pioinfo[handle1]->fd == -1) { - if (fdinfo(handle1)->hFile == INVALID_HANDLE_VALUE) { - __set_errno(EBADF); - return -1; - } - if (handle1 == handle2) - return handle1; -// if (_pioinfo[handle2]->fd != -1) { - if (fdinfo(handle2)->hFile != INVALID_HANDLE_VALUE) { - _close(handle2); - } - hProcess = GetCurrentProcess(); - result = DuplicateHandle(hProcess, - fdinfo(handle1)->hFile, - hProcess, - &fdinfo(handle2)->hFile, - 0, - fdinfo(handle1)->fdflags & FNOINHERIT ? FALSE : TRUE, - DUPLICATE_SAME_ACCESS); - if (result) { -// _pioinfo[handle2]->fd = handle2; - fdinfo(handle2)->fdflags = fdinfo(handle1)->fdflags; - switch (handle2) { - case 0: - SetStdHandle(STD_INPUT_HANDLE, fdinfo(handle2)->hFile); - break; - case 1: - SetStdHandle(STD_OUTPUT_HANDLE, fdinfo(handle2)->hFile); - break; - case 2: - SetStdHandle(STD_ERROR_HANDLE, fdinfo(handle2)->hFile); - break; - } - - return handle1; - } else { - __set_errno(EMFILE); // Is this the correct error no.? - return -1; - } -} - - -void* malloc(size_t sizeObject); - - - -/* - * INTERNAL - */ -BOOL __fileno_init(void) -{ - STARTUPINFOA si; - int i; - - init_bucket(first_bucket); - - GetStartupInfoA(&si); - - if (si.cbReserved2 != 0 && si.lpReserved2 != NULL) - { - char* fdflags_ptr; - HANDLE* handle_ptr; - - g_fdend = *(unsigned*)si.lpReserved2; - - fdflags_ptr= (char*)(si.lpReserved2 + sizeof(unsigned)); - handle_ptr = (HANDLE*)(fdflags_ptr + g_fdend * sizeof(char)); - - g_fdend = min(g_fdend, FDINFO_ENTRIES); - for (i = 0; i < g_fdend; i++) - { - if (!fdinfo_bucket(i)) - { - if (!alloc_init_bucket(i)){ - /* FIXME: free other buckets? */ - return FALSE; - } - } - - if ((*fdflags_ptr & FOPEN) && *handle_ptr != INVALID_HANDLE_VALUE) - { - fdinfo(i)->fdflags = *fdflags_ptr; - fdinfo(i)->hFile = *handle_ptr; - } -/* - else - { - fdinfo(i)->fdflags = 0; - fdinfo(i)->hFile = INVALID_HANDLE_VALUE; - } -*/ - fdflags_ptr++; handle_ptr++; - } - for (g_fdstart = 3; g_fdstart < g_fdend; g_fdstart++) - if (fdinfo(g_fdstart)->hFile == INVALID_HANDLE_VALUE) break; - } - - InitializeCriticalSection(&g_file_cs); - - - if (fdinfo(0)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(0)->fdflags & FOPEN)) { - fdinfo(0)->hFile = GetStdHandle(STD_INPUT_HANDLE); - if (fdinfo(0)->hFile == NULL) - fdinfo(0)->hFile = INVALID_HANDLE_VALUE; - fdinfo(0)->fdflags = FOPEN|FTEXT; - } - if (fdinfo(1)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(1)->fdflags & FOPEN)) { - fdinfo(1)->hFile = GetStdHandle(STD_OUTPUT_HANDLE); - if (fdinfo(1)->hFile == NULL) - fdinfo(1)->hFile = INVALID_HANDLE_VALUE; - fdinfo(1)->fdflags = FOPEN|FTEXT; - } - if (fdinfo(2)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(2)->fdflags & FOPEN)) { - fdinfo(2)->hFile = GetStdHandle(STD_ERROR_HANDLE); - if (fdinfo(2)->hFile == NULL) - fdinfo(2)->hFile = INVALID_HANDLE_VALUE; - fdinfo(2)->fdflags = FOPEN|FTEXT; - } - - - - - for (i = 0; i < 3; i++) - { - /* FILE structs for stdin/out/err are static and never deleted */ -// MSVCRT_fstreams[i] = &MSVCRT__iob[i]; - } -// MSVCRT_stream_idx = 3; - - return TRUE; -} - - - -/* INTERNAL: Create an inheritance data block (for spawned process) - * The inheritance block is made of: - * 00 int nb of file descriptor (NBFD) - * 04 char file flags (wxflag): repeated for each fd - * 4+NBFD HANDLE file handle: repeated for each fd - */ -unsigned create_io_inherit_block(STARTUPINFOA* si) -{ - int fd; - char* fdflags_ptr; - HANDLE* handle_ptr; - - TRACE("create_io_inherit_block(%x)",si); - - si->cbReserved2 = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * g_fdend; - si->lpReserved2 = calloc(si->cbReserved2, 1); - if (!si->lpReserved2) - { - si->cbReserved2 = 0; - return( FALSE ); - } - fdflags_ptr = (char*)si->lpReserved2 + sizeof(unsigned); - handle_ptr = (HANDLE*)(fdflags_ptr + g_fdend * sizeof(char)); - - *(unsigned*)si->lpReserved2 = g_fdend; - for (fd = 0; fd < g_fdend; fd++) - { - /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */ - if ((fdinfo(fd)->fdflags & (FOPEN | FNOINHERIT)) == FOPEN) - { - *fdflags_ptr = fdinfo(fd)->fdflags; - *handle_ptr = fdinfo(fd)->hFile; - } - else - { - *fdflags_ptr = 0; - *handle_ptr = INVALID_HANDLE_VALUE; - } - fdflags_ptr++; handle_ptr++; - } - return( TRUE ); -} - - diff --git a/reactos/lib/sdk/crt/io/pipe.c b/reactos/lib/sdk/crt/io/pipe.c deleted file mode 100644 index 828b74a81f4..00000000000 --- a/reactos/lib/sdk/crt/io/pipe.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/pipe.c - * PURPOSE: Creates a pipe - * PROGRAMER: DJ Delorie - * UPDATE HISTORY: - * 28/12/98: Appropriated for Reactos - */ - -#include - -/* - * @implemented - */ -int _pipe(int _fildes[2], unsigned int size, int mode ) -{ - HANDLE hReadPipe, hWritePipe; - SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; - - TRACE("_pipe((%i,%i), %ui, %i)", _fildes[0], _fildes[1], size, mode); - - if (mode & O_NOINHERIT) - sa.bInheritHandle = FALSE; - - if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size)) { - _dosmaperr(GetLastError()); - return( -1); - } - - if ((_fildes[0] = alloc_fd(hReadPipe, split_oflags(mode))) < 0) - { - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - __set_errno(EMFILE); - return(-1); - } - - if ((_fildes[1] = alloc_fd(hWritePipe, split_oflags(mode))) < 0) - { - free_fd(_fildes[0]); - CloseHandle(hReadPipe); - CloseHandle(hWritePipe); - __set_errno(EMFILE); - return(-1); - } - return(0); -} diff --git a/reactos/lib/sdk/crt/io/read.c b/reactos/lib/sdk/crt/io/read.c deleted file mode 100644 index c9b13d6f487..00000000000 --- a/reactos/lib/sdk/crt/io/read.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/read.c - * PURPOSE: Reads a file - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/1998: Created - * 03/05/2002: made _read() non-greedy - it now returns as soon as - * any amount of data has been read. It's the expected - * behavior for line-buffered streams (KJK::Hyperion) - */ - -#include - -/* - * @implemented - */ -int _read(int _fd, void *_buf, unsigned int _nbyte) -{ - DWORD _rbyte = 0, nbyte = _nbyte; - char *bufp = (char*)_buf; - HANDLE hfile; - int istext, error; - - TRACE("_read(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte); - - /* null read */ - if(_nbyte == 0) - return 0; - - hfile = (HANDLE)_get_osfhandle(_fd); - istext = __fileno_getmode(_fd) & O_TEXT; - - /* read data */ - if (!ReadFile(hfile, bufp, nbyte, &_rbyte, NULL)) - { - /* failure */ - error = GetLastError(); - if (error == ERROR_BROKEN_PIPE) - { - return 0; - } - _dosmaperr(error); - return -1; - } - - /* text mode */ - if (_rbyte && istext) - { - int found_cr = 0; - int cr = 0; - DWORD count = _rbyte; - - /* repeat for all bytes in the buffer */ - for(; count; bufp++, count--) - { -#if 1 - /* carriage return */ - if (*bufp == '\r') { - found_cr = 1; - if (cr != 0) { - *(bufp - cr) = *bufp; - } - continue; - } - if (found_cr) { - found_cr = 0; - if (*bufp == '\n') { - cr++; - *(bufp - cr) = *bufp; - } else { - } - } else if (cr != 0) { - *(bufp - cr) = *bufp; - } -#else - /* carriage return */ - if (*bufp == '\r') { - cr++; - } - /* shift characters back, to ignore carriage returns */ - else if (cr != 0) { - *(bufp - cr) = *bufp; - } -#endif - } - if (found_cr) { - cr++; - } - /* ignore the carriage returns */ - _rbyte -= cr; - } - TRACE("%d\n", _rbyte); - return _rbyte; -} diff --git a/reactos/lib/sdk/crt/io/setmode.c b/reactos/lib/sdk/crt/io/setmode.c deleted file mode 100644 index 06f19151a11..00000000000 --- a/reactos/lib/sdk/crt/io/setmode.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/setmode.c - * PURPOSE: Sets the file translation mode - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ -#include - -__inline BOOL is_valid_fd(int fd); - -/* - * @implemented - */ -int _setmode(int fd, int newmode) -{ - int prevmode; - - TRACE("_setmode(%d, %d)", fd, newmode); - - if (!is_valid_fd(fd)) - { - ERR("_setmode: inval fd (%d)\n",fd); - //errno = EBADF; - return(-1); - } - - if (newmode & ~(_O_TEXT|_O_BINARY)) - { - ERR("_setmode: fd (%d) mode (0x%08x) unknown\n",fd,newmode); - /* FIXME: Should we fail with EINVAL here? */ - } - - prevmode = fdinfo(fd)->fdflags & FTEXT ? _O_TEXT : _O_BINARY; - - if ((newmode & _O_TEXT) == _O_TEXT) - { - fdinfo(fd)->fdflags |= FTEXT; - } - else - { - /* FIXME: If both _O_TEXT and _O_BINARY are set, we get here. - * Should we fail with EINVAL instead? -Gunnar - */ - fdinfo(fd)->fdflags &= ~FTEXT; - } - - return(prevmode); -} - - diff --git a/reactos/lib/sdk/crt/io/sopen.c b/reactos/lib/sdk/crt/io/sopen.c deleted file mode 100644 index 26593b061bc..00000000000 --- a/reactos/lib/sdk/crt/io/sopen.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include - -/* - * @implemented - */ -/********************************************************************* - * _sopen (MSVCRT.@) - */ -int CDECL _sopen( const char *path, int oflags, int shflags, ... ) -{ - va_list ap; - int pmode; - DWORD access = 0, creation = 0, attrib; - DWORD sharing; - int wxflag = 0, fd; - HANDLE hand; - SECURITY_ATTRIBUTES sa; - - - TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n", - path, oflags, shflags); - - wxflag = split_oflags(oflags); - switch (oflags & (O_RDONLY | O_WRONLY | O_RDWR)) - { - case O_RDONLY: access |= GENERIC_READ; break; - case O_WRONLY: access |= GENERIC_WRITE; break; - case O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break; - } - - if (oflags & O_CREAT) - { - va_start(ap, shflags); - pmode = va_arg(ap, int); - va_end(ap); - - if(pmode & ~(S_IREAD | S_IWRITE)) - FIXME(": pmode 0x%04x ignored\n", pmode); - else - WARN(": pmode 0x%04x ignored\n", pmode); - - if (oflags & O_EXCL) - creation = CREATE_NEW; - else if (oflags & O_TRUNC) - creation = CREATE_ALWAYS; - else - creation = OPEN_ALWAYS; - } - else /* no O_CREAT */ - { - if (oflags & O_TRUNC) - creation = TRUNCATE_EXISTING; - else - creation = OPEN_EXISTING; - } - - switch( shflags ) - { - case SH_DENYRW: - sharing = 0L; - break; - case SH_DENYWR: - sharing = FILE_SHARE_READ; - break; - case SH_DENYRD: - sharing = FILE_SHARE_WRITE; - break; - case SH_DENYNO: - sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; - break; - default: - ERR( "Unhandled shflags 0x%x\n", shflags ); - return -1; - } - attrib = FILE_ATTRIBUTE_NORMAL; - - if (oflags & O_TEMPORARY) - { - attrib |= FILE_FLAG_DELETE_ON_CLOSE; - access |= DELETE; - sharing |= FILE_SHARE_DELETE; - } - - sa.nLength = sizeof( SECURITY_ATTRIBUTES ); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = (oflags & O_NOINHERIT) ? FALSE : TRUE; - - hand = CreateFileA(path, access, sharing, &sa, creation, attrib, 0); - - if (hand == INVALID_HANDLE_VALUE) { - WARN(":failed-last error (%d)\n",GetLastError()); - _dosmaperr(GetLastError()); - return -1; - } - - fd = alloc_fd(hand, wxflag); - - TRACE(":fd (%d) handle (%p)\n",fd, hand); - return fd; -} - diff --git a/reactos/lib/sdk/crt/io/stubs.c b/reactos/lib/sdk/crt/io/stubs.c deleted file mode 100644 index aadc2411f4c..00000000000 --- a/reactos/lib/sdk/crt/io/stubs.c +++ /dev/null @@ -1 +0,0 @@ -void *__badioinfo; diff --git a/reactos/lib/sdk/crt/io/tell.c b/reactos/lib/sdk/crt/io/tell.c deleted file mode 100644 index 150e8933c9d..00000000000 --- a/reactos/lib/sdk/crt/io/tell.c +++ /dev/null @@ -1,10 +0,0 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -off_t _tell(int _file) -{ - return _lseek(_file, 0, SEEK_CUR); -} diff --git a/reactos/lib/sdk/crt/io/telli64.c b/reactos/lib/sdk/crt/io/telli64.c deleted file mode 100644 index 8cae825168e..00000000000 --- a/reactos/lib/sdk/crt/io/telli64.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include - -/* - * @implemented - */ -__int64 _telli64(int _file) -{ - return _lseeki64(_file, 0, SEEK_CUR); -} diff --git a/reactos/lib/sdk/crt/io/umask.c b/reactos/lib/sdk/crt/io/umask.c deleted file mode 100644 index 28a498ff1eb..00000000000 --- a/reactos/lib/sdk/crt/io/umask.c +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -unsigned _unMode_dll = 022; - -/* - * @implemented - */ -unsigned _umask (unsigned unMode) -{ - unsigned old_mask = _unMode_dll; - _unMode_dll = unMode; - return old_mask; -} diff --git a/reactos/lib/sdk/crt/io/unlink.c b/reactos/lib/sdk/crt/io/unlink.c deleted file mode 100644 index 784316990b5..00000000000 --- a/reactos/lib/sdk/crt/io/unlink.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/unlink.c - * PURPOSE: Deletes a file - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ - -#include - -/* - * @implemented - */ -int _unlink(const char* filename) -{ - TRACE("_unlink('%s')\n", filename); - if (!DeleteFileA(filename)) { - _dosmaperr(GetLastError()); - return -1; - } - return 0; -} diff --git a/reactos/lib/sdk/crt/io/utime.c b/reactos/lib/sdk/crt/io/utime.c deleted file mode 100644 index 214c55f44ac..00000000000 --- a/reactos/lib/sdk/crt/io/utime.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include -#include - -/* - * @implemented - */ -int _utime(const char* filename, struct _utimbuf* buf) -{ - int fn; - int ret; - - fn = _open(filename, _O_RDWR); - if (fn == -1) { - __set_errno(EBADF); - return -1; - } - ret = _futime(fn, buf); - if (_close(fn) < 0) - return -1; - return ret; -} diff --git a/reactos/lib/sdk/crt/io/wcreat.c b/reactos/lib/sdk/crt/io/wcreat.c deleted file mode 100644 index d7c695f2c51..00000000000 --- a/reactos/lib/sdk/crt/io/wcreat.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include - - - -/* - * @implemented - */ -int _wcreat(const wchar_t* filename, int mode) -{ - TRACE("_wcreat('%S', mode %x)\n", filename, mode); - return _wopen(filename,_O_CREAT|_O_TRUNC,mode); -} diff --git a/reactos/lib/sdk/crt/io/wmktemp.c b/reactos/lib/sdk/crt/io/wmktemp.c deleted file mode 100644 index 356857d9ff7..00000000000 --- a/reactos/lib/sdk/crt/io/wmktemp.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/mktemp.c - * PURPOSE: Makes a temp file based on a template - * PROGRAMER: DJ Delorie - Ariadne - * UPDATE HISTORY: - * 28/12/98: Appropriated for the Reactos Kernel - */ - -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ - -#include - - -/* - * @implemented - */ -wchar_t* _wmktemp (wchar_t *_template) -{ - static int count = 0; - wchar_t *cp, *dp; - int i, len, xcount, loopcnt; - - TRACE("_wmktemp('%S')\n", _template); - len = wcslen (_template); - cp = _template + len; - - xcount = 0; - while (xcount < 6 && cp > _template && cp[-1] == L'X') - xcount++, cp--; - - if (xcount) { - dp = cp; - while (dp > _template && dp[-1] != L'/' && dp[-1] != L'\\' && dp[-1] != L':') - dp--; - - /* Keep the first characters of the template, but turn the rest into - Xs. */ - while (cp > dp + 8 - xcount) { - *--cp = L'X'; - xcount = (xcount >= 6) ? 6 : 1 + xcount; - } - - /* If dots occur too early -- squash them. */ - while (dp < cp) { - if (*dp == L'.') *dp = L'a'; - dp++; - } - - /* Try to add ".tmp" to the filename. Truncate unused Xs. */ - if (cp + xcount + 3 < _template + len) - wcscpy (cp + xcount, L".tmp"); - else - cp[xcount] = 0; - - /* This loop can run up to 2<<(5*6) times, or about 10^9 times. */ - for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) { - int c = count++; - for (i = 0; i < xcount; i++, c >>= 5) - cp[i] = L"abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f]; - if (_waccess(_template,0) == -1) - return _template; - } - } - - /* Failure: truncate the template and return NULL. */ - *_template = 0; - return 0; -} diff --git a/reactos/lib/sdk/crt/io/wopen.c b/reactos/lib/sdk/crt/io/wopen.c deleted file mode 100644 index 60b380e241c..00000000000 --- a/reactos/lib/sdk/crt/io/wopen.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/open.c - * PURPOSE: Opens a file and translates handles to fileno - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ - -// rember to interlock the allocation of fileno when making this thread safe -// possibly store extra information at the handle - -#include -#if !defined(NDEBUG) && defined(DBG) -#include -#endif -#include -#include - - -/********************************************************************* - * _wopen (MSVCRT.@) - */ -int CDECL _wopen(const wchar_t *path,int flags,...) -{ - const unsigned int len = strlenW(path); - char *patha = calloc(len + 1,1); - va_list ap; - int pmode; - - va_start(ap, flags); - pmode = va_arg(ap, int); - va_end(ap); - - if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL)) - { - int retval = _open(patha,flags,pmode); - free(patha); - return retval; - } - - _dosmaperr(GetLastError()); - return -1; -} - -/********************************************************************* - * _wsopen (MSVCRT.@) - */ -int CDECL _wsopen( const wchar_t* path, int oflags, int shflags, ... ) -{ - const unsigned int len = strlenW(path); - char *patha = calloc(len + 1,1); - va_list ap; - int pmode; - - va_start(ap, shflags); - pmode = va_arg(ap, int); - va_end(ap); - - if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL)) - { - int retval = sopen(patha,oflags,shflags,pmode); - free(patha); - return retval; - } - - _dosmaperr(GetLastError()); - return -1; -} diff --git a/reactos/lib/sdk/crt/io/write.c b/reactos/lib/sdk/crt/io/write.c deleted file mode 100644 index 2b99cdd1a8c..00000000000 --- a/reactos/lib/sdk/crt/io/write.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/write.c - * PURPOSE: Writes to a file - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ - -#include - - -#define BUFSIZE 4096 -/* -void ReportLastError(void) -{ - DWORD error = GetLastError(); - if (error != ERROR_SUCCESS) { - PTSTR msg; - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, - 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) { - printf("ReportLastError() %d - %s\n", error, msg); - } else { - printf("ReportLastError() %d - unknown error\n", error); - } - LocalFree(msg); - } -} - */ -/* - * @implemented - */ -int _write(int _fd, const void* _buf, unsigned int _nbyte) -{ - char *tmp, *in, *out; - int result; - unsigned int count; - DWORD wbyte; - - TRACE("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte); - if (__fileno_getmode(_fd) & O_TEXT) { - result = _nbyte; - tmp = (char*) malloc(BUFSIZE); - if (tmp == NULL) { - __set_errno(ENOMEM); - return -1; - } - count = BUFSIZE; - out = tmp; - in = (char*) _buf; - while (_nbyte--) { - if (*in == 0x0a) { - *out++ = 0x0d; - count--; - if (count == 0) { - if (!WriteFile((HANDLE)_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) { - //ReportLastError(); - _dosmaperr(GetLastError()); - result = -1; - break; - } - if (wbyte < BUFSIZE) { - result = in - (char*)_buf; - break; - } - count = BUFSIZE; - out = tmp; - } - } - *out++ = *in++; - count--; - if (count == 0 || _nbyte == 0) { - if (!WriteFile((HANDLE)_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) { - _dosmaperr(GetLastError()); - result = -1; - break; - } - if (wbyte < (BUFSIZE - count)) { - result = in - (char*)_buf; - break; - } - count = BUFSIZE; - out = tmp; - } - } - free(tmp); - return result; - } else { - if(!WriteFile((HANDLE)_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) { - _dosmaperr(GetLastError()); - return -1; - } - return wbyte; - } -} diff --git a/reactos/lib/sdk/crt/io/wunlink.c b/reactos/lib/sdk/crt/io/wunlink.c deleted file mode 100644 index 2fb93ab3f02..00000000000 --- a/reactos/lib/sdk/crt/io/wunlink.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/io/unlink.c - * PURPOSE: Deletes a file - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ - -#include - -/* - * @implemented - */ -int _wunlink(const wchar_t* filename) -{ - TRACE("_wunlink('%S')\n", filename); - if (!DeleteFileW(filename)) { - _dosmaperr(GetLastError()); - return -1; - } - return 0; -} diff --git a/reactos/lib/sdk/crt/io/wutime.c b/reactos/lib/sdk/crt/io/wutime.c deleted file mode 100644 index 8de7492d32b..00000000000 --- a/reactos/lib/sdk/crt/io/wutime.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include -#include - -/* - * @implemented - */ -int _wutime(const wchar_t* filename, struct _utimbuf* buf) -{ - int fn; - int ret; - - fn = _wopen(filename, _O_RDWR); - if (fn == -1) { - __set_errno(EBADF); - return -1; - } - ret = _futime(fn, buf); - if (_close(fn) < 0) - return -1; - return ret; -} - diff --git a/reactos/lib/sdk/crt/libcntpr.rbuild b/reactos/lib/sdk/crt/libcntpr.rbuild index 0a5519cc1d4..b0ec57cf566 100644 --- a/reactos/lib/sdk/crt/libcntpr.rbuild +++ b/reactos/lib/sdk/crt/libcntpr.rbuild @@ -152,6 +152,7 @@ strtol.c strtoul.c strtoull.c + wcs.c wcstol.c wcstombs_nt.c wcstoul.c @@ -166,10 +167,7 @@ wcsnicmp.c wcsupr.c wcscspn.c - wcspbrk.c - wcsset.c wcsspn.c wcsstr.c - wcsrev.c diff --git a/reactos/lib/sdk/crt/misc/stubs.c b/reactos/lib/sdk/crt/misc/stubs.c index fabb0d9c1cb..00f4a2b0300 100644 --- a/reactos/lib/sdk/crt/misc/stubs.c +++ b/reactos/lib/sdk/crt/misc/stubs.c @@ -30,25 +30,3 @@ void stub(void) FIXME("stub\n"); } -/********************************************************************* - * _getmaxstdio (MSVCRT.@) - */ -int CDECL _getmaxstdio(void) -{ - FIXME("stub, always returns 512\n"); - return 512; -} - -/********************************************************************* -* _setmaxstdio_ (MSVCRT.@) -*/ -int CDECL _setmaxstdio(int newmax) -{ - int res; - if( newmax > 2048) - res = -1; - else - res = newmax; - FIXME("stub: setting new maximum for number of simultaneously open files not implemented,returning %d\n",res); - return res; -} diff --git a/reactos/lib/sdk/crt/precomp.h b/reactos/lib/sdk/crt/precomp.h index 823f849a54c..d341036280c 100644 --- a/reactos/lib/sdk/crt/precomp.h +++ b/reactos/lib/sdk/crt/precomp.h @@ -20,6 +20,7 @@ #include #include +#include #include /* PSDK/NDK Headers */ @@ -54,5 +55,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); #include #include #include +#include #endif /* _CRT_PRECOMP_H */ diff --git a/reactos/lib/sdk/crt/process/process.c b/reactos/lib/sdk/crt/process/process.c index bf5bacf2169..24b97408fdc 100644 --- a/reactos/lib/sdk/crt/process/process.c +++ b/reactos/lib/sdk/crt/process/process.c @@ -1,6 +1,15 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: GPL (?) - See COPYING in the top level directory + * FILE: lib/sdk/crt/process/process.c + * PURPOSE: Process management functions + * PROGRAMMERS: ??? + */ + #include #include #include +#include #ifdef _UNICODE #define sT "S" @@ -205,7 +214,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env return(-1); } - //memset (&StartupInfo, 0, sizeof(StartupInfo)); + memset (&StartupInfo, 0, sizeof(StartupInfo)); StartupInfo.cb = sizeof(StartupInfo); #if 0 @@ -265,7 +274,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env } #endif - create_io_inherit_block((STARTUPINFOA*) &StartupInfo); + create_io_inherit_block(&StartupInfo.cbReserved2, &StartupInfo.lpReserved2); bResult = CreateProcess((_TCHAR *)cmdname, (_TCHAR *)args, diff --git a/reactos/lib/sdk/crt/io/access.c b/reactos/lib/sdk/crt/stdio/access.c similarity index 52% rename from reactos/lib/sdk/crt/io/access.c rename to reactos/lib/sdk/crt/stdio/access.c index ec5768c0e22..de150cd4d88 100644 --- a/reactos/lib/sdk/crt/io/access.c +++ b/reactos/lib/sdk/crt/stdio/access.c @@ -11,28 +11,6 @@ #define MK_STR(s) #s -/* - * @implemented - */ -int _taccess( const _TCHAR *_path, int _amode ) -{ - DWORD Attributes = GetFileAttributes(_path); - TRACE(MK_STR(_taccess)"('%"sT"', %x)\n", _path, _amode); - - if (!_path || Attributes == INVALID_FILE_ATTRIBUTES) { - _dosmaperr(GetLastError()); - return -1; - } - if ((_amode & W_OK) == W_OK) { - if ((Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) { - __set_errno(EACCES); - return -1; - } - } - - return 0; -} - /* * INTERNAL */ diff --git a/reactos/lib/sdk/crt/stdio/allocfil.c b/reactos/lib/sdk/crt/stdio/allocfil.c deleted file mode 100644 index 48773382884..00000000000 --- a/reactos/lib/sdk/crt/stdio/allocfil.c +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include - -char __validfp (FILE *f) -{ - if ( (unsigned int)f < 256) - return FALSE; - - if( f == NULL || (int)f== -1 ) - return FALSE; - - return TRUE; -} - -/* A FILE* is considered "free" if its flag is zero. */ - -FILE *__alloc_file(void) -{ - __file_rec *fr = __file_rec_list; - __file_rec **last_fr = &__file_rec_list; - FILE *rv=0; - int i; - - /* 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]->_flag == 0) - { - return fr->files[i]; - } - } - - /* 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; - } - if (!fr) - { - /* add another one to the end, make it empty */ - fr = *last_fr = (__file_rec *)malloc(sizeof(__file_rec)); - if (fr == 0) - return 0; - fr->next = 0; - fr->count = 0; - } - /* fr is a pointer to a rec with empty slots in it */ - rv = fr->files[fr->count] = (FILE *)malloc(sizeof(FILE)); - if (rv == 0) - return 0; - memset(rv, 0, sizeof(FILE)); - fr->count ++; - return rv; -} - - -/* - * @implemented - */ -int _fcloseall( void ) -{ - __file_rec *fr = __file_rec_list; - __file_rec **last_fr = &__file_rec_list; - - int total_closed = 0; - int i = 0; - - /* 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]->_flag != 0) { - fclose(fr->files[i]); - 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; -} diff --git a/reactos/lib/sdk/crt/stdio/clearerr.c b/reactos/lib/sdk/crt/stdio/clearerr.c deleted file mode 100644 index 63621700e4b..00000000000 --- a/reactos/lib/sdk/crt/stdio/clearerr.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#ifdef clearerr -#undef clearerr -void clearerr(FILE *stream); -#endif - -/* - * @implemented - */ -void -clearerr(FILE *f) -{ - if (!__validfp (f)) { - __set_errno (EINVAL); - return; - } - f->_flag &= ~(_IOERR|_IOEOF); -} diff --git a/reactos/lib/sdk/crt/stdio/fclose.c b/reactos/lib/sdk/crt/stdio/fclose.c deleted file mode 100644 index 85372c42f8f..00000000000 --- a/reactos/lib/sdk/crt/stdio/fclose.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include -#include - - -// changed check for writable stream - - -/* - * @implemented - */ -int -fclose(FILE *f) -{ - int r = 0; - - if (f == NULL) { - __set_errno (EINVAL); - return EOF; - } - - - -// flush only if stream was opened for writing - if ( !(f->_flag&_IOSTRG) ) { - if ( OPEN4WRITING(f) ) - r = fflush(f); - - if (_close(_fileno(f)) < 0) - r = EOF; - if (f->_flag&_IOMYBUF) - free(f->_base); - -// Kernel might do this later - if (f->_flag & _IORMONCL && f->_tmpfname) - { - remove(f->_tmpfname); - free(f->_tmpfname); - f->_tmpfname = 0; - } - } - f->_cnt = 0; - f->_base = 0; - f->_ptr = 0; - f->_bufsiz = 0; - f->_flag = 0; - f->_file = -1; - return r; -} diff --git a/reactos/lib/sdk/crt/stdio/fdopen.c b/reactos/lib/sdk/crt/stdio/fdopen.c deleted file mode 100644 index bb33e3ab8cd..00000000000 --- a/reactos/lib/sdk/crt/stdio/fdopen.c +++ /dev/null @@ -1,55 +0,0 @@ -#include - -#include - -/* - * @implemented - */ -FILE* _tfdopen(int handle, -#ifndef _UNICODE - const -#endif - _TCHAR* mode) -{ - FILE* file; - int rw; - - if (handle == 0) - return stdin; - - if (handle == 1) - return stdout; - - if (handle == 2) - return stderr; - - file = __alloc_file(); - if (file == NULL) - return NULL; - file->_file = handle; - - rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+')); - - if (*mode == 'a') - _lseek(handle, 0, SEEK_END); - - file->_cnt = 0; - file->_file = handle; - file->_bufsiz = 0; - -// The mode of the stream must be compatible with the mode of the file descriptor. -// this should be checked. - - if (rw) - file->_flag = _IOREAD | _IOWRT; - else if (*mode == 'r') - file->_flag = _IOREAD; - else - file->_flag = _IOWRT; - - file->_base = file->_ptr = NULL; - - return file; -} - - diff --git a/reactos/lib/sdk/crt/stdio/feof.c b/reactos/lib/sdk/crt/stdio/feof.c deleted file mode 100644 index 3174b0b9a21..00000000000 --- a/reactos/lib/sdk/crt/stdio/feof.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#ifdef feof -#undef feof -int feof(FILE *stream); -#endif - -/* - * @implemented - */ -int feof(FILE *stream) -{ - if (stream == NULL) { - __set_errno (EINVAL); - return EOF; - } - - return stream->_flag & _IOEOF; -} diff --git a/reactos/lib/sdk/crt/stdio/ferror.c b/reactos/lib/sdk/crt/stdio/ferror.c deleted file mode 100644 index 8b8183a324b..00000000000 --- a/reactos/lib/sdk/crt/stdio/ferror.c +++ /dev/null @@ -1,17 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#ifdef ferror -#undef ferror -int ferror(FILE *stream); -#endif - -int *_errno(void); - -/* - * @implemented - */ -int ferror(FILE *stream) -{ - return stream->_flag & _IOERR; -} diff --git a/reactos/lib/sdk/crt/stdio/fflush.c b/reactos/lib/sdk/crt/stdio/fflush.c deleted file mode 100644 index bba777621f9..00000000000 --- a/reactos/lib/sdk/crt/stdio/fflush.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/stdio/fflush.c - * PURPOSE: Checks for keyboard hits - * PROGRAMER: Ariadne - * 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 */ -#include -#include - -/* - * @implemented - */ -int fflush(FILE *f) -{ - char *base; - int n, rn; - - - - if (f == NULL) - { - int e = *_errno(); - - __set_errno(0); - _fwalk((void (*)(FILE *))fflush); - if (*_errno()) - return EOF; - __set_errno(e); - return 0; - } - - -// nothing to do if stream can not be written to - - if ( !OPEN4WRITING(f) ) { - __set_errno (EINVAL); - return 0; - } - -// discard any unget characters - - f->_flag &= ~_IOUNGETC; - - -// check for buffered dirty block - - if ( (f->_flag&(_IODIRTY|_IONBF)) ==_IODIRTY && f->_base != NULL) - { - - base = f->_base; - - -// if the buffer is read ahead and dirty we will flush it entirely -// else the buffer is appended to the file to the extend it has valid bytes - - if ( (f->_flag & _IOAHEAD) == _IOAHEAD ) - rn = n = f->_ptr - base + f->_cnt; - else - rn = n = f->_ptr - base; - - f->_ptr = base; - - if ((f->_flag & _IOFBF) == _IOFBF) { - if ( (f->_flag & _IOAHEAD) == _IOAHEAD ) - _lseek(_fileno(f),-rn, SEEK_CUR); - } - - f->_flag &= ~_IOAHEAD; - - - f->_cnt = (f->_flag&(_IO_LBF|_IONBF)) ? 0 : f->_bufsiz; - -// how can write return less than rn without being on error ??? - -// possibly commit the flushed data -// better open the file in write through mode - - while (rn > 0) { - n = _write(_fileno(f), base, rn); - if (n <= 0) { - f->_flag |= _IOERR; - return EOF; - } - rn -= n; - base += n; - }; - f->_flag &= ~_IODIRTY; - -// commit flushed data -// _commit(_fileno(f)); - } - if (OPEN4READING(f) && OPEN4WRITING(f) ) - { - f->_cnt = 0; - f->_ptr = f->_base; - } - return 0; -} - -/* - * @implemented - */ -int _flushall( void ) -{ - return fflush(NULL); -} diff --git a/reactos/lib/sdk/crt/stdio/fgetc.c b/reactos/lib/sdk/crt/stdio/fgetc.c deleted file mode 100644 index b1ad851e079..00000000000 --- a/reactos/lib/sdk/crt/stdio/fgetc.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/stdio/fgetc.c - * PURPOSE: Get a character string from stdin - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Appropriated for Reactos - 25/02/99: Added fgetwc - */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int fgetc(FILE *f) -{ - return getc(f); -} - -/* - * @implemented - */ -wint_t fgetwc(FILE *f) -{ - return getwc(f); -} diff --git a/reactos/lib/sdk/crt/stdio/fgetchar.c b/reactos/lib/sdk/crt/stdio/fgetchar.c deleted file mode 100644 index 5908c89316d..00000000000 --- a/reactos/lib/sdk/crt/stdio/fgetchar.c +++ /dev/null @@ -1,37 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * fgetchar.c - * - * Copyright (C) 2002 Robert Dickenson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -int _fgetchar(void) -{ - return getc(stdin); -} - -/* - * @implemented - */ -wint_t _fgetwchar(void) -{ - return getwc(stdin); -} diff --git a/reactos/lib/sdk/crt/stdio/fgetpos.c b/reactos/lib/sdk/crt/stdio/fgetpos.c deleted file mode 100644 index a40224e1725..00000000000 --- a/reactos/lib/sdk/crt/stdio/fgetpos.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int fgetpos(FILE *stream, fpos_t *pos) -{ - if (stream && pos) - { - *pos = (fpos_t)ftell(stream); - return 0; - } - //__set_errno ( EFAULT ); - return 1; -} diff --git a/reactos/lib/sdk/crt/stdio/fgets.c b/reactos/lib/sdk/crt/stdio/fgets.c deleted file mode 100644 index c59c11ab04f..00000000000 --- a/reactos/lib/sdk/crt/stdio/fgets.c +++ /dev/null @@ -1,44 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * fgets.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * 28/12/1998: Appropriated for Reactos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -char* fgets(char* s, int n, FILE* f) -{ - int c = 0; - char* cs; - - cs = s; - while (--n>0 && (c = getc(f)) != EOF) { - *cs++ = c; - if (c == '\n') - break; - } - if (c == EOF && cs == s) - return NULL; - *cs++ = '\0'; - return s; -} diff --git a/reactos/lib/sdk/crt/stdio/fgetws.c b/reactos/lib/sdk/crt/stdio/fgetws.c deleted file mode 100644 index 7a75a5d3257..00000000000 --- a/reactos/lib/sdk/crt/stdio/fgetws.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * fgets.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * 28/12/1998: Appropriated for Reactos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#ifndef WEOF -#define WEOF (wchar_t)(0xFFFF) -#endif - -wchar_t* fgetws(wchar_t* s, int n, FILE* f) -{ - - int c=0; - wchar_t *cs; - - cs = s; - while (--n>0 && (c = getwc(f)) != WEOF) - { - *cs++ = c; - if (c == L'\n') - break; - } - if (c == WEOF && cs == s) - return NULL; - *cs++ = L'\0'; - return s; -} diff --git a/reactos/lib/sdk/crt/stdio/filbuf.c b/reactos/lib/sdk/crt/stdio/filbuf.c deleted file mode 100644 index b4f911678a8..00000000000 --- a/reactos/lib/sdk/crt/stdio/filbuf.c +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright (C) 1997 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 */ -#include - -int _readcnv(int fn, void* buf, size_t siz); - -/* - * @implemented - */ -int _filbuf(FILE* f) -{ - int size; - char c; - - if ( !OPEN4READING(f)) { - __set_errno (EINVAL); - return EOF; - } - if (f->_flag&(_IOSTRG|_IOEOF)) - return EOF; - f->_flag &= ~_IOUNGETC; - - if (f->_base == NULL && (f->_flag & _IONBF) == 0) { - size = 4096; - if ((f->_base = malloc(size+1)) == NULL) { - // error ENOMEM - f->_flag |= _IONBF; - f->_flag &= ~(_IOFBF|_IO_LBF); - } else { - f->_flag |= _IOMYBUF; - f->_bufsiz = size; - } - } - if (f->_flag&_IONBF) - f->_base = &c; - - // flush stdout before reading from stdin - if (f == stdin) { - if (stdout->_flag&_IO_LBF) - fflush(stdout); - if (stderr->_flag&_IO_LBF) - fflush(stderr); - } - - // if we have a dirty stream we flush it - if ((f->_flag &_IODIRTY) == _IODIRTY) - fflush(f); - - - - f->_cnt = _read(_fileno(f), f->_base, f->_flag & _IONBF ? 1 : f->_bufsiz ); - f->_flag |= _IOAHEAD; - - if(__is_text_file(f) && f->_cnt>0) - { - /* truncate text file at Ctrl-Z */ - char *cz=memchr(f->_base, 0x1A, f->_cnt); - if(cz) - { - int newcnt = cz - f->_base; - _lseek(_fileno(f), -(f->_cnt - newcnt), SEEK_CUR); - f->_cnt = newcnt; - } - } - - f->_ptr = f->_base; - - if (f->_flag & _IONBF) - f->_base = NULL; // statically allocated buffer for sprintf - - -//check for error - if (f->_cnt <= 0) { - if (f->_cnt == 0) { - f->_flag |= _IOEOF; - } else - f->_flag |= _IOERR; - f->_cnt = 0; - -// FIXME should set errno - - return EOF; - } - - f->_cnt--; - - return *f->_ptr++ & 0377; -} - -wint_t _filwbuf(FILE *fp) -{ - return (wint_t )_filbuf(fp); -} - -// convert the carriage return line feed pairs -/* -int _readcnv(int fn, void *buf, size_t siz ) -{ - char *bufp = (char *)buf; - int _bufsiz = siz; - int cr = 0; - int n; - - n = _read(fn, buf, siz ); - - while (_bufsiz > 0) { - if (*bufp == '\r') - cr++; - else if ( cr != 0 ) - *bufp = *(bufp + cr); - bufp++; - _bufsiz--; - } - return n + cr; -} - */ diff --git a/reactos/lib/sdk/crt/stdio/file.c b/reactos/lib/sdk/crt/stdio/file.c index 05de7e31e78..16682d5e466 100644 --- a/reactos/lib/sdk/crt/stdio/file.c +++ b/reactos/lib/sdk/crt/stdio/file.c @@ -1,3 +1,12 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: LGPL - See COPYING in the top level directory + * FILE: lib/sdk/crt/stdio/file.c + * PURPOSE: File CRT functions + * PROGRAMMERS: Wine team + * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org) + */ + /* * msvcrt.dll file functions * @@ -29,15 +38,43 @@ #include #include "wine/unicode.h" -#if 0 +#include +#include +int *__p__fmode(void); +int *__p___mb_cur_max(void); + +#ifdef feof +#undef feof +#endif +#ifdef _fileno +#undef _fileno +#endif +#ifdef ferror +#undef ferror +#endif +#ifdef clearerr +#undef clearerr +#endif + +#undef getc +#undef getwc +#undef getchar +#undef getwchar +#undef putc +#undef putwc +#undef putchar +#undef putwchar + +#undef vprintf +#undef vwprintf /* for stat mode, permissions apply to all,owner and group */ -#define ALL_S_IREAD (MSVCRT__S_IREAD | (MSVCRT__S_IREAD >> 3) | (MSVCRT__S_IREAD >> 6)) -#define ALL_S_IWRITE (MSVCRT__S_IWRITE | (MSVCRT__S_IWRITE >> 3) | (MSVCRT__S_IWRITE >> 6)) -#define ALL_S_IEXEC (MSVCRT__S_IEXEC | (MSVCRT__S_IEXEC >> 3) | (MSVCRT__S_IEXEC >> 6)) +#define ALL_S_IREAD (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6)) +#define ALL_S_IWRITE (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6)) +#define ALL_S_IEXEC (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6)) /* _access() bit flags FIXME: incomplete */ -#define MSVCRT_W_OK 0x02 +/* defined in crt/io.h */ /* values for wxflag in file descriptor */ #define WX_OPEN 0x01 @@ -48,29 +85,30 @@ #define WX_TEXT 0x80 /* FIXME: this should be allocated dynamically */ -#define MSVCRT_MAX_FILES 2048 +#define MAX_FILES 2048 +/* ReactOS: Use _FDINFO instead! */ typedef struct { HANDLE handle; unsigned char wxflag; DWORD unkn[7]; /* critical section and init flag */ } ioinfo; -static ioinfo MSVCRT_fdesc[MSVCRT_MAX_FILES]; +/*static */ioinfo fdesc[MAX_FILES]; -MSVCRT_FILE MSVCRT__iob[3]; +FILE _iob[3]; -static int MSVCRT_fdstart = 3; /* first unallocated fd */ -static int MSVCRT_fdend = 3; /* highest allocated fd */ +static int fdstart = 3; /* first unallocated fd */ +static int fdend = 3; /* highest allocated fd */ -static MSVCRT_FILE* MSVCRT_fstreams[2048]; -static int MSVCRT_stream_idx; +static FILE* fstreams[2048]; +static int stream_idx; /* INTERNAL: process umask */ static int MSVCRT_umask = 0; /* INTERNAL: Static buffer for temp file name */ -static char MSVCRT_tmpname[MAX_PATH]; +static char tmpname[MAX_PATH]; static const unsigned int EXE = 'e' << 16 | 'x' << 8 | 'e'; static const unsigned int BAT = 'b' << 16 | 'a' << 8 | 't'; @@ -83,18 +121,18 @@ static const ULONGLONG WCBAT = TOUL('b') << 32 | TOUL('a') << 16 | TOUL('t'); static const ULONGLONG WCCMD = TOUL('c') << 32 | TOUL('m') << 16 | TOUL('d'); static const ULONGLONG WCCOM = TOUL('c') << 32 | TOUL('o') << 16 | TOUL('m'); -/* This critical section protects the tables MSVCRT_fdesc and MSVCRT_fstreams, - * and their related indexes, MSVCRT_fdstart, MSVCRT_fdend, - * and MSVCRT_stream_idx, from race conditions. +/* This critical section protects the tables fdesc and fstreams, + * and their related indexes, fdstart, fdend, + * and stream_idx, from race conditions. * It doesn't protect against race conditions manipulating the underlying files * or flags; doing so would probably be better accomplished with per-file * protection, rather than locking the whole table for every change. */ -static CRITICAL_SECTION MSVCRT_file_cs; -#define LOCK_FILES() do { EnterCriticalSection(&MSVCRT_file_cs); } while (0) -#define UNLOCK_FILES() do { LeaveCriticalSection(&MSVCRT_file_cs); } while (0) +static CRITICAL_SECTION FILE_cs; +#define LOCK_FILES() do { EnterCriticalSection(&FILE_cs); } while (0) +#define UNLOCK_FILES() do { LeaveCriticalSection(&FILE_cs); } while (0) -static void msvcrt_stat64_to_stat(const struct MSVCRT__stat64 *buf64, struct MSVCRT__stat *buf) +static void stat64_to_stat(const struct __stat64 *buf64, struct _stat *buf) { buf->st_dev = buf64->st_dev; buf->st_ino = buf64->st_ino; @@ -109,7 +147,7 @@ static void msvcrt_stat64_to_stat(const struct MSVCRT__stat64 *buf64, struct MSV buf->st_ctime = buf64->st_ctime; } -static void msvcrt_stat64_to_stati64(const struct MSVCRT__stat64 *buf64, struct MSVCRT__stati64 *buf) +static void stat64_to_stati64(const struct __stat64 *buf64, struct _stati64 *buf) { buf->st_dev = buf64->st_dev; buf->st_ino = buf64->st_ino; @@ -124,9 +162,9 @@ static void msvcrt_stat64_to_stati64(const struct MSVCRT__stat64 *buf64, struct buf->st_ctime = buf64->st_ctime; } -static inline BOOL msvcrt_is_valid_fd(int fd) +static inline BOOL is_valid_fd(int fd) { - return fd >= 0 && fd < MSVCRT_fdend && (MSVCRT_fdesc[fd].wxflag & WX_OPEN); + return fd >= 0 && fd < fdend && (fdesc[fd].wxflag & WX_OPEN); } /* INTERNAL: Get the HANDLE for a fd @@ -135,25 +173,25 @@ static inline BOOL msvcrt_is_valid_fd(int fd) * it returns a valid handle which is about to be closed, a subsequent call * will fail, most likely in a sane way. */ -static HANDLE msvcrt_fdtoh(int fd) +static HANDLE fdtoh(int fd) { - if (!msvcrt_is_valid_fd(fd)) + if (!is_valid_fd(fd)) { WARN(":fd (%d) - no handle!\n",fd); - *MSVCRT___doserrno() = 0; - *MSVCRT__errno() = MSVCRT_EBADF; + *__doserrno() = 0; + *_errno() = EBADF; return INVALID_HANDLE_VALUE; } - if (MSVCRT_fdesc[fd].handle == INVALID_HANDLE_VALUE) FIXME("wtf\n"); - return MSVCRT_fdesc[fd].handle; + if (fdesc[fd].handle == INVALID_HANDLE_VALUE) FIXME("wtf\n"); + return fdesc[fd].handle; } /* INTERNAL: free a file entry fd */ -static void msvcrt_free_fd(int fd) +static void free_fd(int fd) { LOCK_FILES(); - MSVCRT_fdesc[fd].handle = INVALID_HANDLE_VALUE; - MSVCRT_fdesc[fd].wxflag = 0; + fdesc[fd].handle = INVALID_HANDLE_VALUE; + fdesc[fd].wxflag = 0; TRACE(":fd (%d) freed\n",fd); if (fd < 3) /* don't use 0,1,2 for user files */ { @@ -166,37 +204,37 @@ static void msvcrt_free_fd(int fd) } else { - if (fd == MSVCRT_fdend - 1) - MSVCRT_fdend--; - if (fd < MSVCRT_fdstart) - MSVCRT_fdstart = fd; + if (fd == fdend - 1) + fdend--; + if (fd < fdstart) + fdstart = fd; } UNLOCK_FILES(); } /* INTERNAL: Allocate an fd slot from a Win32 HANDLE, starting from fd */ /* caller must hold the files lock */ -static int msvcrt_alloc_fd_from(HANDLE hand, int flag, int fd) +static int alloc_fd_from(HANDLE hand, int flag, int fd) { - if (fd >= MSVCRT_MAX_FILES) + if (fd >= MAX_FILES) { WARN(":files exhausted!\n"); return -1; } - MSVCRT_fdesc[fd].handle = hand; - MSVCRT_fdesc[fd].wxflag = WX_OPEN | (flag & (WX_DONTINHERIT | WX_APPEND | WX_TEXT)); + fdesc[fd].handle = hand; + fdesc[fd].wxflag = WX_OPEN | (flag & (WX_DONTINHERIT | WX_APPEND | WX_TEXT)); /* locate next free slot */ - if (fd == MSVCRT_fdstart && fd == MSVCRT_fdend) - MSVCRT_fdstart = MSVCRT_fdend + 1; + if (fd == fdstart && fd == fdend) + fdstart = fdend + 1; else - while (MSVCRT_fdstart < MSVCRT_fdend && - MSVCRT_fdesc[MSVCRT_fdstart].handle != INVALID_HANDLE_VALUE) - MSVCRT_fdstart++; + while (fdstart < fdend && + fdesc[fdstart].handle != INVALID_HANDLE_VALUE) + fdstart++; /* update last fd in use */ - if (fd >= MSVCRT_fdend) - MSVCRT_fdend = fd + 1; - TRACE("fdstart is %d, fdend is %d\n", MSVCRT_fdstart, MSVCRT_fdend); + if (fd >= fdend) + fdend = fd + 1; + TRACE("fdstart is %d, fdend is %d\n", fdstart, fdend); switch (fd) { @@ -209,48 +247,48 @@ static int msvcrt_alloc_fd_from(HANDLE hand, int flag, int fd) } /* INTERNAL: Allocate an fd slot from a Win32 HANDLE */ -static int msvcrt_alloc_fd(HANDLE hand, int flag) +/*static */int alloc_fd(HANDLE hand, int flag) { int ret; LOCK_FILES(); - TRACE(":handle (%p) allocating fd (%d)\n",hand,MSVCRT_fdstart); - ret = msvcrt_alloc_fd_from(hand, flag, MSVCRT_fdstart); + TRACE(":handle (%p) allocating fd (%d)\n",hand,fdstart); + ret = alloc_fd_from(hand, flag, fdstart); UNLOCK_FILES(); return ret; } /* INTERNAL: Allocate a FILE* for an fd slot */ /* caller must hold the files lock */ -static MSVCRT_FILE* msvcrt_alloc_fp(void) +static FILE* alloc_fp(void) { unsigned int i; - for (i = 3; i < sizeof(MSVCRT_fstreams) / sizeof(MSVCRT_fstreams[0]); i++) + for (i = 3; i < sizeof(fstreams) / sizeof(fstreams[0]); i++) { - if (!MSVCRT_fstreams[i] || MSVCRT_fstreams[i]->_flag == 0) + if (!fstreams[i] || fstreams[i]->_flag == 0) { - if (!MSVCRT_fstreams[i]) + if (!fstreams[i]) { - if (!(MSVCRT_fstreams[i] = MSVCRT_calloc(sizeof(MSVCRT_FILE),1))) + if (!(fstreams[i] = calloc(sizeof(FILE),1))) return NULL; - if (i == MSVCRT_stream_idx) MSVCRT_stream_idx++; + if (i == stream_idx) stream_idx++; } - return MSVCRT_fstreams[i]; + return fstreams[i]; } } return NULL; } /* INTERNAL: initialize a FILE* from an open fd */ -static int msvcrt_init_fp(MSVCRT_FILE* file, int fd, unsigned stream_flags) +static int init_fp(FILE* file, int fd, unsigned stream_flags) { TRACE(":fd (%d) allocating FILE*\n",fd); - if (!msvcrt_is_valid_fd(fd)) + if (!is_valid_fd(fd)) { WARN(":invalid fd %d\n",fd); - *MSVCRT___doserrno() = 0; - *MSVCRT__errno() = MSVCRT_EBADF; + *__doserrno() = 0; + *_errno() = EBADF; return -1; } memset(file, 0, sizeof(*file)); @@ -267,30 +305,30 @@ static int msvcrt_init_fp(MSVCRT_FILE* file, int fd, unsigned stream_flags) * 04 char file flags (wxflag): repeated for each fd * 4+NBFD HANDLE file handle: repeated for each fd */ -unsigned msvcrt_create_io_inherit_block(WORD *size, BYTE **block) +unsigned create_io_inherit_block(WORD *size, BYTE **block) { int fd; char* wxflag_ptr; HANDLE* handle_ptr; - *size = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * MSVCRT_fdend; - *block = MSVCRT_calloc(*size, 1); + *size = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * fdend; + *block = calloc(*size, 1); if (!*block) { *size = 0; return FALSE; } wxflag_ptr = (char*)*block + sizeof(unsigned); - handle_ptr = (HANDLE*)(wxflag_ptr + MSVCRT_fdend * sizeof(char)); + handle_ptr = (HANDLE*)(wxflag_ptr + fdend * sizeof(char)); - *(unsigned*)*block = MSVCRT_fdend; - for (fd = 0; fd < MSVCRT_fdend; fd++) + *(unsigned*)*block = fdend; + for (fd = 0; fd < fdend; fd++) { /* to be inherited, we need it to be open, and that DONTINHERIT isn't set */ - if ((MSVCRT_fdesc[fd].wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN) + if ((fdesc[fd].wxflag & (WX_OPEN | WX_DONTINHERIT)) == WX_OPEN) { - *wxflag_ptr = MSVCRT_fdesc[fd].wxflag; - *handle_ptr = MSVCRT_fdesc[fd].handle; + *wxflag_ptr = fdesc[fd].wxflag; + *handle_ptr = fdesc[fd].handle; } else { @@ -310,83 +348,101 @@ void msvcrt_init_io(void) STARTUPINFOA si; int i; - InitializeCriticalSection(&MSVCRT_file_cs); - MSVCRT_file_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": MSVCRT_file_cs"); + InitializeCriticalSection(&FILE_cs); + FILE_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": FILE_cs"); GetStartupInfoA(&si); if (si.cbReserved2 != 0 && si.lpReserved2 != NULL) { char* wxflag_ptr; HANDLE* handle_ptr; - MSVCRT_fdend = *(unsigned*)si.lpReserved2; + fdend = *(unsigned*)si.lpReserved2; wxflag_ptr = (char*)(si.lpReserved2 + sizeof(unsigned)); - handle_ptr = (HANDLE*)(wxflag_ptr + MSVCRT_fdend * sizeof(char)); + handle_ptr = (HANDLE*)(wxflag_ptr + fdend * sizeof(char)); - MSVCRT_fdend = min(MSVCRT_fdend, sizeof(MSVCRT_fdesc) / sizeof(MSVCRT_fdesc[0])); - for (i = 0; i < MSVCRT_fdend; i++) + fdend = min(fdend, sizeof(fdesc) / sizeof(fdesc[0])); + for (i = 0; i < fdend; i++) { if ((*wxflag_ptr & WX_OPEN) && *handle_ptr != INVALID_HANDLE_VALUE) { - MSVCRT_fdesc[i].wxflag = *wxflag_ptr; - MSVCRT_fdesc[i].handle = *handle_ptr; + fdesc[i].wxflag = *wxflag_ptr; + fdesc[i].handle = *handle_ptr; } else { - MSVCRT_fdesc[i].wxflag = 0; - MSVCRT_fdesc[i].handle = INVALID_HANDLE_VALUE; + fdesc[i].wxflag = 0; + fdesc[i].handle = INVALID_HANDLE_VALUE; } wxflag_ptr++; handle_ptr++; } - for (MSVCRT_fdstart = 3; MSVCRT_fdstart < MSVCRT_fdend; MSVCRT_fdstart++) - if (MSVCRT_fdesc[MSVCRT_fdstart].handle == INVALID_HANDLE_VALUE) break; + for (fdstart = 3; fdstart < fdend; fdstart++) + if (fdesc[fdstart].handle == INVALID_HANDLE_VALUE) break; } - if (!(MSVCRT_fdesc[0].wxflag & WX_OPEN) || MSVCRT_fdesc[0].handle == INVALID_HANDLE_VALUE) + if (!(fdesc[0].wxflag & WX_OPEN) || fdesc[0].handle == INVALID_HANDLE_VALUE) { +#ifndef __REACTOS__ DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_INPUT_HANDLE), - GetCurrentProcess(), &MSVCRT_fdesc[0].handle, 0, TRUE, + GetCurrentProcess(), &fdesc[0].handle, 0, TRUE, DUPLICATE_SAME_ACCESS); - MSVCRT_fdesc[0].wxflag = WX_OPEN | WX_TEXT; +#else + fdesc[0].handle = GetStdHandle(STD_INPUT_HANDLE); + if (fdesc[0].handle == NULL) + fdesc[0].handle = INVALID_HANDLE_VALUE; +#endif + fdesc[0].wxflag = WX_OPEN | WX_TEXT; } - if (!(MSVCRT_fdesc[1].wxflag & WX_OPEN) || MSVCRT_fdesc[1].handle == INVALID_HANDLE_VALUE) + if (!(fdesc[1].wxflag & WX_OPEN) || fdesc[1].handle == INVALID_HANDLE_VALUE) { - DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE), - GetCurrentProcess(), &MSVCRT_fdesc[1].handle, 0, TRUE, +#ifndef __REACTOS__ + DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE), + GetCurrentProcess(), &fdesc[1].handle, 0, TRUE, DUPLICATE_SAME_ACCESS); - MSVCRT_fdesc[1].wxflag = WX_OPEN | WX_TEXT; +#else + fdesc[1].handle = GetStdHandle(STD_OUTPUT_HANDLE); + if (fdesc[1].handle == NULL) + fdesc[1].handle = INVALID_HANDLE_VALUE; +#endif + fdesc[1].wxflag = WX_OPEN | WX_TEXT; } - if (!(MSVCRT_fdesc[2].wxflag & WX_OPEN) || MSVCRT_fdesc[2].handle == INVALID_HANDLE_VALUE) + if (!(fdesc[2].wxflag & WX_OPEN) || fdesc[2].handle == INVALID_HANDLE_VALUE) { - DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE), - GetCurrentProcess(), &MSVCRT_fdesc[2].handle, 0, TRUE, +#ifndef __REACTOS__ + DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE), + GetCurrentProcess(), &fdesc[2].handle, 0, TRUE, DUPLICATE_SAME_ACCESS); - MSVCRT_fdesc[2].wxflag = WX_OPEN | WX_TEXT; +#else + fdesc[2].handle = GetStdHandle(STD_ERROR_HANDLE); + if (fdesc[2].handle == NULL) + fdesc[2].handle = INVALID_HANDLE_VALUE; +#endif + fdesc[2].wxflag = WX_OPEN | WX_TEXT; } - TRACE(":handles (%p)(%p)(%p)\n",MSVCRT_fdesc[0].handle, - MSVCRT_fdesc[1].handle,MSVCRT_fdesc[2].handle); + TRACE(":handles (%p)(%p)(%p)\n",fdesc[0].handle, + fdesc[1].handle,fdesc[2].handle); - memset(MSVCRT__iob,0,3*sizeof(MSVCRT_FILE)); + memset(_iob,0,3*sizeof(FILE)); for (i = 0; i < 3; i++) { /* FILE structs for stdin/out/err are static and never deleted */ - MSVCRT_fstreams[i] = &MSVCRT__iob[i]; - MSVCRT__iob[i]._file = i; - MSVCRT__iob[i]._tmpfname = NULL; - MSVCRT__iob[i]._flag = (i == 0) ? MSVCRT__IOREAD : MSVCRT__IOWRT; + fstreams[i] = &_iob[i]; + _iob[i]._file = i; + _iob[i]._tmpfname = NULL; + _iob[i]._flag = (i == 0) ? _IOREAD : _IOWRT; } - MSVCRT_stream_idx = 3; + stream_idx = 3; } /* INTERNAL: Flush stdio file buffer */ -static int msvcrt_flush_buffer(MSVCRT_FILE* file) +static int flush_buffer(FILE* file) { if(file->_bufsiz) { int cnt=file->_ptr-file->_base; - if(cnt>0 && MSVCRT__write(file->_file, file->_base, cnt) != cnt) { - file->_flag |= MSVCRT__IOERR; - return MSVCRT_EOF; + if(cnt>0 && _write(file->_file, file->_base, cnt) != cnt) { + file->_flag |= _IOERR; + return EOF; } file->_ptr=file->_base; file->_cnt=file->_bufsiz; @@ -395,12 +451,12 @@ static int msvcrt_flush_buffer(MSVCRT_FILE* file) } /* INTERNAL: Allocate stdio file buffer */ -static void msvcrt_alloc_buffer(MSVCRT_FILE* file) +static void alloc_buffer(FILE* file) { - file->_base = MSVCRT_calloc(MSVCRT_BUFSIZ,1); + file->_base = calloc(BUFSIZ,1); if(file->_base) { - file->_bufsiz = MSVCRT_BUFSIZ; - file->_flag |= MSVCRT__IOMYBUF; + file->_bufsiz = BUFSIZ; + file->_flag |= _IOMYBUF; } else { file->_base = (char*)(&file->_charbuf); /* put here 2 ??? */ @@ -411,7 +467,7 @@ static void msvcrt_alloc_buffer(MSVCRT_FILE* file) } /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */ -static void msvcrt_int_to_base32(int num, char *str) +static void int_to_base32(int num, char *str) { char *p; int n = num; @@ -436,15 +492,15 @@ static void msvcrt_int_to_base32(int num, char *str) /********************************************************************* * __p__iob(MSVCRT.@) */ -MSVCRT_FILE * CDECL __p__iob(void) +FILE * CDECL __p__iob(void) { - return &MSVCRT__iob[0]; + return &_iob[0]; } /********************************************************************* * _access (MSVCRT.@) */ -int CDECL MSVCRT__access(const char *filename, int mode) +int CDECL _access(const char *filename, int mode) { DWORD attr = GetFileAttributesA(filename); @@ -452,12 +508,12 @@ int CDECL MSVCRT__access(const char *filename, int mode) if (!filename || attr == INVALID_FILE_ATTRIBUTES) { - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } - if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & MSVCRT_W_OK)) + if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK)) { - msvcrt_set_errno(ERROR_ACCESS_DENIED); + __set_errno(ERROR_ACCESS_DENIED); return -1; } return 0; @@ -466,7 +522,7 @@ int CDECL MSVCRT__access(const char *filename, int mode) /********************************************************************* * _waccess (MSVCRT.@) */ -int CDECL _waccess(const MSVCRT_wchar_t *filename, int mode) +int CDECL _waccess(const wchar_t *filename, int mode) { DWORD attr = GetFileAttributesW(filename); @@ -474,12 +530,12 @@ int CDECL _waccess(const MSVCRT_wchar_t *filename, int mode) if (!filename || attr == INVALID_FILE_ATTRIBUTES) { - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } - if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & MSVCRT_W_OK)) + if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK)) { - msvcrt_set_errno(ERROR_ACCESS_DENIED); + __set_errno(ERROR_ACCESS_DENIED); return -1; } return 0; @@ -488,69 +544,69 @@ int CDECL _waccess(const MSVCRT_wchar_t *filename, int mode) /********************************************************************* * _chmod (MSVCRT.@) */ -int CDECL MSVCRT__chmod(const char *path, int flags) +int CDECL _chmod(const char *path, int flags) { DWORD oldFlags = GetFileAttributesA(path); if (oldFlags != INVALID_FILE_ATTRIBUTES) { - DWORD newFlags = (flags & MSVCRT__S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: + DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: oldFlags | FILE_ATTRIBUTE_READONLY; if (newFlags == oldFlags || SetFileAttributesA(path, newFlags)) return 0; } - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } /********************************************************************* * _wchmod (MSVCRT.@) */ -int CDECL _wchmod(const MSVCRT_wchar_t *path, int flags) +int CDECL _wchmod(const wchar_t *path, int flags) { DWORD oldFlags = GetFileAttributesW(path); if (oldFlags != INVALID_FILE_ATTRIBUTES) { - DWORD newFlags = (flags & MSVCRT__S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: + DWORD newFlags = (flags & _S_IWRITE)? oldFlags & ~FILE_ATTRIBUTE_READONLY: oldFlags | FILE_ATTRIBUTE_READONLY; if (newFlags == oldFlags || SetFileAttributesW(path, newFlags)) return 0; } - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } /********************************************************************* * _unlink (MSVCRT.@) */ -int CDECL MSVCRT__unlink(const char *path) +int CDECL _unlink(const char *path) { TRACE("%s\n",debugstr_a(path)); if(DeleteFileA(path)) return 0; TRACE("failed (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } /********************************************************************* * _wunlink (MSVCRT.@) */ -int CDECL _wunlink(const MSVCRT_wchar_t *path) +int CDECL _wunlink(const wchar_t *path) { TRACE("(%s)\n",debugstr_w(path)); if(DeleteFileW(path)) return 0; TRACE("failed (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } -/* _flushall calls MSVCRT_fflush which calls _flushall */ -int CDECL MSVCRT_fflush(MSVCRT_FILE* file); +/* _flushall calls fflush which calls _flushall */ +int CDECL fflush(FILE* file); /********************************************************************* * _flushall (MSVCRT.@) @@ -560,17 +616,17 @@ int CDECL _flushall(void) int i, num_flushed = 0; LOCK_FILES(); - for (i = 3; i < MSVCRT_stream_idx; i++) - if (MSVCRT_fstreams[i] && MSVCRT_fstreams[i]->_flag) + for (i = 3; i < stream_idx; i++) + if (fstreams[i] && fstreams[i]->_flag) { #if 0 /* FIXME: flush, do not commit */ if (_commit(i) == -1) - if (MSVCRT_fstreams[i]) - MSVCRT_fstreams[i]->_flag |= MSVCRT__IOERR; + if (fstreams[i]) + fstreams[i]->_flag |= _IOERR; #endif - if(MSVCRT_fstreams[i]->_flag & MSVCRT__IOWRT) { - MSVCRT_fflush(MSVCRT_fstreams[i]); + if(fstreams[i]->_flag & _IOWRT) { + fflush(fstreams[i]); num_flushed++; } } @@ -583,12 +639,12 @@ int CDECL _flushall(void) /********************************************************************* * fflush (MSVCRT.@) */ -int CDECL MSVCRT_fflush(MSVCRT_FILE* file) +int CDECL fflush(FILE* file) { if(!file) { _flushall(); - } else if(file->_flag & MSVCRT__IOWRT) { - int res=msvcrt_flush_buffer(file); + } else if(file->_flag & _IOWRT) { + int res=flush_buffer(file); return res; } return 0; @@ -597,25 +653,25 @@ int CDECL MSVCRT_fflush(MSVCRT_FILE* file) /********************************************************************* * _close (MSVCRT.@) */ -int CDECL MSVCRT__close(int fd) +int CDECL _close(int fd) { HANDLE hand; int ret; LOCK_FILES(); - hand = msvcrt_fdtoh(fd); + hand = fdtoh(fd); TRACE(":fd (%d) handle (%p)\n",fd,hand); if (hand == INVALID_HANDLE_VALUE) ret = -1; else if (!CloseHandle(hand)) { WARN(":failed-last error (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); ret = -1; } else { - msvcrt_free_fd(fd); + free_fd(fd); ret = 0; } UNLOCK_FILES(); @@ -628,7 +684,7 @@ int CDECL MSVCRT__close(int fd) */ int CDECL _commit(int fd) { - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); TRACE(":fd (%d) handle (%p)\n",fd,hand); if (hand == INVALID_HANDLE_VALUE) @@ -644,7 +700,7 @@ int CDECL _commit(int fd) return 0; } TRACE(":failed-last error (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } TRACE(":ok\n"); @@ -658,28 +714,28 @@ int CDECL _commit(int fd) * indicate file descriptors duplicated with _dup and _dup2 are always * inheritable. */ -int CDECL MSVCRT__dup2(int od, int nd) +int CDECL _dup2(int od, int nd) { int ret; TRACE("(od=%d, nd=%d)\n", od, nd); LOCK_FILES(); - if (nd < MSVCRT_MAX_FILES && msvcrt_is_valid_fd(od)) + if (nd < MAX_FILES && is_valid_fd(od)) { HANDLE handle; - if (DuplicateHandle(GetCurrentProcess(), MSVCRT_fdesc[od].handle, + if (DuplicateHandle(GetCurrentProcess(), fdesc[od].handle, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS)) { - int wxflag = MSVCRT_fdesc[od].wxflag & ~MSVCRT__O_NOINHERIT; + int wxflag = fdesc[od].wxflag & ~_O_NOINHERIT; - if (msvcrt_is_valid_fd(nd)) - MSVCRT__close(nd); - ret = msvcrt_alloc_fd_from(handle, wxflag, nd); + if (is_valid_fd(nd)) + _close(nd); + ret = alloc_fd_from(handle, wxflag, nd); if (ret == -1) { CloseHandle(handle); - *MSVCRT__errno() = MSVCRT_EMFILE; + *_errno() = EMFILE; } else { @@ -690,12 +746,12 @@ int CDECL MSVCRT__dup2(int od, int nd) else { ret = -1; - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); } } else { - *MSVCRT__errno() = MSVCRT_EBADF; + *_errno() = EBADF; ret = -1; } UNLOCK_FILES(); @@ -705,13 +761,13 @@ int CDECL MSVCRT__dup2(int od, int nd) /********************************************************************* * _dup (MSVCRT.@) */ -int CDECL MSVCRT__dup(int od) +int CDECL _dup(int od) { int fd, ret; LOCK_FILES(); - fd = MSVCRT_fdstart; - if (MSVCRT__dup2(od, fd) == 0) + fd = fdstart; + if (_dup2(od, fd) == 0) ret = fd; else ret = -1; @@ -726,14 +782,14 @@ int CDECL _eof(int fd) { DWORD curpos,endpos; LONG hcurpos,hendpos; - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); TRACE(":fd (%d) handle (%p)\n",fd,hand); if (hand == INVALID_HANDLE_VALUE) return -1; - if (MSVCRT_fdesc[fd].wxflag & WX_ATEOF) return TRUE; + if (fdesc[fd].wxflag & WX_ATEOF) return TRUE; /* Otherwise we do it the hard way */ hcurpos = hendpos = 0; @@ -753,14 +809,14 @@ int CDECL _eof(int fd) /********************************************************************* * _fcloseall (MSVCRT.@) */ -int CDECL MSVCRT__fcloseall(void) +int CDECL _fcloseall(void) { int num_closed = 0, i; LOCK_FILES(); - for (i = 3; i < MSVCRT_stream_idx; i++) - if (MSVCRT_fstreams[i] && MSVCRT_fstreams[i]->_flag && - !MSVCRT_fclose(MSVCRT_fstreams[i])) + for (i = 3; i < stream_idx; i++) + if (fstreams[i] && fstreams[i]->_flag && + !fclose(fstreams[i])) num_closed++; UNLOCK_FILES(); @@ -771,24 +827,24 @@ int CDECL MSVCRT__fcloseall(void) /* free everything on process exit */ void msvcrt_free_io(void) { - MSVCRT__fcloseall(); + _fcloseall(); /* The Win32 _fcloseall() function explicitly doesn't close stdin, * stdout, and stderr (unlike GNU), so we need to fclose() them here * or they won't get flushed. */ - MSVCRT_fclose(&MSVCRT__iob[0]); - MSVCRT_fclose(&MSVCRT__iob[1]); - MSVCRT_fclose(&MSVCRT__iob[2]); - MSVCRT_file_cs.DebugInfo->Spare[0] = 0; - DeleteCriticalSection(&MSVCRT_file_cs); + fclose(&_iob[0]); + fclose(&_iob[1]); + fclose(&_iob[2]); + FILE_cs.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&FILE_cs); } /********************************************************************* * _lseeki64 (MSVCRT.@) */ -__int64 CDECL MSVCRT__lseeki64(int fd, __int64 offset, int whence) +__int64 CDECL _lseeki64(int fd, __int64 offset, int whence) { - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); LARGE_INTEGER ofs, ret; TRACE(":fd (%d) handle (%p)\n",fd,hand); @@ -797,7 +853,7 @@ __int64 CDECL MSVCRT__lseeki64(int fd, __int64 offset, int whence) if (whence < 0 || whence > 2) { - *MSVCRT__errno() = MSVCRT_EINVAL; + *_errno() = EINVAL; return -1; } @@ -810,22 +866,22 @@ __int64 CDECL MSVCRT__lseeki64(int fd, __int64 offset, int whence) ofs.QuadPart = offset; if (SetFilePointerEx(hand, ofs, &ret, whence)) { - MSVCRT_fdesc[fd].wxflag &= ~(WX_ATEOF|WX_READEOF); + fdesc[fd].wxflag &= ~(WX_ATEOF|WX_READEOF); /* FIXME: What if we seek _to_ EOF - is EOF set? */ return ret.QuadPart; } TRACE(":error-last error (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } /********************************************************************* * _lseek (MSVCRT.@) */ -LONG CDECL MSVCRT__lseek(int fd, LONG offset, int whence) +LONG CDECL _lseek(int fd, LONG offset, int whence) { - return MSVCRT__lseeki64(fd, offset, whence); + return _lseeki64(fd, offset, whence); } /********************************************************************* @@ -833,11 +889,11 @@ LONG CDECL MSVCRT__lseek(int fd, LONG offset, int whence) * * This is untested; the underlying LockFile doesn't work yet. */ -int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes) +int CDECL _locking(int fd, int mode, LONG nbytes) { BOOL ret; DWORD cur_locn; - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); TRACE(":fd (%d) handle (%p)\n",fd,hand); if (hand == INVALID_HANDLE_VALUE) @@ -845,25 +901,25 @@ int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes) if (mode < 0 || mode > 4) { - *MSVCRT__errno() = MSVCRT_EINVAL; + *_errno() = EINVAL; return -1; } TRACE(":fd (%d) by 0x%08x mode %s\n", - fd,nbytes,(mode==MSVCRT__LK_UNLCK)?"_LK_UNLCK": - (mode==MSVCRT__LK_LOCK)?"_LK_LOCK": - (mode==MSVCRT__LK_NBLCK)?"_LK_NBLCK": - (mode==MSVCRT__LK_RLCK)?"_LK_RLCK": - (mode==MSVCRT__LK_NBRLCK)?"_LK_NBRLCK": + fd,nbytes,(mode==_LK_UNLCK)?"_LK_UNLCK": + (mode==_LK_LOCK)?"_LK_LOCK": + (mode==_LK_NBLCK)?"_LK_NBLCK": + (mode==_LK_RLCK)?"_LK_RLCK": + (mode==_LK_NBRLCK)?"_LK_NBRLCK": "UNKNOWN"); if ((cur_locn = SetFilePointer(hand, 0L, NULL, SEEK_CUR)) == INVALID_SET_FILE_POINTER) { FIXME ("Seek failed\n"); - *MSVCRT__errno() = MSVCRT_EINVAL; /* FIXME */ + *_errno() = EINVAL; /* FIXME */ return -1; } - if (mode == MSVCRT__LK_LOCK || mode == MSVCRT__LK_RLCK) + if (mode == _LK_LOCK || mode == _LK_RLCK) { int nretry = 10; ret = 1; /* just to satisfy gcc */ @@ -874,7 +930,7 @@ int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes) Sleep(1); } } - else if (mode == MSVCRT__LK_UNLCK) + else if (mode == _LK_UNLCK) ret = UnlockFile(hand, cur_locn, 0L, nbytes, 0L); else ret = LockFile(hand, cur_locn, 0L, nbytes, 0L); @@ -885,25 +941,25 @@ int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes) /********************************************************************* * fseek (MSVCRT.@) */ -int CDECL MSVCRT_fseek(MSVCRT_FILE* file, long offset, int whence) +int CDECL fseek(FILE* file, long offset, int whence) { /* Flush output if needed */ - if(file->_flag & MSVCRT__IOWRT) - msvcrt_flush_buffer(file); + if(file->_flag & _IOWRT) + flush_buffer(file); - if(whence == SEEK_CUR && file->_flag & MSVCRT__IOREAD ) { + if(whence == SEEK_CUR && file->_flag & _IOREAD ) { offset -= file->_cnt; } /* Discard buffered input */ file->_cnt = 0; file->_ptr = file->_base; /* Reset direction of i/o */ - if(file->_flag & MSVCRT__IORW) { - file->_flag &= ~(MSVCRT__IOREAD|MSVCRT__IOWRT); + if(file->_flag & _IORW) { + file->_flag &= ~(_IOREAD|_IOWRT); } /* Clear end of file flag */ - file->_flag &= ~MSVCRT__IOEOF; - return (MSVCRT__lseek(file->_file,offset,whence) == -1)?-1:0; + file->_flag &= ~_IOEOF; + return (_lseek(file->_file,offset,whence) == -1)?-1:0; } /********************************************************************* @@ -919,22 +975,22 @@ int CDECL _chsize(int fd, long size) LOCK_FILES(); - handle = msvcrt_fdtoh(fd); + handle = fdtoh(fd); if (handle != INVALID_HANDLE_VALUE) { /* save the current file pointer */ - cur = MSVCRT__lseek(fd, 0, SEEK_CUR); + cur = _lseek(fd, 0, SEEK_CUR); if (cur >= 0) { - pos = MSVCRT__lseek(fd, size, SEEK_SET); + pos = _lseek(fd, size, SEEK_SET); if (pos >= 0) { ret = SetEndOfFile(handle); - if (!ret) msvcrt_set_errno(GetLastError()); + if (!ret) __set_errno(GetLastError()); } /* restore the file pointer */ - MSVCRT__lseek(fd, cur, SEEK_SET); + _lseek(fd, cur, SEEK_SET); } } @@ -945,39 +1001,39 @@ int CDECL _chsize(int fd, long size) /********************************************************************* * clearerr (MSVCRT.@) */ -void CDECL MSVCRT_clearerr(MSVCRT_FILE* file) +void CDECL clearerr(FILE* file) { TRACE(":file (%p) fd (%d)\n",file,file->_file); - file->_flag &= ~(MSVCRT__IOERR | MSVCRT__IOEOF); + file->_flag &= ~(_IOERR | _IOEOF); } /********************************************************************* * rewind (MSVCRT.@) */ -void CDECL MSVCRT_rewind(MSVCRT_FILE* file) +void CDECL rewind(FILE* file) { TRACE(":file (%p) fd (%d)\n",file,file->_file); - MSVCRT_fseek(file, 0L, SEEK_SET); - MSVCRT_clearerr(file); + fseek(file, 0L, SEEK_SET); + clearerr(file); } -static int msvcrt_get_flags(const char* mode, int *open_flags, int* stream_flags) +static int get_flags(const char* mode, int *open_flags, int* stream_flags) { int plus = strchr(mode, '+') != NULL; switch(*mode++) { case 'R': case 'r': - *open_flags = plus ? MSVCRT__O_RDWR : MSVCRT__O_RDONLY; - *stream_flags = plus ? MSVCRT__IORW : MSVCRT__IOREAD; + *open_flags = plus ? _O_RDWR : _O_RDONLY; + *stream_flags = plus ? _IORW : _IOREAD; break; case 'W': case 'w': - *open_flags = MSVCRT__O_CREAT | MSVCRT__O_TRUNC | (plus ? MSVCRT__O_RDWR : MSVCRT__O_WRONLY); - *stream_flags = plus ? MSVCRT__IORW : MSVCRT__IOWRT; + *open_flags = _O_CREAT | _O_TRUNC | (plus ? _O_RDWR : _O_WRONLY); + *stream_flags = plus ? _IORW : _IOWRT; break; case 'A': case 'a': - *open_flags = MSVCRT__O_CREAT | MSVCRT__O_APPEND | (plus ? MSVCRT__O_RDWR : MSVCRT__O_WRONLY); - *stream_flags = plus ? MSVCRT__IORW : MSVCRT__IOWRT; + *open_flags = _O_CREAT | _O_APPEND | (plus ? _O_RDWR : _O_WRONLY); + *stream_flags = plus ? _IORW : _IOWRT; break; default: return -1; @@ -987,12 +1043,12 @@ static int msvcrt_get_flags(const char* mode, int *open_flags, int* stream_flags switch (*mode++) { case 'B': case 'b': - *open_flags |= MSVCRT__O_BINARY; - *open_flags &= ~MSVCRT__O_TEXT; + *open_flags |= _O_BINARY; + *open_flags &= ~_O_TEXT; break; case 'T': case 't': - *open_flags |= MSVCRT__O_TEXT; - *open_flags &= ~MSVCRT__O_BINARY; + *open_flags |= _O_TEXT; + *open_flags &= ~_O_BINARY; break; case '+': break; @@ -1005,17 +1061,17 @@ static int msvcrt_get_flags(const char* mode, int *open_flags, int* stream_flags /********************************************************************* * _fdopen (MSVCRT.@) */ -MSVCRT_FILE* CDECL MSVCRT__fdopen(int fd, const char *mode) +FILE* CDECL _fdopen(int fd, const char *mode) { int open_flags, stream_flags; - MSVCRT_FILE* file; + FILE* file; - if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) return NULL; + if (get_flags(mode, &open_flags, &stream_flags) == -1) return NULL; LOCK_FILES(); - if (!(file = msvcrt_alloc_fp())) + if (!(file = alloc_fp())) file = NULL; - else if (msvcrt_init_fp(file, fd, stream_flags) == -1) + else if (init_fp(file, fd, stream_flags) == -1) { file->_flag = 0; file = NULL; @@ -1029,21 +1085,21 @@ MSVCRT_FILE* CDECL MSVCRT__fdopen(int fd, const char *mode) /********************************************************************* * _wfdopen (MSVCRT.@) */ -MSVCRT_FILE* CDECL MSVCRT__wfdopen(int fd, const MSVCRT_wchar_t *mode) +FILE* CDECL _wfdopen(int fd, const wchar_t *mode) { unsigned mlen = strlenW(mode); - char *modea = MSVCRT_calloc(mlen + 1, 1); - MSVCRT_FILE* file = NULL; + char *modea = calloc(mlen + 1, 1); + FILE* file = NULL; int open_flags, stream_flags; if (modea && WideCharToMultiByte(CP_ACP,0,mode,mlen,modea,mlen,NULL,NULL)) { - if (msvcrt_get_flags(modea, &open_flags, &stream_flags) == -1) return NULL; + if (get_flags(modea, &open_flags, &stream_flags) == -1) return NULL; LOCK_FILES(); - if (!(file = msvcrt_alloc_fp())) + if (!(file = alloc_fp())) file = NULL; - else if (msvcrt_init_fp(file, fd, stream_flags) == -1) + else if (init_fp(file, fd, stream_flags) == -1) { file->_flag = 0; file = NULL; @@ -1051,7 +1107,7 @@ MSVCRT_FILE* CDECL MSVCRT__wfdopen(int fd, const MSVCRT_wchar_t *mode) else { if (file) - MSVCRT_rewind(file); /* FIXME: is this needed ??? */ + rewind(file); /* FIXME: is this needed ??? */ TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd,debugstr_w(mode),file); } UNLOCK_FILES(); @@ -1062,16 +1118,16 @@ MSVCRT_FILE* CDECL MSVCRT__wfdopen(int fd, const MSVCRT_wchar_t *mode) /********************************************************************* * _filelength (MSVCRT.@) */ -LONG CDECL MSVCRT__filelength(int fd) +LONG CDECL _filelength(int fd) { - LONG curPos = MSVCRT__lseek(fd, 0, SEEK_CUR); + LONG curPos = _lseek(fd, 0, SEEK_CUR); if (curPos != -1) { - LONG endPos = MSVCRT__lseek(fd, 0, SEEK_END); + LONG endPos = _lseek(fd, 0, SEEK_END); if (endPos != -1) { if (endPos != curPos) - MSVCRT__lseek(fd, curPos, SEEK_SET); + _lseek(fd, curPos, SEEK_SET); return endPos; } } @@ -1081,16 +1137,16 @@ LONG CDECL MSVCRT__filelength(int fd) /********************************************************************* * _filelengthi64 (MSVCRT.@) */ -__int64 CDECL MSVCRT__filelengthi64(int fd) +__int64 CDECL _filelengthi64(int fd) { - __int64 curPos = MSVCRT__lseeki64(fd, 0, SEEK_CUR); + __int64 curPos = _lseeki64(fd, 0, SEEK_CUR); if (curPos != -1) { - __int64 endPos = MSVCRT__lseeki64(fd, 0, SEEK_END); + __int64 endPos = _lseeki64(fd, 0, SEEK_END); if (endPos != -1) { if (endPos != curPos) - MSVCRT__lseeki64(fd, curPos, SEEK_SET); + _lseeki64(fd, curPos, SEEK_SET); return endPos; } } @@ -1100,7 +1156,7 @@ __int64 CDECL MSVCRT__filelengthi64(int fd) /********************************************************************* * _fileno (MSVCRT.@) */ -int CDECL MSVCRT__fileno(MSVCRT_FILE* file) +int CDECL _fileno(FILE* file) { TRACE(":FILE* (%p) fd (%d)\n",file,file->_file); return file->_file; @@ -1109,12 +1165,12 @@ int CDECL MSVCRT__fileno(MSVCRT_FILE* file) /********************************************************************* * _fstat64 (MSVCRT.@) */ -int CDECL MSVCRT__fstat64(int fd, struct MSVCRT__stat64* buf) +int CDECL _fstat64(int fd, struct __stat64* buf) { DWORD dw; DWORD type; BY_HANDLE_FILE_INFORMATION hfi; - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); TRACE(":fd (%d) stat (%p)\n",fd,buf); if (hand == INVALID_HANDLE_VALUE) @@ -1123,12 +1179,12 @@ int CDECL MSVCRT__fstat64(int fd, struct MSVCRT__stat64* buf) if (!buf) { WARN(":failed-NULL buf\n"); - msvcrt_set_errno(ERROR_INVALID_PARAMETER); + __set_errno(ERROR_INVALID_PARAMETER); return -1; } memset(&hfi, 0, sizeof(hfi)); - memset(buf, 0, sizeof(struct MSVCRT__stat64)); + memset(buf, 0, sizeof(struct __stat64)); type = GetFileType(hand); if (type == FILE_TYPE_PIPE) { @@ -1147,7 +1203,7 @@ int CDECL MSVCRT__fstat64(int fd, struct MSVCRT__stat64* buf) if (!GetFileInformationByHandle(hand, &hfi)) { WARN(":failed-last error (%d)\n",GetLastError()); - msvcrt_set_errno(ERROR_INVALID_PARAMETER); + __set_errno(ERROR_INVALID_PARAMETER); return -1; } buf->st_mode = S_IFREG | S_IREAD; @@ -1168,42 +1224,42 @@ int CDECL MSVCRT__fstat64(int fd, struct MSVCRT__stat64* buf) /********************************************************************* * _fstati64 (MSVCRT.@) */ -int CDECL MSVCRT__fstati64(int fd, struct MSVCRT__stati64* buf) +int CDECL _fstati64(int fd, struct _stati64* buf) { int ret; - struct MSVCRT__stat64 buf64; + struct __stat64 buf64; - ret = MSVCRT__fstat64(fd, &buf64); + ret = _fstat64(fd, &buf64); if (!ret) - msvcrt_stat64_to_stati64(&buf64, buf); + stat64_to_stati64(&buf64, buf); return ret; } /********************************************************************* * _fstat (MSVCRT.@) */ -int CDECL MSVCRT__fstat(int fd, struct MSVCRT__stat* buf) +int CDECL _fstat(int fd, struct _stat* buf) { int ret; - struct MSVCRT__stat64 buf64; + struct __stat64 buf64; - ret = MSVCRT__fstat64(fd, &buf64); + ret = _fstat64(fd, &buf64); if (!ret) - msvcrt_stat64_to_stat(&buf64, buf); + stat64_to_stat(&buf64, buf); return ret; } /********************************************************************* * _futime (MSVCRT.@) */ -int CDECL _futime(int fd, struct MSVCRT__utimbuf *t) +int CDECL _futime(int fd, struct _utimbuf *t) { - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); FILETIME at, wt; if (!t) { - MSVCRT_time_t currTime; - MSVCRT_time(&currTime); + time_t currTime; + time(&currTime); RtlSecondsSince1970ToTime(currTime, (LARGE_INTEGER *)&at); wt = at; } @@ -1218,7 +1274,7 @@ int CDECL _futime(int fd, struct MSVCRT__utimbuf *t) if (!SetFileTime(hand, NULL, &at, &wt)) { - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1 ; } return 0; @@ -1229,7 +1285,7 @@ int CDECL _futime(int fd, struct MSVCRT__utimbuf *t) */ long CDECL _get_osfhandle(int fd) { - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); TRACE(":fd (%d) handle (%p)\n",fd,hand); return (long)hand; @@ -1240,7 +1296,7 @@ long CDECL _get_osfhandle(int fd) */ int CDECL _isatty(int fd) { - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); TRACE(":fd (%d) handle (%p)\n",fd,hand); if (hand == INVALID_HANDLE_VALUE) @@ -1286,12 +1342,12 @@ char * CDECL _mktemp(char *pattern) /********************************************************************* * _wmktemp (MSVCRT.@) */ -MSVCRT_wchar_t * CDECL _wmktemp(MSVCRT_wchar_t *pattern) +wchar_t * CDECL _wmktemp(wchar_t *pattern) { int numX = 0; - MSVCRT_wchar_t *retVal = pattern; + wchar_t *retVal = pattern; int id; - MSVCRT_wchar_t letter = 'a'; + wchar_t letter = 'a'; while(*pattern) numX = (*pattern++ == 'X')? numX + 1 : 0; @@ -1317,24 +1373,24 @@ MSVCRT_wchar_t * CDECL _wmktemp(MSVCRT_wchar_t *pattern) return NULL; } -static unsigned split_oflags(unsigned oflags) +/*static */unsigned split_oflags(unsigned oflags) { int wxflags = 0; unsigned unsupp; /* until we support everything */ - if (oflags & MSVCRT__O_APPEND) wxflags |= WX_APPEND; - if (oflags & MSVCRT__O_BINARY) {/* Nothing to do */} - else if (oflags & MSVCRT__O_TEXT) wxflags |= WX_TEXT; - else if (*__p__fmode() & MSVCRT__O_BINARY) {/* Nothing to do */} + if (oflags & _O_APPEND) wxflags |= WX_APPEND; + if (oflags & _O_BINARY) {/* Nothing to do */} + else if (oflags & _O_TEXT) wxflags |= WX_TEXT; + else if (*__p__fmode() & _O_BINARY) {/* Nothing to do */} else wxflags |= WX_TEXT; /* default to TEXT*/ - if (oflags & MSVCRT__O_NOINHERIT) wxflags |= WX_DONTINHERIT; + if (oflags & _O_NOINHERIT) wxflags |= WX_DONTINHERIT; if ((unsupp = oflags & ~( - MSVCRT__O_BINARY|MSVCRT__O_TEXT|MSVCRT__O_APPEND| - MSVCRT__O_TRUNC|MSVCRT__O_EXCL|MSVCRT__O_CREAT| - MSVCRT__O_RDWR|MSVCRT__O_WRONLY|MSVCRT__O_TEMPORARY| - MSVCRT__O_NOINHERIT| - MSVCRT__O_SEQUENTIAL|MSVCRT__O_RANDOM|MSVCRT__O_SHORT_LIVED + _O_BINARY|_O_TEXT|_O_APPEND| + _O_TRUNC|_O_EXCL|_O_CREAT| + _O_RDWR|_O_WRONLY|_O_TEMPORARY| + _O_NOINHERIT| + _O_SEQUENTIAL|_O_RANDOM|_O_SHORT_LIVED ))) ERR(":unsupported oflags 0x%04x\n",unsupp); @@ -1344,7 +1400,7 @@ static unsigned split_oflags(unsigned oflags) /********************************************************************* * _pipe (MSVCRT.@) */ -int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode) +int CDECL _pipe(int *pfds, unsigned int psize, int textmode) { int ret = -1; SECURITY_ATTRIBUTES sa; @@ -1352,12 +1408,12 @@ int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode) if (!pfds) { - *MSVCRT__errno() = MSVCRT_EINVAL; + *_errno() = EINVAL; return -1; } sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.bInheritHandle = !(textmode & MSVCRT__O_NOINHERIT); + sa.bInheritHandle = !(textmode & _O_NOINHERIT); sa.lpSecurityDescriptor = NULL; if (CreatePipe(&readHandle, &writeHandle, &sa, psize)) { @@ -1365,11 +1421,11 @@ int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode) int fd; LOCK_FILES(); - fd = msvcrt_alloc_fd(readHandle, wxflags); + fd = alloc_fd(readHandle, wxflags); if (fd != -1) { pfds[0] = fd; - fd = msvcrt_alloc_fd(writeHandle, wxflags); + fd = alloc_fd(writeHandle, wxflags); if (fd != -1) { pfds[1] = fd; @@ -1377,21 +1433,21 @@ int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode) } else { - MSVCRT__close(pfds[0]); + _close(pfds[0]); CloseHandle(writeHandle); - *MSVCRT__errno() = MSVCRT_EMFILE; + *_errno() = EMFILE; } } else { CloseHandle(readHandle); CloseHandle(writeHandle); - *MSVCRT__errno() = MSVCRT_EMFILE; + *_errno() = EMFILE; } UNLOCK_FILES(); } else - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return ret; } @@ -1399,7 +1455,7 @@ int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode) /********************************************************************* * _sopen (MSVCRT.@) */ -int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... ) +int CDECL _sopen( const char *path, int oflags, int shflags, ... ) { va_list ap; int pmode; @@ -1414,34 +1470,34 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... ) path, oflags, shflags); wxflag = split_oflags(oflags); - switch (oflags & (MSVCRT__O_RDONLY | MSVCRT__O_WRONLY | MSVCRT__O_RDWR)) + switch (oflags & (_O_RDONLY | _O_WRONLY | _O_RDWR)) { - case MSVCRT__O_RDONLY: access |= GENERIC_READ; break; - case MSVCRT__O_WRONLY: access |= GENERIC_WRITE; break; - case MSVCRT__O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break; + case _O_RDONLY: access |= GENERIC_READ; break; + case _O_WRONLY: access |= GENERIC_WRITE; break; + case _O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break; } - if (oflags & MSVCRT__O_CREAT) + if (oflags & _O_CREAT) { va_start(ap, shflags); pmode = va_arg(ap, int); va_end(ap); - if(pmode & ~(MSVCRT__S_IREAD | MSVCRT__S_IWRITE)) + if(pmode & ~(_S_IREAD | _S_IWRITE)) FIXME(": pmode 0x%04x ignored\n", pmode); else WARN(": pmode 0x%04x ignored\n", pmode); - if (oflags & MSVCRT__O_EXCL) + if (oflags & _O_EXCL) creation = CREATE_NEW; - else if (oflags & MSVCRT__O_TRUNC) + else if (oflags & _O_TRUNC) creation = CREATE_ALWAYS; else creation = OPEN_ALWAYS; } - else /* no MSVCRT__O_CREAT */ + else /* no _O_CREAT */ { - if (oflags & MSVCRT__O_TRUNC) + if (oflags & _O_TRUNC) creation = TRUNCATE_EXISTING; else creation = OPEN_EXISTING; @@ -1449,16 +1505,16 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... ) switch( shflags ) { - case MSVCRT__SH_DENYRW: + case _SH_DENYRW: sharing = 0L; break; - case MSVCRT__SH_DENYWR: + case _SH_DENYWR: sharing = FILE_SHARE_READ; break; - case MSVCRT__SH_DENYRD: + case _SH_DENYRD: sharing = FILE_SHARE_WRITE; break; - case MSVCRT__SH_DENYNO: + case _SH_DENYNO: sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break; default: @@ -1467,7 +1523,7 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... ) } attrib = FILE_ATTRIBUTE_NORMAL; - if (oflags & MSVCRT__O_TEMPORARY) + if (oflags & _O_TEMPORARY) { attrib |= FILE_FLAG_DELETE_ON_CLOSE; access |= DELETE; @@ -1476,17 +1532,17 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... ) sa.nLength = sizeof( SECURITY_ATTRIBUTES ); sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = (oflags & MSVCRT__O_NOINHERIT) ? FALSE : TRUE; + sa.bInheritHandle = (oflags & _O_NOINHERIT) ? FALSE : TRUE; hand = CreateFileA(path, access, sharing, &sa, creation, attrib, 0); if (hand == INVALID_HANDLE_VALUE) { WARN(":failed-last error (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } - fd = msvcrt_alloc_fd(hand, wxflag); + fd = alloc_fd(hand, wxflag); TRACE(":fd (%d) handle (%p)\n",fd, hand); return fd; @@ -1495,10 +1551,10 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... ) /********************************************************************* * _wsopen (MSVCRT.@) */ -int CDECL MSVCRT__wsopen( const MSVCRT_wchar_t* path, int oflags, int shflags, ... ) +int CDECL _wsopen( const wchar_t* path, int oflags, int shflags, ... ) { const unsigned int len = strlenW(path); - char *patha = MSVCRT_calloc(len + 1,1); + char *patha = calloc(len + 1,1); va_list ap; int pmode; @@ -1508,41 +1564,41 @@ int CDECL MSVCRT__wsopen( const MSVCRT_wchar_t* path, int oflags, int shflags, . if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL)) { - int retval = MSVCRT__sopen(patha,oflags,shflags,pmode); - MSVCRT_free(patha); + int retval = _sopen(patha,oflags,shflags,pmode); + free(patha); return retval; } - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } /********************************************************************* * _open (MSVCRT.@) */ -int CDECL MSVCRT__open( const char *path, int flags, ... ) +int CDECL _open( const char *path, int flags, ... ) { va_list ap; - if (flags & MSVCRT__O_CREAT) + if (flags & _O_CREAT) { int pmode; va_start(ap, flags); pmode = va_arg(ap, int); va_end(ap); - return MSVCRT__sopen( path, flags, MSVCRT__SH_DENYNO, pmode ); + return _sopen( path, flags, _SH_DENYNO, pmode ); } else - return MSVCRT__sopen( path, flags, MSVCRT__SH_DENYNO); + return _sopen( path, flags, _SH_DENYNO); } /********************************************************************* * _wopen (MSVCRT.@) */ -int CDECL _wopen(const MSVCRT_wchar_t *path,int flags,...) +int CDECL _wopen(const wchar_t *path,int flags,...) { const unsigned int len = strlenW(path); - char *patha = MSVCRT_calloc(len + 1,1); + char *patha = calloc(len + 1,1); va_list ap; int pmode; @@ -1552,30 +1608,30 @@ int CDECL _wopen(const MSVCRT_wchar_t *path,int flags,...) if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL)) { - int retval = MSVCRT__open(patha,flags,pmode); - MSVCRT_free(patha); + int retval = _open(patha,flags,pmode); + free(patha); return retval; } - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return -1; } /********************************************************************* * _creat (MSVCRT.@) */ -int CDECL MSVCRT__creat(const char *path, int flags) +int CDECL _creat(const char *path, int flags) { - int usedFlags = (flags & MSVCRT__O_TEXT)| MSVCRT__O_CREAT| MSVCRT__O_WRONLY| MSVCRT__O_TRUNC; - return MSVCRT__open(path, usedFlags); + int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC; + return _open(path, usedFlags); } /********************************************************************* * _wcreat (MSVCRT.@) */ -int CDECL _wcreat(const MSVCRT_wchar_t *path, int flags) +int CDECL _wcreat(const wchar_t *path, int flags) { - int usedFlags = (flags & MSVCRT__O_TEXT)| MSVCRT__O_CREAT| MSVCRT__O_WRONLY| MSVCRT__O_TRUNC; + int usedFlags = (flags & _O_TEXT)| _O_CREAT| _O_WRONLY| _O_TRUNC; return _wopen(path, usedFlags); } @@ -1586,16 +1642,16 @@ int CDECL _open_osfhandle(long handle, int oflags) { int fd; - /* MSVCRT__O_RDONLY (0) always matches, so set the read flag + /* _O_RDONLY (0) always matches, so set the read flag * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the - * file, so set the write flag. It also only sets MSVCRT__O_TEXT if it wants - * text - it never sets MSVCRT__O_BINARY. + * file, so set the write flag. It also only sets _O_TEXT if it wants + * text - it never sets _O_BINARY. */ /* don't let split_oflags() decide the mode if no mode is passed */ - if (!(oflags & (MSVCRT__O_BINARY | MSVCRT__O_TEXT))) - oflags |= MSVCRT__O_BINARY; + if (!(oflags & (_O_BINARY | _O_TEXT))) + oflags |= _O_BINARY; - fd = msvcrt_alloc_fd((HANDLE)handle, split_oflags(oflags)); + fd = alloc_fd((HANDLE)handle, split_oflags(oflags)); TRACE(":handle (%ld) fd (%d) flags 0x%08x\n", handle, fd, oflags); return fd; } @@ -1608,10 +1664,10 @@ int CDECL _rmtmp(void) int num_removed = 0, i; LOCK_FILES(); - for (i = 3; i < MSVCRT_stream_idx; i++) - if (MSVCRT_fstreams[i] && MSVCRT_fstreams[i]->_tmpfname) + for (i = 3; i < stream_idx; i++) + if (fstreams[i] && fstreams[i]->_tmpfname) { - MSVCRT_fclose(MSVCRT_fstreams[i]); + fclose(fstreams[i]); num_removed++; } UNLOCK_FILES(); @@ -1649,10 +1705,10 @@ static int read_i(int fd, void *buf, unsigned int count) { DWORD num_read; char *bufstart = buf; - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); - if (MSVCRT_fdesc[fd].wxflag & WX_READEOF) { - MSVCRT_fdesc[fd].wxflag |= WX_ATEOF; + if (fdesc[fd].wxflag & WX_READEOF) { + fdesc[fd].wxflag |= WX_ATEOF; TRACE("already at EOF, returning 0\n"); return 0; } @@ -1667,7 +1723,7 @@ static int read_i(int fd, void *buf, unsigned int count) */ if (ReadFile(hand, bufstart, count, &num_read, NULL)) { - if (MSVCRT_fdesc[fd].wxflag & WX_TEXT) + if (fdesc[fd].wxflag & WX_TEXT) { int i; /* in text mode, a ctrl-z signals EOF */ @@ -1676,7 +1732,7 @@ static int read_i(int fd, void *buf, unsigned int count) if (bufstart[i] == 0x1a) { num_read = i; - MSVCRT_fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF); + fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF); TRACE(":^Z EOF %s\n",debugstr_an(buf,num_read)); break; } @@ -1684,7 +1740,7 @@ static int read_i(int fd, void *buf, unsigned int count) } if (count != 0 && num_read == 0) { - MSVCRT_fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF); + fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF); TRACE(":EOF %s\n",debugstr_an(buf,num_read)); } } @@ -1693,7 +1749,7 @@ static int read_i(int fd, void *buf, unsigned int count) if (GetLastError() == ERROR_BROKEN_PIPE) { TRACE(":end-of-pipe\n"); - MSVCRT_fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF); + fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF); return 0; } else @@ -1711,11 +1767,11 @@ static int read_i(int fd, void *buf, unsigned int count) /********************************************************************* * _read (MSVCRT.@) */ -int CDECL MSVCRT__read(int fd, void *buf, unsigned int count) +int CDECL _read(int fd, void *buf, unsigned int count) { int num_read; num_read = read_i(fd, buf, count); - if (num_read>0 && MSVCRT_fdesc[fd].wxflag & WX_TEXT) + if (num_read>0 && fdesc[fd].wxflag & WX_TEXT) { num_read -= remove_cr(buf,num_read); } @@ -1727,20 +1783,20 @@ int CDECL MSVCRT__read(int fd, void *buf, unsigned int count) */ int CDECL _setmode(int fd,int mode) { - int ret = MSVCRT_fdesc[fd].wxflag & WX_TEXT ? MSVCRT__O_TEXT : MSVCRT__O_BINARY; - if (mode & (~(MSVCRT__O_TEXT|MSVCRT__O_BINARY))) + int ret = fdesc[fd].wxflag & WX_TEXT ? _O_TEXT : _O_BINARY; + if (mode & (~(_O_TEXT|_O_BINARY))) FIXME("fd (%d) mode (0x%08x) unknown\n",fd,mode); - if ((mode & MSVCRT__O_TEXT) == MSVCRT__O_TEXT) - MSVCRT_fdesc[fd].wxflag |= WX_TEXT; + if ((mode & _O_TEXT) == _O_TEXT) + fdesc[fd].wxflag |= WX_TEXT; else - MSVCRT_fdesc[fd].wxflag &= ~WX_TEXT; + fdesc[fd].wxflag &= ~WX_TEXT; return ret; } /********************************************************************* * _stat64 (MSVCRT.@) */ -int CDECL MSVCRT__stat64(const char* path, struct MSVCRT__stat64 * buf) +int CDECL _stat64(const char* path, struct __stat64 * buf) { DWORD dw; WIN32_FILE_ATTRIBUTE_DATA hfi; @@ -1752,11 +1808,11 @@ int CDECL MSVCRT__stat64(const char* path, struct MSVCRT__stat64 * buf) if (!GetFileAttributesExA(path, GetFileExInfoStandard, &hfi)) { TRACE("failed (%d)\n",GetLastError()); - msvcrt_set_errno(ERROR_FILE_NOT_FOUND); + __set_errno(ERROR_FILE_NOT_FOUND); return -1; } - memset(buf,0,sizeof(struct MSVCRT__stat64)); + memset(buf,0,sizeof(struct __stat64)); /* FIXME: rdev isn't drive num, despite what the docs say-what is it? Bon 011120: This FIXME seems incorrect @@ -1773,10 +1829,10 @@ int CDECL MSVCRT__stat64(const char* path, struct MSVCRT__stat64 * buf) /* Dir, or regular file? */ if ((hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (path[plen-1] == '\\')) - mode |= (MSVCRT__S_IFDIR | ALL_S_IEXEC); + mode |= (_S_IFDIR | ALL_S_IEXEC); else { - mode |= MSVCRT__S_IFREG; + mode |= _S_IFREG; /* executable? */ if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */ { @@ -1806,34 +1862,34 @@ int CDECL MSVCRT__stat64(const char* path, struct MSVCRT__stat64 * buf) /********************************************************************* * _stati64 (MSVCRT.@) */ -int CDECL MSVCRT__stati64(const char* path, struct MSVCRT__stati64 * buf) +int CDECL _stati64(const char* path, struct _stati64 * buf) { int ret; - struct MSVCRT__stat64 buf64; + struct __stat64 buf64; - ret = MSVCRT__stat64(path, &buf64); + ret = _stat64(path, &buf64); if (!ret) - msvcrt_stat64_to_stati64(&buf64, buf); + stat64_to_stati64(&buf64, buf); return ret; } /********************************************************************* * _stat (MSVCRT.@) */ -int CDECL MSVCRT__stat(const char* path, struct MSVCRT__stat * buf) +int CDECL _stat(const char* path, struct _stat * buf) { int ret; - struct MSVCRT__stat64 buf64; + struct __stat64 buf64; - ret = MSVCRT__stat64( path, &buf64); + ret = _stat64( path, &buf64); if (!ret) - msvcrt_stat64_to_stat(&buf64, buf); + stat64_to_stat(&buf64, buf); return ret; } /********************************************************************* * _wstat64 (MSVCRT.@) */ -int CDECL MSVCRT__wstat64(const MSVCRT_wchar_t* path, struct MSVCRT__stat64 * buf) +int CDECL _wstat64(const wchar_t* path, struct __stat64 * buf) { DWORD dw; WIN32_FILE_ATTRIBUTE_DATA hfi; @@ -1845,14 +1901,14 @@ int CDECL MSVCRT__wstat64(const MSVCRT_wchar_t* path, struct MSVCRT__stat64 * bu if (!GetFileAttributesExW(path, GetFileExInfoStandard, &hfi)) { TRACE("failed (%d)\n",GetLastError()); - msvcrt_set_errno(ERROR_FILE_NOT_FOUND); + __set_errno(ERROR_FILE_NOT_FOUND); return -1; } - memset(buf,0,sizeof(struct MSVCRT__stat64)); + memset(buf,0,sizeof(struct __stat64)); /* FIXME: rdev isn't drive num, despite what the docs says-what is it? */ - if (MSVCRT_iswalpha(*path)) + if (iswalpha(*path)) buf->st_dev = buf->st_rdev = toupperW(*path - 'A'); /* drive num */ else buf->st_dev = buf->st_rdev = _getdrive() - 1; @@ -1862,10 +1918,10 @@ int CDECL MSVCRT__wstat64(const MSVCRT_wchar_t* path, struct MSVCRT__stat64 * bu /* Dir, or regular file? */ if ((hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (path[plen-1] == '\\')) - mode |= (MSVCRT__S_IFDIR | ALL_S_IEXEC); + mode |= (_S_IFDIR | ALL_S_IEXEC); else { - mode |= MSVCRT__S_IFREG; + mode |= _S_IFREG; /* executable? */ if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */ { @@ -1895,27 +1951,27 @@ int CDECL MSVCRT__wstat64(const MSVCRT_wchar_t* path, struct MSVCRT__stat64 * bu /********************************************************************* * _wstati64 (MSVCRT.@) */ -int CDECL MSVCRT__wstati64(const MSVCRT_wchar_t* path, struct MSVCRT__stati64 * buf) +int CDECL _wstati64(const wchar_t* path, struct _stati64 * buf) { int ret; - struct MSVCRT__stat64 buf64; + struct __stat64 buf64; - ret = MSVCRT__wstat64(path, &buf64); + ret = _wstat64(path, &buf64); if (!ret) - msvcrt_stat64_to_stati64(&buf64, buf); + stat64_to_stati64(&buf64, buf); return ret; } /********************************************************************* * _wstat (MSVCRT.@) */ -int CDECL MSVCRT__wstat(const MSVCRT_wchar_t* path, struct MSVCRT__stat * buf) +int CDECL _wstat(const wchar_t* path, struct _stat * buf) { int ret; - struct MSVCRT__stat64 buf64; + struct __stat64 buf64; - ret = MSVCRT__wstat64( path, &buf64 ); - if (!ret) msvcrt_stat64_to_stat(&buf64, buf); + ret = _wstat64( path, &buf64 ); + if (!ret) stat64_to_stat(&buf64, buf); return ret; } @@ -1924,7 +1980,7 @@ int CDECL MSVCRT__wstat(const MSVCRT_wchar_t* path, struct MSVCRT__stat * buf) */ long CDECL _tell(int fd) { - return MSVCRT__lseek(fd, 0, SEEK_CUR); + return _lseek(fd, 0, SEEK_CUR); } /********************************************************************* @@ -1932,7 +1988,7 @@ long CDECL _tell(int fd) */ __int64 CDECL _telli64(int fd) { - return MSVCRT__lseeki64(fd, 0, SEEK_CUR); + return _lseeki64(fd, 0, SEEK_CUR); } /********************************************************************* @@ -1941,7 +1997,7 @@ __int64 CDECL _telli64(int fd) char * CDECL _tempnam(const char *dir, const char *prefix) { char tmpbuf[MAX_PATH]; - const char *tmp_dir = MSVCRT_getenv("TMP"); + const char *tmp_dir = getenv("TMP"); if (tmp_dir) dir = tmp_dir; @@ -1959,9 +2015,9 @@ char * CDECL _tempnam(const char *dir, const char *prefix) /********************************************************************* * _wtempnam (MSVCRT.@) */ -MSVCRT_wchar_t * CDECL _wtempnam(const MSVCRT_wchar_t *dir, const MSVCRT_wchar_t *prefix) +wchar_t * CDECL _wtempnam(const wchar_t *dir, const wchar_t *prefix) { - MSVCRT_wchar_t tmpbuf[MAX_PATH]; + wchar_t tmpbuf[MAX_PATH]; TRACE("dir (%s) prefix (%s)\n",debugstr_w(dir),debugstr_w(prefix)); if (GetTempFileNameW(dir,prefix,0,tmpbuf)) @@ -1977,9 +2033,9 @@ MSVCRT_wchar_t * CDECL _wtempnam(const MSVCRT_wchar_t *dir, const MSVCRT_wchar_t /********************************************************************* * _umask (MSVCRT.@) */ -int CDECL MSVCRT__umask(int umask) +int CDECL _umask(int umask) { - int old_umask = MSVCRT_umask; + int old_umask = umask; TRACE("(%d)\n",umask); MSVCRT_umask = umask; return old_umask; @@ -1988,14 +2044,14 @@ int CDECL MSVCRT__umask(int umask) /********************************************************************* * _utime (MSVCRT.@) */ -int CDECL _utime(const char* path, struct MSVCRT__utimbuf *t) +int CDECL _utime(const char* path, struct _utimbuf *t) { - int fd = MSVCRT__open(path, MSVCRT__O_WRONLY | MSVCRT__O_BINARY); + int fd = _open(path, _O_WRONLY | _O_BINARY); if (fd > 0) { int retVal = _futime(fd, t); - MSVCRT__close(fd); + _close(fd); return retVal; } return -1; @@ -2004,14 +2060,14 @@ int CDECL _utime(const char* path, struct MSVCRT__utimbuf *t) /********************************************************************* * _wutime (MSVCRT.@) */ -int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT__utimbuf *t) +int CDECL _wutime(const wchar_t* path, struct _utimbuf *t) { - int fd = _wopen(path, MSVCRT__O_WRONLY | MSVCRT__O_BINARY); + int fd = _wopen(path, _O_WRONLY | _O_BINARY); if (fd > 0) { int retVal = _futime(fd, t); - MSVCRT__close(fd); + _close(fd); return retVal; } return -1; @@ -2020,10 +2076,10 @@ int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT__utimbuf *t) /********************************************************************* * _write (MSVCRT.@) */ -int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count) +int CDECL _write(int fd, const void* buf, unsigned int count) { DWORD num_written; - HANDLE hand = msvcrt_fdtoh(fd); + HANDLE hand = fdtoh(fd); /* Don't trace small writes, it gets *very* annoying */ #if 0 @@ -2032,22 +2088,22 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count) #endif if (hand == INVALID_HANDLE_VALUE) { - *MSVCRT__errno() = MSVCRT_EBADF; + *_errno() = EBADF; return -1; } /* If appending, go to EOF */ - if (MSVCRT_fdesc[fd].wxflag & WX_APPEND) - MSVCRT__lseek(fd, 0, FILE_END); + if (fdesc[fd].wxflag & WX_APPEND) + _lseek(fd, 0, FILE_END); - if (!(MSVCRT_fdesc[fd].wxflag & WX_TEXT)) + if (!(fdesc[fd].wxflag & WX_TEXT)) { if (WriteFile(hand, buf, count, &num_written, NULL) && (num_written == count)) return num_written; TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd, hand, GetLastError()); - *MSVCRT__errno() = MSVCRT_ENOSPC; + *_errno() = ENOSPC; } else { @@ -2066,7 +2122,7 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count) } if (nr_lf) { - if ((q = p = MSVCRT_malloc(count + nr_lf))) + if ((q = p = malloc(count + nr_lf))) { for (s = (const char *)buf, i = 0, j = 0; i < count; i++) { @@ -2092,15 +2148,15 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count) { TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n", fd, hand, GetLastError(), num_written); - *MSVCRT__errno() = MSVCRT_ENOSPC; + *_errno() = ENOSPC; if(nr_lf) - MSVCRT_free(p); + free(p); return s - buf_start; } else { if(nr_lf) - MSVCRT_free(p); + free(p); return count; } } @@ -2110,84 +2166,84 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count) /********************************************************************* * _putw (MSVCRT.@) */ -int CDECL MSVCRT__putw(int val, MSVCRT_FILE* file) +int CDECL _putw(int val, FILE* file) { int len; - len = MSVCRT__write(file->_file, &val, sizeof(val)); + len = _write(file->_file, &val, sizeof(val)); if (len == sizeof(val)) return val; - file->_flag |= MSVCRT__IOERR; - return MSVCRT_EOF; + file->_flag |= _IOERR; + return EOF; } /********************************************************************* * fclose (MSVCRT.@) */ -int CDECL MSVCRT_fclose(MSVCRT_FILE* file) +int CDECL fclose(FILE* file) { int r, flag; flag = file->_flag; - MSVCRT_free(file->_tmpfname); + free(file->_tmpfname); file->_tmpfname = NULL; /* flush stdio buffers */ - if(file->_flag & MSVCRT__IOWRT) - MSVCRT_fflush(file); - if(file->_flag & MSVCRT__IOMYBUF) - MSVCRT_free(file->_base); + if(file->_flag & _IOWRT) + fflush(file); + if(file->_flag & _IOMYBUF) + free(file->_base); - r=MSVCRT__close(file->_file); + r=_close(file->_file); file->_flag = 0; - return ((r == -1) || (flag & MSVCRT__IOERR) ? MSVCRT_EOF : 0); + return ((r == -1) || (flag & _IOERR) ? EOF : 0); } /********************************************************************* * feof (MSVCRT.@) */ -int CDECL MSVCRT_feof(MSVCRT_FILE* file) +int CDECL feof(FILE* file) { - return file->_flag & MSVCRT__IOEOF; + return file->_flag & _IOEOF; } /********************************************************************* * ferror (MSVCRT.@) */ -int CDECL MSVCRT_ferror(MSVCRT_FILE* file) +int CDECL ferror(FILE* file) { - return file->_flag & MSVCRT__IOERR; + return file->_flag & _IOERR; } /********************************************************************* * _filbuf (MSVCRT.@) */ -int CDECL MSVCRT__filbuf(MSVCRT_FILE* file) +int CDECL _filbuf(FILE* file) { /* Allocate buffer if needed */ - if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF) ) { - msvcrt_alloc_buffer(file); + if(file->_bufsiz == 0 && !(file->_flag & _IONBF) ) { + alloc_buffer(file); } - if(!(file->_flag & MSVCRT__IOREAD)) { - if(file->_flag & MSVCRT__IORW) { - file->_flag |= MSVCRT__IOREAD; + if(!(file->_flag & _IOREAD)) { + if(file->_flag & _IORW) { + file->_flag |= _IOREAD; } else { - return MSVCRT_EOF; + return EOF; } } - if(file->_flag & MSVCRT__IONBF) { + if(file->_flag & _IONBF) { unsigned char c; int r; if ((r = read_i(file->_file,&c,1)) != 1) { - file->_flag |= (r == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR; - return MSVCRT_EOF; + file->_flag |= (r == 0) ? _IOEOF : _IOERR; + return EOF; } return c; } else { file->_cnt = read_i(file->_file, file->_base, file->_bufsiz); if(file->_cnt<=0) { - file->_flag |= (file->_cnt == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR; + file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR; file->_cnt = 0; - return MSVCRT_EOF; + return EOF; } file->_cnt--; file->_ptr = file->_base+1; @@ -2198,7 +2254,7 @@ int CDECL MSVCRT__filbuf(MSVCRT_FILE* file) /********************************************************************* * fgetc (MSVCRT.@) */ -int CDECL MSVCRT_fgetc(MSVCRT_FILE* file) +int CDECL fgetc(FILE* file) { unsigned char *i; unsigned int j; @@ -2208,8 +2264,8 @@ int CDECL MSVCRT_fgetc(MSVCRT_FILE* file) i = (unsigned char *)file->_ptr++; j = *i; } else - j = MSVCRT__filbuf(file); - if (!(MSVCRT_fdesc[file->_file].wxflag & WX_TEXT) + j = _filbuf(file); + if (!(fdesc[file->_file].wxflag & WX_TEXT) || ((j != '\r') || (file->_cnt && file->_ptr[0] != '\n'))) return j; } while(1); @@ -2220,31 +2276,31 @@ int CDECL MSVCRT_fgetc(MSVCRT_FILE* file) */ int CDECL _fgetchar(void) { - return MSVCRT_fgetc(MSVCRT_stdin); + return fgetc(stdin); } /********************************************************************* * fgets (MSVCRT.@) */ -char * CDECL MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file) +char * CDECL fgets(char *s, int size, FILE* file) { - int cc = MSVCRT_EOF; + int cc = EOF; char * buf_start = s; TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", file,file->_file,s,size); - while ((size >1) && (cc = MSVCRT_fgetc(file)) != MSVCRT_EOF && cc != '\n') + while ((size >1) && (cc = fgetc(file)) != EOF && cc != '\n') { *s++ = (char)cc; size --; } - if ((cc == MSVCRT_EOF) && (s == buf_start)) /* If nothing read, return 0*/ + if ((cc == EOF) && (s == buf_start)) /* If nothing read, return 0*/ { TRACE(":nothing read\n"); return NULL; } - if ((cc != MSVCRT_EOF) && (size > 1)) + if ((cc != EOF) && (size > 1)) *s++ = cc; *s = '\0'; TRACE(":got %s\n", debugstr_a(buf_start)); @@ -2254,16 +2310,16 @@ char * CDECL MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file) /********************************************************************* * fgetwc (MSVCRT.@) * - * In MSVCRT__O_TEXT mode, multibyte characters are read from the file, dropping + * In _O_TEXT mode, multibyte characters are read from the file, dropping * the CR from CR/LF combinations */ -MSVCRT_wint_t CDECL MSVCRT_fgetwc(MSVCRT_FILE* file) +wint_t CDECL fgetwc(FILE* file) { char c; - if (!(MSVCRT_fdesc[file->_file].wxflag & WX_TEXT)) + if (!(fdesc[file->_file].wxflag & WX_TEXT)) { - MSVCRT_wchar_t wc; + wchar_t wc; int i,j; char *chp, *wcp; wcp = (char *)&wc; @@ -2277,12 +2333,12 @@ MSVCRT_wint_t CDECL MSVCRT_fgetwc(MSVCRT_FILE* file) } else { - j = MSVCRT__filbuf(file); + j = _filbuf(file); if(file->_cnt<=0) { - file->_flag |= (file->_cnt == 0) ? MSVCRT__IOEOF : MSVCRT__IOERR; + file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR; file->_cnt = 0; - return MSVCRT_WEOF; + return WEOF; } wcp[i] = j; } @@ -2290,29 +2346,29 @@ MSVCRT_wint_t CDECL MSVCRT_fgetwc(MSVCRT_FILE* file) return wc; } - c = MSVCRT_fgetc(file); - if ((*__p___mb_cur_max() > 1) && MSVCRT_isleadbyte(c)) + c = fgetc(file); + if ((*__p___mb_cur_max() > 1) && isleadbyte(c)) { FIXME("Treat Multibyte characters\n"); } - if (c == MSVCRT_EOF) - return MSVCRT_WEOF; + if (c == EOF) + return WEOF; else - return (MSVCRT_wint_t)c; + return (wint_t)c; } /********************************************************************* * _getw (MSVCRT.@) */ -int CDECL MSVCRT__getw(MSVCRT_FILE* file) +int CDECL _getw(FILE* file) { char *ch; int i, j, k; ch = (char *)&i; for (j=0; j_flag |= MSVCRT__IOEOF; + k = fgetc(file); + if (k == EOF) { + file->_flag |= _IOEOF; return EOF; } ch[j] = k; @@ -2323,23 +2379,23 @@ int CDECL MSVCRT__getw(MSVCRT_FILE* file) /********************************************************************* * getwc (MSVCRT.@) */ -MSVCRT_wint_t CDECL MSVCRT_getwc(MSVCRT_FILE* file) +wint_t CDECL getwc(FILE* file) { - return MSVCRT_fgetwc(file); + return fgetwc(file); } /********************************************************************* * _fgetwchar (MSVCRT.@) */ -MSVCRT_wint_t CDECL _fgetwchar(void) +wint_t CDECL _fgetwchar(void) { - return MSVCRT_fgetwc(MSVCRT_stdin); + return fgetwc(stdin); } /********************************************************************* * getwchar (MSVCRT.@) */ -MSVCRT_wint_t CDECL MSVCRT_getwchar(void) +wint_t CDECL getwchar(void) { return _fgetwchar(); } @@ -2347,25 +2403,25 @@ MSVCRT_wint_t CDECL MSVCRT_getwchar(void) /********************************************************************* * fgetws (MSVCRT.@) */ -MSVCRT_wchar_t * CDECL MSVCRT_fgetws(MSVCRT_wchar_t *s, int size, MSVCRT_FILE* file) +wchar_t * CDECL fgetws(wchar_t *s, int size, FILE* file) { - int cc = MSVCRT_WEOF; - MSVCRT_wchar_t * buf_start = s; + int cc = WEOF; + wchar_t * buf_start = s; TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", file,file->_file,s,size); - while ((size >1) && (cc = MSVCRT_fgetwc(file)) != MSVCRT_WEOF && cc != '\n') + while ((size >1) && (cc = fgetwc(file)) != WEOF && cc != '\n') { *s++ = (char)cc; size --; } - if ((cc == MSVCRT_WEOF) && (s == buf_start)) /* If nothing read, return 0*/ + if ((cc == WEOF) && (s == buf_start)) /* If nothing read, return 0*/ { TRACE(":nothing read\n"); return NULL; } - if ((cc != MSVCRT_WEOF) && (size > 1)) + if ((cc != WEOF) && (size > 1)) *s++ = cc; *s = 0; TRACE(":got %s\n", debugstr_w(buf_start)); @@ -2375,9 +2431,9 @@ MSVCRT_wchar_t * CDECL MSVCRT_fgetws(MSVCRT_wchar_t *s, int size, MSVCRT_FILE* f /********************************************************************* * fwrite (MSVCRT.@) */ -MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_size_t nmemb, MSVCRT_FILE* file) +size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE* file) { - MSVCRT_size_t wrcnt=size * nmemb; + size_t wrcnt=size * nmemb; int written = 0; if (size == 0) return 0; @@ -2389,20 +2445,20 @@ MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_si written = pcnt; wrcnt -= pcnt; ptr = (const char*)ptr + pcnt; - } else if(!(file->_flag & MSVCRT__IOWRT)) { - if(file->_flag & MSVCRT__IORW) { - file->_flag |= MSVCRT__IOWRT; + } else if(!(file->_flag & _IOWRT)) { + if(file->_flag & _IORW) { + file->_flag |= _IOWRT; } else return 0; } if(wrcnt) { /* Flush buffer */ - int res=msvcrt_flush_buffer(file); + int res=flush_buffer(file); if(!res) { - int pwritten = MSVCRT__write(file->_file, ptr, wrcnt); + int pwritten = _write(file->_file, ptr, wrcnt); if (pwritten <= 0) { - file->_flag |= MSVCRT__IOERR; + file->_flag |= _IOERR; pwritten=0; } written += pwritten; @@ -2414,41 +2470,41 @@ MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_si /********************************************************************* * fputwc (MSVCRT.@) */ -MSVCRT_wint_t CDECL MSVCRT_fputwc(MSVCRT_wint_t wc, MSVCRT_FILE* file) +wint_t CDECL fputwc(wint_t wc, FILE* file) { - MSVCRT_wchar_t mwc=wc; - if (MSVCRT_fwrite( &mwc, sizeof(mwc), 1, file) != 1) - return MSVCRT_WEOF; + wchar_t mwc=wc; + if (fwrite( &mwc, sizeof(mwc), 1, file) != 1) + return WEOF; return wc; } /********************************************************************* * _fputwchar (MSVCRT.@) */ -MSVCRT_wint_t CDECL _fputwchar(MSVCRT_wint_t wc) +wint_t CDECL _fputwchar(wint_t wc) { - return MSVCRT_fputwc(wc, MSVCRT_stdout); + return fputwc(wc, stdout); } /********************************************************************* * _fsopen (MSVCRT.@) */ -MSVCRT_FILE * CDECL MSVCRT__fsopen(const char *path, const char *mode, int share) +FILE * CDECL _fsopen(const char *path, const char *mode, int share) { - MSVCRT_FILE* file; + FILE* file; int open_flags, stream_flags, fd; TRACE("(%s,%s)\n",path,mode); /* map mode string to open() flags. "man fopen" for possibilities. */ - if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) + if (get_flags(mode, &open_flags, &stream_flags) == -1) return NULL; LOCK_FILES(); - fd = MSVCRT__sopen(path, open_flags, share, MSVCRT__S_IREAD | MSVCRT__S_IWRITE); + fd = _sopen(path, open_flags, share, _S_IREAD | _S_IWRITE); if (fd < 0) file = NULL; - else if ((file = msvcrt_alloc_fp()) && msvcrt_init_fp(file, fd, stream_flags) + else if ((file = alloc_fp()) && init_fp(file, fd, stream_flags) != -1) TRACE(":fd (%d) mode (%s) FILE* (%p)\n",fd,mode,file); else if (file) @@ -2459,7 +2515,7 @@ MSVCRT_FILE * CDECL MSVCRT__fsopen(const char *path, const char *mode, int share TRACE(":got (%p)\n",file); if (fd >= 0 && !file) - MSVCRT__close(fd); + _close(fd); UNLOCK_FILES(); return file; } @@ -2467,11 +2523,11 @@ MSVCRT_FILE * CDECL MSVCRT__fsopen(const char *path, const char *mode, int share /********************************************************************* * _wfsopen (MSVCRT.@) */ -MSVCRT_FILE * CDECL MSVCRT__wfsopen(const MSVCRT_wchar_t *path, const MSVCRT_wchar_t *mode, int share) +FILE * CDECL _wfsopen(const wchar_t *path, const wchar_t *mode, int share) { const unsigned int plen = strlenW(path), mlen = strlenW(mode); - char *patha = MSVCRT_calloc(plen + 1, 1); - char *modea = MSVCRT_calloc(mlen + 1, 1); + char *patha = calloc(plen + 1, 1); + char *modea = calloc(mlen + 1, 1); TRACE("(%s,%s)\n",debugstr_w(path),debugstr_w(mode)); @@ -2479,81 +2535,81 @@ MSVCRT_FILE * CDECL MSVCRT__wfsopen(const MSVCRT_wchar_t *path, const MSVCRT_wch WideCharToMultiByte(CP_ACP,0,path,plen,patha,plen,NULL,NULL) && WideCharToMultiByte(CP_ACP,0,mode,mlen,modea,mlen,NULL,NULL)) { - MSVCRT_FILE *retval = MSVCRT__fsopen(patha,modea,share); - MSVCRT_free(patha); - MSVCRT_free(modea); + FILE *retval = _fsopen(patha,modea,share); + free(patha); + free(modea); return retval; } - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); return NULL; } /********************************************************************* * fopen (MSVCRT.@) */ -MSVCRT_FILE * CDECL MSVCRT_fopen(const char *path, const char *mode) +FILE * CDECL fopen(const char *path, const char *mode) { - return MSVCRT__fsopen( path, mode, MSVCRT__SH_DENYNO ); + return _fsopen( path, mode, _SH_DENYNO ); } /********************************************************************* * _wfopen (MSVCRT.@) */ -MSVCRT_FILE * CDECL MSVCRT__wfopen(const MSVCRT_wchar_t *path, const MSVCRT_wchar_t *mode) +FILE * CDECL _wfopen(const wchar_t *path, const wchar_t *mode) { - return MSVCRT__wfsopen( path, mode, MSVCRT__SH_DENYNO ); + return _wfsopen( path, mode, _SH_DENYNO ); } -/* MSVCRT_fputc calls MSVCRT__flsbuf which calls MSVCRT_fputc */ -int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file); +/* fputc calls _flsbuf which calls fputc */ +int CDECL _flsbuf(int c, FILE* file); /********************************************************************* * fputc (MSVCRT.@) */ -int CDECL MSVCRT_fputc(int c, MSVCRT_FILE* file) +int CDECL fputc(int c, FILE* file) { if(file->_cnt>0) { *file->_ptr++=c; file->_cnt--; if (c == '\n') { - int res = msvcrt_flush_buffer(file); + int res = flush_buffer(file); return res ? res : c; } else return c; } else { - return MSVCRT__flsbuf(c, file); + return _flsbuf(c, file); } } /********************************************************************* * _flsbuf (MSVCRT.@) */ -int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file) +int CDECL _flsbuf(int c, FILE* file) { /* Flush output buffer */ - if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF)) { - msvcrt_alloc_buffer(file); + if(file->_bufsiz == 0 && !(file->_flag & _IONBF)) { + alloc_buffer(file); } - if(!(file->_flag & MSVCRT__IOWRT)) { - if(file->_flag & MSVCRT__IORW) { - file->_flag |= MSVCRT__IOWRT; + if(!(file->_flag & _IOWRT)) { + if(file->_flag & _IORW) { + file->_flag |= _IOWRT; } else { - return MSVCRT_EOF; + return EOF; } } if(file->_bufsiz) { - int res=msvcrt_flush_buffer(file); - return res?res : MSVCRT_fputc(c, file); + int res=flush_buffer(file); + return res?res : fputc(c, file); } else { unsigned char cc=c; int len; - len = MSVCRT__write(file->_file, &cc, 1); + len = _write(file->_file, &cc, 1); if (len == 1) return c; - file->_flag |= MSVCRT__IOERR; - return MSVCRT_EOF; + file->_flag |= _IOERR; + return EOF; } } @@ -2562,15 +2618,15 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file) */ int CDECL _fputchar(int c) { - return MSVCRT_fputc(c, MSVCRT_stdout); + return fputc(c, stdout); } /********************************************************************* * fread (MSVCRT.@) */ -MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nmemb, MSVCRT_FILE* file) -{ MSVCRT_size_t rcnt=size * nmemb; - MSVCRT_size_t read=0; +size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE* file) +{ size_t rcnt=size * nmemb; + size_t read=0; int pread=0; if(!rcnt) @@ -2582,14 +2638,14 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm memcpy(ptr, file->_ptr, pcnt); file->_cnt -= pcnt; file->_ptr += pcnt; - if (MSVCRT_fdesc[file->_file].wxflag & WX_TEXT) + if (fdesc[file->_file].wxflag & WX_TEXT) pcnt -= remove_cr(ptr,pcnt); read += pcnt ; rcnt -= pcnt ; ptr = (char*)ptr + pcnt; - } else if(!(file->_flag & MSVCRT__IOREAD )) { - if(file->_flag & MSVCRT__IORW) { - file->_flag |= MSVCRT__IOREAD; + } else if(!(file->_flag & _IOREAD )) { + if(file->_flag & _IORW) { + file->_flag |= _IOREAD; } else return 0; } @@ -2599,17 +2655,17 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm /* Fill the buffer on small reads. * TODO: Use a better buffering strategy. */ - if (!file->_cnt && size*nmemb <= MSVCRT_BUFSIZ/2 && !(file->_flag & MSVCRT__IONBF)) { + if (!file->_cnt && size*nmemb <= BUFSIZ/2 && !(file->_flag & _IONBF)) { if (file->_bufsiz == 0) { - msvcrt_alloc_buffer(file); + alloc_buffer(file); } - file->_cnt = MSVCRT__read(file->_file, file->_base, file->_bufsiz); + file->_cnt = _read(file->_file, file->_base, file->_bufsiz); file->_ptr = file->_base; i = (file->_cnt_cnt : rcnt; /* If the buffer fill reaches eof but fread wouldn't, clear eof. */ if (i > 0 && i < file->_cnt) { - MSVCRT_fdesc[file->_file].wxflag &= ~WX_ATEOF; - file->_flag &= ~MSVCRT__IOEOF; + fdesc[file->_file].wxflag &= ~WX_ATEOF; + file->_flag &= ~_IOEOF; } if (i > 0) { memcpy(ptr, file->_ptr, i); @@ -2617,7 +2673,7 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm file->_ptr += i; } } else { - i = MSVCRT__read(file->_file,ptr, rcnt); + i = _read(file->_file,ptr, rcnt); } pread += i; rcnt -= i; @@ -2625,11 +2681,11 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm /* expose feof condition in the flags * MFC tests file->_flag for feof, and doesn't call feof()) */ - if ( MSVCRT_fdesc[file->_file].wxflag & WX_ATEOF) - file->_flag |= MSVCRT__IOEOF; + if ( fdesc[file->_file].wxflag & WX_ATEOF) + file->_flag |= _IOEOF; else if (i == -1) { - file->_flag |= MSVCRT__IOERR; + file->_flag |= _IOERR; pread = 0; rcnt = 0; } @@ -2643,31 +2699,31 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm * freopen (MSVCRT.@) * */ -MSVCRT_FILE* CDECL MSVCRT_freopen(const char *path, const char *mode,MSVCRT_FILE* file) +FILE* CDECL freopen(const char *path, const char *mode,FILE* file) { int open_flags, stream_flags, fd; TRACE(":path (%p) mode (%s) file (%p) fd (%d)\n",path,mode,file,file->_file); LOCK_FILES(); - if (!file || ((fd = file->_file) < 0) || fd > MSVCRT_fdend) + if (!file || ((fd = file->_file) < 0) || fd > fdend) file = NULL; else { - MSVCRT_fclose(file); + fclose(file); /* map mode string to open() flags. "man fopen" for possibilities. */ - if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1) + if (get_flags(mode, &open_flags, &stream_flags) == -1) file = NULL; else { - fd = MSVCRT__open(path, open_flags, MSVCRT__S_IREAD | MSVCRT__S_IWRITE); + fd = _open(path, open_flags, _S_IREAD | _S_IWRITE); if (fd < 0) file = NULL; - else if (msvcrt_init_fp(file, fd, stream_flags) == -1) + else if (init_fp(file, fd, stream_flags) == -1) { file->_flag = 0; WARN(":failed-last error (%d)\n",GetLastError()); - msvcrt_set_errno(GetLastError()); + __set_errno(GetLastError()); file = NULL; } } @@ -2676,36 +2732,46 @@ MSVCRT_FILE* CDECL MSVCRT_freopen(const char *path, const char *mode,MSVCRT_FILE return file; } +/********************************************************************* + * wfreopen (MSVCRT.@) + * + */ +FILE* CDECL _wfreopen(const wchar_t *path, const wchar_t *mode,FILE* file) +{ + FIXME("UNIMPLEMENTED stub!\n"); + return NULL; +} + /********************************************************************* * fsetpos (MSVCRT.@) */ -int CDECL MSVCRT_fsetpos(MSVCRT_FILE* file, MSVCRT_fpos_t *pos) +int CDECL fsetpos(FILE* file, const fpos_t *pos) { /* Note that all this has been lifted 'as is' from fseek */ - if(file->_flag & MSVCRT__IOWRT) - msvcrt_flush_buffer(file); + if(file->_flag & _IOWRT) + flush_buffer(file); /* Discard buffered input */ file->_cnt = 0; file->_ptr = file->_base; /* Reset direction of i/o */ - if(file->_flag & MSVCRT__IORW) { - file->_flag &= ~(MSVCRT__IOREAD|MSVCRT__IOWRT); + if(file->_flag & _IORW) { + file->_flag &= ~(_IOREAD|_IOWRT); } - return (MSVCRT__lseeki64(file->_file,*pos,SEEK_SET) == -1) ? -1 : 0; + return (_lseeki64(file->_file,*pos,SEEK_SET) == -1) ? -1 : 0; } /********************************************************************* * ftell (MSVCRT.@) */ -LONG CDECL MSVCRT_ftell(MSVCRT_FILE* file) +LONG CDECL ftell(FILE* file) { int off=0; long pos; if(file->_bufsiz) { - if( file->_flag & MSVCRT__IOWRT ) { + if( file->_flag & _IOWRT ) { off = file->_ptr - file->_base; } else { off = -file->_cnt; @@ -2719,17 +2785,17 @@ LONG CDECL MSVCRT_ftell(MSVCRT_FILE* file) /********************************************************************* * fgetpos (MSVCRT.@) */ -int CDECL MSVCRT_fgetpos(MSVCRT_FILE* file, MSVCRT_fpos_t *pos) +int CDECL fgetpos(FILE* file, fpos_t *pos) { - /* This code has been lifted form the MSVCRT_ftell function */ + /* This code has been lifted form the ftell function */ int off=0; - *pos = MSVCRT__lseeki64(file->_file,0,SEEK_CUR); + *pos = _lseeki64(file->_file,0,SEEK_CUR); if (*pos == -1) return -1; if(file->_bufsiz) { - if( file->_flag & MSVCRT__IOWRT ) { + if( file->_flag & _IOWRT ) { off = file->_ptr - file->_base; } else { off = -file->_cnt; @@ -2743,31 +2809,31 @@ int CDECL MSVCRT_fgetpos(MSVCRT_FILE* file, MSVCRT_fpos_t *pos) /********************************************************************* * fputs (MSVCRT.@) */ -int CDECL MSVCRT_fputs(const char *s, MSVCRT_FILE* file) +int CDECL fputs(const char *s, FILE* file) { size_t i, len = strlen(s); - if (!(MSVCRT_fdesc[file->_file].wxflag & WX_TEXT)) - return MSVCRT_fwrite(s,sizeof(*s),len,file) == len ? 0 : MSVCRT_EOF; + if (!(fdesc[file->_file].wxflag & WX_TEXT)) + return fwrite(s,sizeof(*s),len,file) == len ? 0 : EOF; for (i=0; i_file].wxflag & WX_TEXT)) - return MSVCRT_fwrite(s,sizeof(*s),len,file) == len ? 0 : MSVCRT_EOF; + if (!(fdesc[file->_file].wxflag & WX_TEXT)) + return fwrite(s,sizeof(*s),len,file) == len ? 0 : EOF; for (i=0; i_bufsiz) { - MSVCRT_free(file->_base); + free(file->_base); file->_bufsiz = 0; file->_cnt = 0; } - if(mode == MSVCRT__IOFBF) { - file->_flag &= ~MSVCRT__IONBF; + if(mode == _IOFBF) { + file->_flag &= ~_IONBF; file->_base = file->_ptr = buf; if(buf) { file->_bufsiz = size; } } else { - file->_flag |= MSVCRT__IONBF; + file->_flag |= _IONBF; } return 0; } @@ -2941,27 +3007,27 @@ int CDECL MSVCRT_setvbuf(MSVCRT_FILE* file, char *buf, int mode, MSVCRT_size_t s /********************************************************************* * setbuf (MSVCRT.@) */ -void CDECL MSVCRT_setbuf(MSVCRT_FILE* file, char *buf) +void CDECL setbuf(FILE* file, char *buf) { - MSVCRT_setvbuf(file, buf, buf ? MSVCRT__IOFBF : MSVCRT__IONBF, MSVCRT_BUFSIZ); + setvbuf(file, buf, buf ? _IOFBF : _IONBF, BUFSIZ); } /********************************************************************* * tmpnam (MSVCRT.@) */ -char * CDECL MSVCRT_tmpnam(char *s) +char * CDECL tmpnam(char *s) { static int unique; char tmpstr[16]; char *p; int count; if (s == 0) - s = MSVCRT_tmpname; - msvcrt_int_to_base32(GetCurrentProcessId(), tmpstr); + s = tmpname; + int_to_base32(GetCurrentProcessId(), tmpstr); p = s + sprintf(s, "\\s%s.", tmpstr); - for (count = 0; count < MSVCRT_TMP_MAX; count++) + for (count = 0; count < TMP_MAX; count++) { - msvcrt_int_to_base32(unique++, tmpstr); + int_to_base32(unique++, tmpstr); strcpy(p, tmpstr); if (GetFileAttributesA(s) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND) @@ -2970,20 +3036,29 @@ char * CDECL MSVCRT_tmpnam(char *s) return s; } +/********************************************************************* + * wtmpnam (MSVCRT.@) + */ +wchar_t * CDECL _wtmpnam(wchar_t *s) +{ + ERR("UNIMPLEMENTED!\n"); + return NULL; +} + /********************************************************************* * tmpfile (MSVCRT.@) */ -MSVCRT_FILE* CDECL MSVCRT_tmpfile(void) +FILE* CDECL tmpfile(void) { - char *filename = MSVCRT_tmpnam(NULL); + char *filename = tmpnam(NULL); int fd; - MSVCRT_FILE* file = NULL; + FILE* file = NULL; LOCK_FILES(); - fd = MSVCRT__open(filename, MSVCRT__O_CREAT | MSVCRT__O_BINARY | MSVCRT__O_RDWR | MSVCRT__O_TEMPORARY); - if (fd != -1 && (file = msvcrt_alloc_fp())) + fd = _open(filename, _O_CREAT | _O_BINARY | _O_RDWR | _O_TEMPORARY); + if (fd != -1 && (file = alloc_fp())) { - if (msvcrt_init_fp(file, fd, MSVCRT__O_RDWR) == -1) + if (init_fp(file, fd, _O_RDWR) == -1) { file->_flag = 0; file = NULL; @@ -2997,7 +3072,7 @@ MSVCRT_FILE* CDECL MSVCRT_tmpfile(void) /********************************************************************* * vfprintf (MSVCRT.@) */ -int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, va_list valist) +int CDECL vfprintf(FILE* file, const char *format, va_list valist) { char buf[2048], *mem = buf; int written, resize = sizeof(buf), retval; @@ -3006,18 +3081,18 @@ int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, va_list valist) * Return the number of bytes that would have been written * The code below handles both cases */ - while ((written = MSVCRT_vsnprintf(mem, resize, format, valist)) == -1 || + while ((written = vsnprintf(mem, resize, format, valist)) == -1 || written > resize) { resize = (written == -1 ? resize * 2 : written + 1); if (mem != buf) - MSVCRT_free (mem); - if (!(mem = MSVCRT_malloc(resize))) - return MSVCRT_EOF; + free (mem); + if (!(mem = malloc(resize))) + return EOF; } - retval = MSVCRT_fwrite(mem, sizeof(*mem), written, file); + retval = fwrite(mem, sizeof(*mem), written, file); if (mem != buf) - MSVCRT_free (mem); + free (mem); return retval; } @@ -3027,51 +3102,51 @@ int CDECL MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, va_list valist) * Is final char included in written (then resize is too big) or not * (then we must test for equality too)? */ -int CDECL MSVCRT_vfwprintf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, va_list valist) +int CDECL vfwprintf(FILE* file, const wchar_t *format, va_list valist) { - MSVCRT_wchar_t buf[2048], *mem = buf; - int written, resize = sizeof(buf) / sizeof(MSVCRT_wchar_t), retval; + wchar_t buf[2048], *mem = buf; + int written, resize = sizeof(buf) / sizeof(wchar_t), retval; /* See vfprintf comments */ - while ((written = MSVCRT_vsnwprintf(mem, resize, format, valist)) == -1 || + while ((written = vsnwprintf(mem, resize, format, valist)) == -1 || written > resize) { - resize = (written == -1 ? resize * 2 : written + sizeof(MSVCRT_wchar_t)); + resize = (written == -1 ? resize * 2 : written + sizeof(wchar_t)); if (mem != buf) - MSVCRT_free (mem); - if (!(mem = MSVCRT_malloc(resize*sizeof(*mem)))) - return MSVCRT_EOF; + free (mem); + if (!(mem = malloc(resize*sizeof(*mem)))) + return EOF; } - retval = MSVCRT_fwrite(mem, sizeof(*mem), written, file); + retval = fwrite(mem, sizeof(*mem), written, file); if (mem != buf) - MSVCRT_free (mem); + free (mem); return retval; } /********************************************************************* * vprintf (MSVCRT.@) */ -int CDECL MSVCRT_vprintf(const char *format, va_list valist) +int CDECL vprintf(const char *format, va_list valist) { - return MSVCRT_vfprintf(MSVCRT_stdout,format,valist); + return vfprintf(stdout,format,valist); } /********************************************************************* * vwprintf (MSVCRT.@) */ -int CDECL MSVCRT_vwprintf(const MSVCRT_wchar_t *format, va_list valist) +int CDECL vwprintf(const wchar_t *format, va_list valist) { - return MSVCRT_vfwprintf(MSVCRT_stdout,format,valist); + return vfwprintf(stdout,format,valist); } /********************************************************************* * fprintf (MSVCRT.@) */ -int CDECL MSVCRT_fprintf(MSVCRT_FILE* file, const char *format, ...) +int CDECL fprintf(FILE* file, const char *format, ...) { va_list valist; int res; va_start(valist, format); - res = MSVCRT_vfprintf(file, format, valist); + res = vfprintf(file, format, valist); va_end(valist); return res; } @@ -3079,12 +3154,12 @@ int CDECL MSVCRT_fprintf(MSVCRT_FILE* file, const char *format, ...) /********************************************************************* * fwprintf (MSVCRT.@) */ -int CDECL MSVCRT_fwprintf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, ...) +int CDECL fwprintf(FILE* file, const wchar_t *format, ...) { va_list valist; int res; va_start(valist, format); - res = MSVCRT_vfwprintf(file, format, valist); + res = vfwprintf(file, format, valist); va_end(valist); return res; } @@ -3092,12 +3167,12 @@ int CDECL MSVCRT_fwprintf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, ...) /********************************************************************* * printf (MSVCRT.@) */ -int CDECL MSVCRT_printf(const char *format, ...) +int CDECL printf(const char *format, ...) { va_list valist; int res; va_start(valist, format); - res = MSVCRT_vfprintf(MSVCRT_stdout, format, valist); + res = vfprintf(stdout, format, valist); va_end(valist); return res; } @@ -3105,35 +3180,35 @@ int CDECL MSVCRT_printf(const char *format, ...) /********************************************************************* * ungetc (MSVCRT.@) */ -int CDECL MSVCRT_ungetc(int c, MSVCRT_FILE * file) +int CDECL ungetc(int c, FILE * file) { - if (c == MSVCRT_EOF) - return MSVCRT_EOF; - if(file->_bufsiz == 0 && !(file->_flag & MSVCRT__IONBF)) { - msvcrt_alloc_buffer(file); + if (c == EOF) + return EOF; + if(file->_bufsiz == 0 && !(file->_flag & _IONBF)) { + alloc_buffer(file); file->_ptr++; } if(file->_ptr>file->_base) { file->_ptr--; *file->_ptr=c; file->_cnt++; - MSVCRT_clearerr(file); + clearerr(file); return c; } - return MSVCRT_EOF; + return EOF; } /********************************************************************* * ungetwc (MSVCRT.@) */ -MSVCRT_wint_t CDECL MSVCRT_ungetwc(MSVCRT_wint_t wc, MSVCRT_FILE * file) +wint_t CDECL ungetwc(wint_t wc, FILE * file) { - MSVCRT_wchar_t mwc = wc; + wchar_t mwc = wc; char * pp = (char *)&mwc; int i; - for(i=sizeof(MSVCRT_wchar_t)-1;i>=0;i--) { - if(pp[i] != MSVCRT_ungetc(pp[i],file)) - return MSVCRT_WEOF; + for(i=sizeof(wchar_t)-1;i>=0;i--) { + if(pp[i] != ungetc(pp[i],file)) + return WEOF; } return mwc; } @@ -3141,12 +3216,12 @@ MSVCRT_wint_t CDECL MSVCRT_ungetwc(MSVCRT_wint_t wc, MSVCRT_FILE * file) /********************************************************************* * wprintf (MSVCRT.@) */ -int CDECL MSVCRT_wprintf(const MSVCRT_wchar_t *format, ...) +int CDECL wprintf(const wchar_t *format, ...) { va_list valist; int res; va_start(valist, format); - res = MSVCRT_vwprintf(format, valist); + res = vwprintf(format, valist); va_end(valist); return res; } @@ -3176,24 +3251,23 @@ int CDECL _setmaxstdio(int newmax) /********************************************************************* * __pioinfo (MSVCRT.@) - * FIXME: see MSVCRT_MAX_FILES define. + * FIXME: see MAX_FILES define. */ -ioinfo * MSVCRT___pioinfo[] = { /* array of pointers to ioinfo arrays [64] */ - &MSVCRT_fdesc[0 * 64], &MSVCRT_fdesc[1 * 64], &MSVCRT_fdesc[2 * 64], - &MSVCRT_fdesc[3 * 64], &MSVCRT_fdesc[4 * 64], &MSVCRT_fdesc[5 * 64], - &MSVCRT_fdesc[6 * 64], &MSVCRT_fdesc[7 * 64], &MSVCRT_fdesc[8 * 64], - &MSVCRT_fdesc[9 * 64], &MSVCRT_fdesc[10 * 64], &MSVCRT_fdesc[11 * 64], - &MSVCRT_fdesc[12 * 64], &MSVCRT_fdesc[13 * 64], &MSVCRT_fdesc[14 * 64], - &MSVCRT_fdesc[15 * 64], &MSVCRT_fdesc[16 * 64], &MSVCRT_fdesc[17 * 64], - &MSVCRT_fdesc[18 * 64], &MSVCRT_fdesc[19 * 64], &MSVCRT_fdesc[20 * 64], - &MSVCRT_fdesc[21 * 64], &MSVCRT_fdesc[22 * 64], &MSVCRT_fdesc[23 * 64], - &MSVCRT_fdesc[24 * 64], &MSVCRT_fdesc[25 * 64], &MSVCRT_fdesc[26 * 64], - &MSVCRT_fdesc[27 * 64], &MSVCRT_fdesc[28 * 64], &MSVCRT_fdesc[29 * 64], - &MSVCRT_fdesc[30 * 64], &MSVCRT_fdesc[31 * 64] +ioinfo * __pioinfo[] = { /* array of pointers to ioinfo arrays [64] */ + &fdesc[0 * 64], &fdesc[1 * 64], &fdesc[2 * 64], + &fdesc[3 * 64], &fdesc[4 * 64], &fdesc[5 * 64], + &fdesc[6 * 64], &fdesc[7 * 64], &fdesc[8 * 64], + &fdesc[9 * 64], &fdesc[10 * 64], &fdesc[11 * 64], + &fdesc[12 * 64], &fdesc[13 * 64], &fdesc[14 * 64], + &fdesc[15 * 64], &fdesc[16 * 64], &fdesc[17 * 64], + &fdesc[18 * 64], &fdesc[19 * 64], &fdesc[20 * 64], + &fdesc[21 * 64], &fdesc[22 * 64], &fdesc[23 * 64], + &fdesc[24 * 64], &fdesc[25 * 64], &fdesc[26 * 64], + &fdesc[27 * 64], &fdesc[28 * 64], &fdesc[29 * 64], + &fdesc[30 * 64], &fdesc[31 * 64] } ; /********************************************************************* * __badioinfo (MSVCRT.@) */ -ioinfo MSVCRT___badioinfo = { INVALID_HANDLE_VALUE, WX_TEXT }; -#endif +ioinfo __badioinfo = { INVALID_HANDLE_VALUE, WX_TEXT }; diff --git a/reactos/lib/sdk/crt/stdio/fileno.c b/reactos/lib/sdk/crt/stdio/fileno.c deleted file mode 100644 index 869550601dd..00000000000 --- a/reactos/lib/sdk/crt/stdio/fileno.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include - -#undef _fileno - -/* - * @implemented - */ -int _fileno(FILE *f) -{ - return f->_file; -} diff --git a/reactos/lib/sdk/crt/io/find.c b/reactos/lib/sdk/crt/stdio/find.c similarity index 100% rename from reactos/lib/sdk/crt/io/find.c rename to reactos/lib/sdk/crt/stdio/find.c diff --git a/reactos/lib/sdk/crt/stdio/flsbuf.c b/reactos/lib/sdk/crt/stdio/flsbuf.c deleted file mode 100644 index 0634ff6be88..00000000000 --- a/reactos/lib/sdk/crt/stdio/flsbuf.c +++ /dev/null @@ -1,153 +0,0 @@ -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include -#include - -int cntcr(char* bufp, int bufsiz); -int convert(char* endp, int bufsiz, int n); -int _writecnv(int fn, void* buf, size_t bufsiz); - - -/* - * @implemented - */ -int _flsbuf(int c, FILE* f) -{ - char* base; - int n, rn; - char c1; - int size; - - if (!OPEN4WRITING(f)) { - __set_errno(EINVAL); - return EOF; - } - - // no file associated with buffer, this is a memory stream - if (_fileno(f) == -1) { - return c; - } - - /* if the buffer is not yet allocated, allocate it */ - if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0) { - size = 4096; - if ((f->_base = base = malloc(size)) == NULL) { - f->_flag |= _IONBF; - f->_flag &= ~(_IOFBF|_IO_LBF); - } else { - f->_flag |= _IOMYBUF; - f->_cnt = f->_bufsiz = size; - f->_ptr = base; - rn = 0; - if (f == stdout && _isatty(_fileno(stdout))) { - f->_flag |= _IO_LBF; - } - } - } - - if (f->_flag & _IO_LBF) { - /* in line-buffering mode we get here on each character */ - *f->_ptr++ = c; - rn = f->_ptr - base; - if (c == '\n' || rn >= f->_bufsiz) { - /* time for real flush */ - f->_ptr = base; - f->_cnt = 0; - } else { - /* we got here because _cnt is wrong, so fix it */ - /* Negative _cnt causes all output functions to call */ - /* _flsbuf for each character, thus realizing line-buffering */ - f->_cnt = -rn; - return c; - } - } else if (f->_flag & _IONBF) { - c1 = c; - rn = 1; - base = &c1; - f->_cnt = 0; - } else { /* _IOFBF */ - rn = f->_ptr - base; - f->_ptr = base; - if ((f->_flag & _IOAHEAD) == _IOAHEAD) - _lseek(_fileno(f), -(rn+f->_cnt), SEEK_CUR); - f->_cnt = f->_bufsiz; - f->_flag &= ~_IOAHEAD; - } - f->_flag &= ~_IODIRTY; - while (rn > 0) { - n = _write(_fileno(f), base, rn); - if (n <= 0) { - f->_flag |= _IOERR; - return EOF; - } - rn -= n; - base += n; - } - if ((f->_flag & (_IO_LBF|_IONBF)) == 0) { - f->_cnt--; - *f->_ptr++ = c; - f->_flag |= _IODIRTY; - } - return c; -} - -wint_t _flswbuf(wchar_t c, FILE* fp) -{ - int result; - - result = _flsbuf((int)c, fp); - if (result == EOF) - return WEOF; - return (wint_t)result; -} - -int _writecnv(int fn, void* buf, size_t siz) -{ - char* bufp = (char*)buf; - int bufsiz = siz; - char* tmp; - int cr1 = 0; - int cr2 = 0; - int n; - - cr1 = cntcr(bufp, bufsiz); - tmp = malloc(cr1); - memcpy(tmp, bufp + bufsiz - cr1, cr1); - cr2 = cntcr(tmp, cr1); - convert(bufp, bufsiz - cr2, cr1 - cr2); - n = _write(fn, bufp, bufsiz + cr1); - convert(tmp, cr1, cr2); - n += _write(fn, tmp, cr1 + cr2); - free(tmp); - return n; -} - -int convert(char* endp, int bufsiz, int n) -{ - endp = endp + bufsiz + n; - while (bufsiz > 0) { - *endp = *(endp - n); - if (*endp == '\n') { - endp--; - n--; - *endp = '\r'; - } - endp--; - bufsiz--; - } - return n; -} - -int cntcr(char* bufp, int bufsiz) -{ - int cr = 0; - - while (bufsiz > 0) { - if (*bufp == '\n') { - cr++; - } - bufp++; - bufsiz--; - } - return cr; -} diff --git a/reactos/lib/sdk/crt/io/fmode.c b/reactos/lib/sdk/crt/stdio/fmode.c similarity index 100% rename from reactos/lib/sdk/crt/io/fmode.c rename to reactos/lib/sdk/crt/stdio/fmode.c diff --git a/reactos/lib/sdk/crt/stdio/fopen.c b/reactos/lib/sdk/crt/stdio/fopen.c deleted file mode 100644 index e421474791c..00000000000 --- a/reactos/lib/sdk/crt/stdio/fopen.c +++ /dev/null @@ -1,91 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * fopen.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * 28/12/1998: Appropriated for Reactos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ - -#include - -#include - -//might change fopen(file,mode) -> fsopen(file,mode,_SH_DENYNO); - -FILE* _tfopen(const _TCHAR *file, const _TCHAR *mode) -{ - FILE *f; - int fd, rw, oflags = 0; - - if (file == 0) - return 0; - if (mode == 0) - return 0; - - f = __alloc_file(); - if (f == NULL) - return NULL; - - rw = (_tcschr(mode, '+') == NULL) ? 0 : 1; - if (_tcschr(mode, 'a')) - oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY); - if (_tcschr(mode, 'r')) - oflags = rw ? O_RDWR : O_RDONLY; - if (_tcschr(mode, 'w')) - oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY); - if (_tcschr(mode, 't')) - oflags |= O_TEXT; - else if (_tcschr(mode, 'b')) - oflags |= O_BINARY; - else - oflags |= (_fmode& (O_TEXT|O_BINARY)); - - fd = _topen(file, oflags, 0); - if (fd < 0) - return NULL; - -// msvcrt ensures that writes will end up at the end of file in append mode -// we just move the file pointer to the end of file initially - - if (_tcschr(mode, 'a')) - _lseek(fd, 0, SEEK_END); - - f->_cnt = 0; - f->_file = fd; - f->_bufsiz = 0; - if (rw) - f->_flag = _IOREAD | _IOWRT; - else if (_tcschr(mode, 'r')) - f->_flag = _IOREAD; - else - f->_flag = _IOWRT; - - if (_tcschr(mode, 't')) - f->_flag |= _IOTEXT; - else if (_tcschr(mode, 'b')) - f->_flag |= _IOBINARY; - else if (_fmode& O_BINARY) - f->_flag |= _IOBINARY; - - f->_base = f->_ptr = NULL; - return f; -} diff --git a/reactos/lib/sdk/crt/stdio/fprintf.c b/reactos/lib/sdk/crt/stdio/fprintf.c deleted file mode 100644 index 5e0c86ccbf4..00000000000 --- a/reactos/lib/sdk/crt/stdio/fprintf.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#include -#include - -/* - * @implemented - */ -int -_ftprintf(register FILE *iop, const _TCHAR *fmt, ...) -{ - int len; - _TCHAR localbuf[BUFSIZ]; - va_list a=0; - - - va_start( a, fmt ); - if (iop->_flag & _IONBF) - { - iop->_flag &= ~_IONBF; - iop->_ptr = iop->_base = (char *)localbuf; - iop->_bufsiz = BUFSIZ; - len = _vftprintf(iop,fmt,a); - fflush(iop); - iop->_flag |= _IONBF; - iop->_base = NULL; - iop->_bufsiz = 0; - iop->_cnt = 0; - } - else - len = _vftprintf(iop, fmt, a); - return ferror(iop) ? -1 : len; -} diff --git a/reactos/lib/sdk/crt/stdio/fputc.c b/reactos/lib/sdk/crt/stdio/fputc.c deleted file mode 100644 index 43b27ed6e7d..00000000000 --- a/reactos/lib/sdk/crt/stdio/fputc.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#include - -/* - * @implemented - */ -int -fputc(int c, FILE *fp) -{ - return putc(c, fp); -} - -/* - * @implemented - */ -wint_t -fputwc(wchar_t c, FILE *fp) -{ - return putwc(c,fp); -} - - diff --git a/reactos/lib/sdk/crt/stdio/fputchar.c b/reactos/lib/sdk/crt/stdio/fputchar.c deleted file mode 100644 index 533f1a8e3e2..00000000000 --- a/reactos/lib/sdk/crt/stdio/fputchar.c +++ /dev/null @@ -1,38 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * fputchar.c - * - * Copyright (C) 2002 Robert Dickenson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - - -int _fputchar(int c) -{ - return putc(c, stdout); -} - -/* - * @implemented - */ -wint_t _fputwchar(wint_t c) -{ - return putwc(c, stdout); -} diff --git a/reactos/lib/sdk/crt/stdio/fputs.c b/reactos/lib/sdk/crt/stdio/fputs.c deleted file mode 100644 index e336672858c..00000000000 --- a/reactos/lib/sdk/crt/stdio/fputs.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * fputs.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * 28/12/1998: Appropriated for Reactos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ - -#include -#include - -int -_fputts(const _TCHAR *s, FILE *f) -{ - int r = 0; - int c; - int unbuffered; - _TCHAR localbuf[BUFSIZ]; - - unbuffered = f->_flag & _IONBF; - if (unbuffered) - { - f->_flag &= ~_IONBF; - f->_ptr = f->_base = (char*)localbuf; - f->_bufsiz = BUFSIZ; - } - - while ((c = *s++)) - r = _puttc(c, f); - - if (unbuffered) - { - fflush(f); - f->_flag |= _IONBF; - f->_base = NULL; - f->_bufsiz = 0; - f->_cnt = 0; - } - - return(r); -} - diff --git a/reactos/lib/sdk/crt/stdio/fputws.c b/reactos/lib/sdk/crt/stdio/fputws.c deleted file mode 100644 index 06a0a2631f0..00000000000 --- a/reactos/lib/sdk/crt/stdio/fputws.c +++ /dev/null @@ -1,5 +0,0 @@ - -#define UNICODE -#define _UNICODE - -#include "fputs.c" diff --git a/reactos/lib/sdk/crt/stdio/fread.c b/reactos/lib/sdk/crt/stdio/fread.c deleted file mode 100644 index 1142698a4ce..00000000000 --- a/reactos/lib/sdk/crt/stdio/fread.c +++ /dev/null @@ -1,88 +0,0 @@ -#include - -/* - * @implemented - */ -size_t fread(void *vptr, size_t size, size_t count, FILE *iop) -{ - unsigned char *ptr = (unsigned char *)vptr; - size_t to_read ,n_read; - int c, copy; - - to_read = size * count; - - if (!OPEN4READING(iop)) - { - __set_errno (EINVAL); - return 0; - } - - if (!__validfp (iop) ) - { - __set_errno (EINVAL); - return 0; - } - if (feof (iop) || ferror (iop)) - return 0; - - if (vptr == NULL || to_read == 0) - return 0; - - if (iop->_base == NULL) - { - int c = _filbuf(iop); - if (c == EOF) - return 0; - *ptr++ = c; - if (--to_read == 0) - return 1; - } - - if (iop->_cnt > 0 && to_read > 0) - { - copy = min((size_t)iop->_cnt, to_read); - memcpy(ptr, iop->_ptr, copy); - ptr += copy; - iop->_ptr += copy; - iop->_cnt -= copy; - to_read -= copy; - if (to_read == 0) - return count; - } - - if (to_read > 0) - { - - if (to_read >= (size_t)iop->_bufsiz) - { - n_read = _read(_fileno(iop), ptr, to_read); - if (n_read < 0) - iop->_flag |= _IOERR; - else if (n_read == 0) - iop->_flag |= _IOEOF; - else - to_read -= n_read; - - // the file buffer is empty and there is no read ahead information anymore. - iop->_flag &= ~_IOAHEAD; - } - else - { - c = _filbuf(iop); - if (c != EOF) - { - *ptr++ = c; - to_read--; - copy = min((size_t)iop->_cnt, to_read); - memcpy(ptr, iop->_ptr, copy); - iop->_ptr += copy; - iop->_cnt -= copy; - to_read -= copy; - } - } - } - // return count - (to_read/size) - /* FIXME is this formual right ?, I copy the formula from djgpp - in our to_read or copy ? */ - return size != 0 ? count - ((to_read + size - 1) / size) : 0; -} diff --git a/reactos/lib/sdk/crt/stdio/freopen.c b/reactos/lib/sdk/crt/stdio/freopen.c deleted file mode 100644 index 134ca290a75..00000000000 --- a/reactos/lib/sdk/crt/stdio/freopen.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ - -#include - -#include - -/* - * @implemented - */ -FILE *_tfreopen(const _TCHAR *file, const _TCHAR *mode, FILE *f) -{ - int fd, rw, oflags=0; - _TCHAR tbchar; - - if (file == 0 || mode == 0 || f == 0) - return 0; - - rw = (mode[1] == '+'); - - fclose(f); - - switch (*mode) { - case 'a': - oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY); - break; - case 'r': - oflags = rw ? O_RDWR : O_RDONLY; - break; - case 'w': - oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY); - break; - default: - return NULL; - } - if (mode[1] == '+') - tbchar = mode[2]; - else - tbchar = mode[1]; - if (tbchar == 't') - oflags |= O_TEXT; - else if (tbchar == 'b') - oflags |= O_BINARY; - else - oflags |= (_fmode& (O_TEXT|O_BINARY)); - - fd = _topen(file, oflags, 0666); - if (fd < 0) - return NULL; - - if (*mode == 'a') - _lseek(fd, 0, SEEK_END); - - f->_cnt = 0; - f->_file = fd; - f->_bufsiz = 0; - if (rw) - f->_flag = _IOREAD | _IOWRT; - else if (*mode == 'r') - f->_flag = _IOREAD; - else - f->_flag = _IOWRT; - - f->_base = f->_ptr = NULL; - return f; -} - diff --git a/reactos/lib/sdk/crt/stdio/fseek.c b/reactos/lib/sdk/crt/stdio/fseek.c deleted file mode 100644 index d9204810e2b..00000000000 --- a/reactos/lib/sdk/crt/stdio/fseek.c +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (C) 1997 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 */ - -#include - -/* - * @implemented - */ -int fseek(FILE *f, long offset, int ptrname) -{ - long p = -1; /* can't happen? */ - if ( f == NULL ) { - __set_errno (EINVAL); - return -1; - } - - f->_flag &= ~_IOEOF; - if (!OPEN4WRITING(f)) - { - if (f->_base && !(f->_flag & _IONBF)) - { - p = ftell(f); - if (ptrname == SEEK_CUR) - { - offset += p; - ptrname = SEEK_SET; - } - /* check if the target position is in the buffer and - optimize seek by moving inside the buffer */ - if (ptrname == SEEK_SET && (f->_flag & (_IOUNGETC|_IOREAD|_IOWRT )) == 0 - && p-offset <= f->_ptr-f->_base && offset-p <= f->_cnt) - { - f->_ptr+=offset-p; - f->_cnt+=p-offset; - return 0; - } - } - - p = _lseek(_fileno(f), offset, ptrname); - f->_cnt = 0; - f->_ptr = f->_base; - f->_flag &= ~_IOUNGETC; - } - else - { - p = fflush(f); - return _lseek(_fileno(f), offset, ptrname) == -1 || p == EOF ? - -1 : 0; - } - return p==-1 ? -1 : 0; -} diff --git a/reactos/lib/sdk/crt/stdio/fsetpos.c b/reactos/lib/sdk/crt/stdio/fsetpos.c deleted file mode 100644 index 1d2e3a25104..00000000000 --- a/reactos/lib/sdk/crt/stdio/fsetpos.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int fsetpos(FILE *stream,const fpos_t *pos) -{ - if (stream && pos) - { - fseek(stream, (long)(*pos), SEEK_SET); - return 0; - } - __set_errno(EFAULT); - return -1; -} diff --git a/reactos/lib/sdk/crt/stdio/fsopen.c b/reactos/lib/sdk/crt/stdio/fsopen.c deleted file mode 100644 index 88c13aa8c6e..00000000000 --- a/reactos/lib/sdk/crt/stdio/fsopen.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/stdio/fsopen.c - * PURPOSE: Checks for keyboard hits - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ - -#include - -#include -#include -#include - - -/* - * @implemented - */ -FILE* _tfsopen(const _TCHAR *file, const _TCHAR *mode, int shflag) -{ - FILE *f; - int fd, rw, oflags = 0; - _TCHAR tbchar; - - int shf; - - if (file == 0) - return 0; - if (mode == 0) - return 0; - - f = __alloc_file(); - if (f == NULL) - return NULL; - - rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+')); - - switch (*mode) - { - case 'a': - oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY); - break; - case 'r': - oflags = rw ? O_RDWR : O_RDONLY; - break; - case 'w': - oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY); - break; - default: - return (NULL); - } - if (mode[1] == '+') - tbchar = mode[2]; - else - tbchar = mode[1]; - if (tbchar == 't') - oflags |= O_TEXT; - else if (tbchar == 'b') - oflags |= O_BINARY; - else - oflags |= (_fmode& (O_TEXT|O_BINARY)); - - 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 = _topen(file, oflags, shf); - if (fd < 0) - return NULL; - -// msvcrt ensures that writes will end up at the end of file in append mode -// we just move the file pointer to the end of file initially - if (*mode == 'a') - _lseek(fd, 0, SEEK_END); - - f->_cnt = 0; - f->_file = fd; - f->_bufsiz = 0; - if (rw) - f->_flag = _IOREAD | _IOWRT; - else if (*mode == 'r') - f->_flag = _IOREAD; - else - f->_flag = _IOWRT; - - f->_base = f->_ptr = NULL; - return f; -} - diff --git a/reactos/lib/sdk/crt/stdio/ftell.c b/reactos/lib/sdk/crt/stdio/ftell.c deleted file mode 100644 index aa7b4e939ef..00000000000 --- a/reactos/lib/sdk/crt/stdio/ftell.c +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ - -#include - -/* - * @implemented - */ -long ftell(FILE *f) -{ - long tres; - int adjust=0; - - if (!f) - { - __set_errno(EBADF); - return -1; - } - - if (f->_cnt < 0) - f->_cnt = 0; - else if (f->_flag&(_IOWRT)) - { - if (f->_base && (f->_flag&_IONBF)==0) - adjust = f->_ptr - f->_base; - } - else if (f->_flag&_IOREAD) - { - adjust = - f->_cnt; - } - else - return -1; - - tres = _lseek(_fileno(f), 0L, SEEK_CUR); - if (tres<0) - return tres; - tres += adjust; - - //f->_cnt = f->_bufsiz - tres; - //f->_ptr = f->_base + tres; - - return tres; -} diff --git a/reactos/lib/sdk/crt/stdio/fwalk.c b/reactos/lib/sdk/crt/stdio/fwalk.c deleted file mode 100644 index fc3a70c2135..00000000000 --- a/reactos/lib/sdk/crt/stdio/fwalk.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -// not exported by msvcrt or crtdll -__file_rec *__file_rec_list; - -void _fwalk(void (*func)(FILE *)) -{ - __file_rec *fr; - int i; - - for (fr=__file_rec_list; fr; fr=fr->next) - for (i=0; icount; i++) - if (fr->files[i]->_flag) - func(fr->files[i]); -} diff --git a/reactos/lib/sdk/crt/stdio/fwprintf.c b/reactos/lib/sdk/crt/stdio/fwprintf.c deleted file mode 100644 index e25b3bcc387..00000000000 --- a/reactos/lib/sdk/crt/stdio/fwprintf.c +++ /dev/null @@ -1,4 +0,0 @@ -#define UNICODE -#define _UNICODE - -#include "fprintf.c" diff --git a/reactos/lib/sdk/crt/stdio/fwrite.c b/reactos/lib/sdk/crt/stdio/fwrite.c deleted file mode 100644 index 486902e1d06..00000000000 --- a/reactos/lib/sdk/crt/stdio/fwrite.c +++ /dev/null @@ -1,107 +0,0 @@ -#include - -/* - * @implemented - */ -size_t fwrite(const void *vptr, size_t size, size_t count, FILE *iop) -{ - size_t to_write, n_written; - unsigned char *ptr = (unsigned char *)vptr; - int copy; - - TRACE("fwrite(%x, %d, %d, %x)", vptr, size, count, iop); - - to_write = size*count; - if (!OPEN4WRITING(iop)) - { - __set_errno (EINVAL); - return(0); - } - - if (iop == NULL) - { - __set_errno (EINVAL); - return(0); - } - - if (ferror (iop)) - return(0); - if (vptr == NULL || to_write == 0) - return(0); - - if (iop->_base == NULL && !(iop->_flag&_IONBF)) - { - if (EOF == _flsbuf(*ptr++, iop)) - return(0); - if (--to_write == 0) - return(1); - } - - if (iop->_flag & _IO_LBF) - { - while (to_write > 0) - { - if (EOF == putc(*ptr++, iop)) - { - iop->_flag |= _IOERR; - break; - } - to_write--; - } - } - else - { - if (iop->_cnt > 0 && to_write > 0) - { - copy = min((size_t)iop->_cnt, to_write); - memcpy(iop->_ptr, ptr, copy); - ptr += copy; - iop->_ptr += copy; - iop->_cnt -= copy; - to_write -= copy; - iop->_flag |= _IODIRTY; - } - - if (to_write > 0) - { - // if the buffer is dirty it will have to be written now - // otherwise the file pointer won't match anymore. - fflush(iop); - if (to_write >= (size_t)iop->_bufsiz) - { - while (to_write > 0) - { - n_written = _write(_fileno(iop), ptr, to_write); - if (n_written <= 0) - { - iop->_flag |= _IOERR; - break; - } - to_write -= n_written; - ptr += n_written; - } - - // check to see if this will work with in combination with ungetc - - // the file buffer is empty and there is no read ahead information anymore. - iop->_flag &= ~_IOAHEAD; - } - else - { - if (EOF != _flsbuf(*ptr++, iop)) - { - if (--to_write > 0) - { - memcpy(iop->_ptr, ptr, to_write); - iop->_ptr += to_write; - iop->_cnt -= to_write; - iop->_flag |= _IODIRTY; - return(count); - } - } - } - } - } - - return(count - (to_write/size)); -} diff --git a/reactos/lib/sdk/crt/stdio/getc.c b/reactos/lib/sdk/crt/stdio/getc.c deleted file mode 100644 index acf2afca05f..00000000000 --- a/reactos/lib/sdk/crt/stdio/getc.c +++ /dev/null @@ -1,130 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * getc.c - * - * Copyright (C) 2002 Robert Dickenson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -//getc can be a macro -#undef getc -#undef getwc - -#ifndef MB_CUR_MAX -#define MB_CUR_MAX 10 -#endif - -int getc(FILE *fp) -{ - int c = -1; - - // check for invalid stream - if ( !__validfp (fp) ) { - __set_errno(EINVAL); - return EOF; - } - // check for read access on stream - if ( !OPEN4READING(fp) ) { - __set_errno(EINVAL); - return EOF; - } - if(fp->_cnt > 0) { - fp->_cnt--; - c = (int)(*fp->_ptr++ & 0377); - } else { - c = _filbuf(fp); - } - return c; -} - -/* - * @implemented - */ -wint_t getwc(FILE *fp) -{ - wint_t c = -1; - - // check for invalid stream - if (!__validfp(fp)) { - __set_errno(EINVAL); - return WEOF; - } - // check for read access on stream -//#define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD ) ) - if (!OPEN4READING(fp)) { - __set_errno(EINVAL); - return WEOF; - } - // might check on multi bytes if text mode - if (fp->_flag & _IOBINARY) { - if (fp->_cnt > 1) { - fp->_cnt -= sizeof(wchar_t); - c = *((wchar_t*)fp->_ptr); - fp->_ptr += sizeof(wchar_t); - } else { - c = _filwbuf(fp); - // need to fix by one values of fp->_ptr and fp->_cnt - fp->_ptr++; - fp->_cnt--; - } - } else { -#if 0 - BOOL get_bytes = 0; - int mb_cnt = 0; - int found_cr = 0; - //int count; - char mbchar[MB_CUR_MAX]; - - do { - if (fp->_cnt > 0) { - fp->_cnt--; - mbchar[mb_cnt] = *fp->_ptr++ & 0377; - } else { - mbchar[mb_cnt] = _filbuf(fp); - } - if (isleadbyte(mbchar[mb_cnt])) { - get_bytes = 1; - } else { - get_bytes = 0; - } - if (_ismbblead(mbchar[mb_cnt])) { - } - ++mb_cnt; - //} - } while (get_bytes); - - // Convert a multibyte character to a corresponding wide character. - mb_cnt = mbtowc(&c, mbchar, mb_cnt); - if (mb_cnt == -1) { - fp->_flag |= _IOERR; - return WEOF; - } -#else - if (fp->_cnt > 0) { - fp->_cnt--; - c = *fp->_ptr++ &0377; - } else { - c = _filbuf(fp); - } -#endif - } - return c; -} - diff --git a/reactos/lib/sdk/crt/stdio/getchar.c b/reactos/lib/sdk/crt/stdio/getchar.c deleted file mode 100644 index 3fcd0d80f77..00000000000 --- a/reactos/lib/sdk/crt/stdio/getchar.c +++ /dev/null @@ -1,44 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * getchar.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * 28/12/1998: Appropriated for Reactos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include - -#undef getchar -#undef getwchar - -int -getchar(void) -{ - return getc(stdin); -} - -/* - * @implemented - */ -wint_t -getwchar(void) -{ - return getwc(stdin); -} diff --git a/reactos/lib/sdk/crt/stdio/gets.c b/reactos/lib/sdk/crt/stdio/gets.c deleted file mode 100644 index 53251c74e20..00000000000 --- a/reactos/lib/sdk/crt/stdio/gets.c +++ /dev/null @@ -1,144 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * gets.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * 28/12/1998: Appropriated for Reactos - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ - -#include - -char* gets(char* s) -{ - int c; - char* cs; - - cs = s; - while ((c = getc(stdin)) != '\n' && c != EOF) - *cs++ = c; - if (c == EOF && cs == s) - return NULL; - *cs++ = '\0'; - return s; -} - -#ifndef WEOF -#define WEOF (wchar_t)(0xFFFF) -#endif - -/* - * Get a line from the stdin stream. - * - * @implemented - */ -wchar_t* _getws(wchar_t* s) -{ - wchar_t c; - wchar_t* cs; - - cs = s; - while ((c = getwc(stdin)) != L'\n' && c != WEOF) - *cs++ = c; - if (c == WEOF && cs == s) - return NULL; - *cs++ = L'\0'; - return s; -} - -#if 0 -/* Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#include - -link_warning (gets, "the `gets' function is dangerous and should not be used.") - - -/* Read a newline-terminated multibyte string from stdin into S, - removing the trailing newline. Return S or NULL. */ - -char * -gets (s) - char *s; -{ - register char *p = s; - register int c; - FILE *stream = stdin; - int l; - - if (!__validfp (stream) || p == NULL) - { - __set_errno (EINVAL); - return NULL; - } - - if (feof (stream) || ferror (stream)) - return NULL; - - while ((c = getc(stdin)) != EOF) { - if (c == '\n') - break; - if ( isascii(c) ) - *cs++ = c; -#ifdef _MULTIBYTE - else if ( isleadbyte(c) ) { - l = mblen(c); - while(l > 0 ) { - c = getchar(); - if ( isleadbyte(c) || c == EOF ) - return NULL; // encoding error - *cs++ = c; - l--; - } - } -#endif - else - return NULL; // suspicious input - } - - *p = '\0'; - - /* Return null if we had an error, or if we got EOF - before writing any characters. */ - - if (ferror (stream) || (feof (stream) && p == s)) - return NULL; - - return s; -} - -#endif diff --git a/reactos/lib/sdk/crt/stdio/getw.c b/reactos/lib/sdk/crt/stdio/getw.c deleted file mode 100644 index 2bc42696e17..00000000000 --- a/reactos/lib/sdk/crt/stdio/getw.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 1991 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#include - -/* - * Read a word (int) from STREAM. - * - * @implemented - */ -int _getw(FILE *stream) -{ - int w; - - /* Is there a better way? */ - if (fread( &w, sizeof(w), 1, stream) != 1) { - // EOF is a legitimate integer value so users must - // check feof or ferror to verify an EOF return. - return(EOF); - } - return(w); -} - diff --git a/reactos/lib/sdk/crt/stdio/lnx_sprintf.c b/reactos/lib/sdk/crt/stdio/lnx_sprintf.c new file mode 100644 index 00000000000..efef2b6d22d --- /dev/null +++ b/reactos/lib/sdk/crt/stdio/lnx_sprintf.c @@ -0,0 +1,28 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: LGPL - See COPYING in the top level directory + * FILE: lib/sdk/crt/stdio/lnx_sprintf.c + * PURPOSE: Base implementation of sprintf + * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org) + */ + +#include + +#include +#include + +/* + * @implemented + */ +int +lnx_sprintf(_TCHAR *str, const _TCHAR *fmt, ...) +{ + va_list arg; + int done; + + va_start (arg, fmt); + done = lnx__vstprintf (str, fmt, arg); + va_end (arg); + return done; +} + diff --git a/reactos/lib/sdk/crt/stdio/vfprintf.c b/reactos/lib/sdk/crt/stdio/lnx_vfprintf.c similarity index 99% rename from reactos/lib/sdk/crt/stdio/vfprintf.c rename to reactos/lib/sdk/crt/stdio/lnx_vfprintf.c index bf76e8298c8..c2a288496d6 100644 --- a/reactos/lib/sdk/crt/stdio/vfprintf.c +++ b/reactos/lib/sdk/crt/stdio/lnx_vfprintf.c @@ -7,7 +7,7 @@ int __vfprintf(FILE*, const char*, va_list); /* * @implemented */ -int vfprintf(FILE* f, const char* fmt, va_list ap) +int lnx_vfprintf(FILE* f, const char* fmt, va_list ap) { int len; char localbuf[BUFSIZ]; diff --git a/reactos/lib/sdk/crt/stdio/vfwprint.c b/reactos/lib/sdk/crt/stdio/lnx_vfwprint.c similarity index 99% rename from reactos/lib/sdk/crt/stdio/vfwprint.c rename to reactos/lib/sdk/crt/stdio/lnx_vfwprint.c index 03b542a49cd..c6a494dd1f6 100644 --- a/reactos/lib/sdk/crt/stdio/vfwprint.c +++ b/reactos/lib/sdk/crt/stdio/lnx_vfwprint.c @@ -2,6 +2,7 @@ #include + int __vfwprintf(FILE *fp, const wchar_t *fmt0, va_list argp); @@ -10,7 +11,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt0, va_list argp); * @implemented */ int -vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) +lnx_vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) { int len; wchar_t localbuf[BUFSIZ]; diff --git a/reactos/lib/sdk/crt/stdio/vsprintf.c b/reactos/lib/sdk/crt/stdio/lnx_vsprintf.c similarity index 72% rename from reactos/lib/sdk/crt/stdio/vsprintf.c rename to reactos/lib/sdk/crt/stdio/lnx_vsprintf.c index 1a463ca2d44..32fda2185ff 100644 --- a/reactos/lib/sdk/crt/stdio/vsprintf.c +++ b/reactos/lib/sdk/crt/stdio/lnx_vsprintf.c @@ -1,13 +1,12 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include - #include /* * @implemented */ int -_vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap) +lnx__vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap) { FILE f = {0}; int len; @@ -16,7 +15,7 @@ _vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap) f._ptr = (char*)str; f._cnt = INT_MAX; f._file = -1; - len = _vftprintf(&f,fmt, ap); + len = lnx_vftprintf(&f,fmt, ap); *(_TCHAR*)f._ptr = 0; return len; } @@ -26,7 +25,7 @@ _vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap) * @implemented */ int -_vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap) +lnx__vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap) { FILE f = {0}; int len; @@ -35,7 +34,7 @@ _vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap) f._ptr = (char*)str; f._cnt = maxlen * sizeof(_TCHAR); f._file = -1; - len = _vftprintf(&f,fmt, ap); + len = lnx_vftprintf(&f,fmt, ap); // what if the buffer is full ?? *(_TCHAR *)f._ptr = 0; return len; diff --git a/reactos/lib/sdk/crt/io/wchmod.c b/reactos/lib/sdk/crt/stdio/lnx_vswprintf.c similarity index 56% rename from reactos/lib/sdk/crt/io/wchmod.c rename to reactos/lib/sdk/crt/stdio/lnx_vswprintf.c index 1a81c9e2a41..184d8ee6615 100644 --- a/reactos/lib/sdk/crt/io/wchmod.c +++ b/reactos/lib/sdk/crt/stdio/lnx_vswprintf.c @@ -1,4 +1,4 @@ -#define _UNICODE #define UNICODE +#define _UNICODE -#include "chmod.c" +#include "lnx_vsprintf.c" diff --git a/reactos/lib/sdk/crt/stdio/popen.c b/reactos/lib/sdk/crt/stdio/popen.c index 07a4aa3094b..bb6f93c3660 100644 --- a/reactos/lib/sdk/crt/stdio/popen.c +++ b/reactos/lib/sdk/crt/stdio/popen.c @@ -18,6 +18,10 @@ #endif #define MK_STR(s) #s + +int alloc_fd(HANDLE hand, int flag); //FIXME: Remove +unsigned split_oflags(unsigned oflags); //FIXME: Remove + /* * @implemented */ @@ -128,8 +132,8 @@ int _pclose (FILE *pp) TRACE("_pclose(%x)",pp); fclose(pp); - if (!TerminateProcess(pp->_tmpfname ,0)) - return( -1 ); + //if (!TerminateProcess(pp->_tmpfname ,0)) + // return( -1 ); return( 0 ); } diff --git a/reactos/lib/sdk/crt/stdio/printf.c b/reactos/lib/sdk/crt/stdio/printf.c deleted file mode 100644 index f68e40fdcc3..00000000000 --- a/reactos/lib/sdk/crt/stdio/printf.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include - -#include -#include - -/* - * @implemented - */ -int _tprintf(const _TCHAR* format, ...) -{ - va_list arg; - int done; - - va_start(arg, format); - done = _vtprintf(format, arg); - va_end(arg); - return done; -} diff --git a/reactos/lib/sdk/crt/stdio/putc.c b/reactos/lib/sdk/crt/stdio/putc.c deleted file mode 100644 index 71c0fd0854b..00000000000 --- a/reactos/lib/sdk/crt/stdio/putc.c +++ /dev/null @@ -1,142 +0,0 @@ -/* $Id$ - * - * ReactOS msvcrt library - * - * putc.c - * - * Copyright (C) 2002 Robert Dickenson - * - * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ - -#include - -// putc can be a macro -#undef putc -#undef putwc - -#ifndef MB_CUR_MAX_CONST -#define MB_CUR_MAX_CONST 10 -#endif - -int putc(int c, FILE* fp) -{ - // valid stream macro should check that fp is dword aligned - if (!__validfp(fp)) { - __set_errno(EINVAL); - return EOF; - } - // check for write access on fp - if (!OPEN4WRITING(fp)) { - __set_errno(EINVAL); - return EOF; - } - fp->_flag |= _IODIRTY; - if (fp->_cnt > 0) { - fp->_cnt--; - *(fp)->_ptr++ = (unsigned char)c; - return (int)(unsigned char)c; - } else { - return _flsbuf((unsigned char)c, fp); - } - return EOF; -} - -//wint_t putwc(wint_t c, FILE* fp) -/* - * @implemented - */ -wint_t putwc(wint_t c, FILE* fp) -{ - // valid stream macro should check that fp is dword aligned - if (!__validfp(fp)) { - __set_errno(EINVAL); - return WEOF; - } - // check for write access on fp - if (!OPEN4WRITING(fp)) { - __set_errno(EINVAL); - return WEOF; - } - // might check on multi bytes if text mode - if (fp->_flag & _IOBINARY) { - //if (1) { - - fp->_flag |= _IODIRTY; - if (fp->_cnt > 0) { - fp->_cnt -= sizeof(wchar_t); - //*((wchar_t*)(fp->_ptr))++ = c; - *((wchar_t*)(fp->_ptr)) = c; - fp->_ptr += sizeof(wchar_t); - return (wint_t)c; - } else { -#if 1 - wint_t result; - result = _flsbuf(c, fp); - if (result == (wint_t)EOF) - return WEOF; - result = _flsbuf((int)(c >> 8), fp); - if (result == (wint_t)EOF) - return WEOF; - return result; -#else - return _flswbuf(c, fp); -#endif - } - - } else { -#if 0 - int i; - int mb_cnt; - char mbchar[MB_CUR_MAX_CONST]; - - // Convert wide character to the corresponding multibyte character. - mb_cnt = wctomb(mbchar, (wchar_t)c); - if (mb_cnt == -1) { - fp->_flag |= _IOERR; - return WEOF; - } - if (mb_cnt > MB_CUR_MAX_CONST) { - // BARF(); - } - for (i = 0; i < mb_cnt; i++) { - fp->_flag |= _IODIRTY; - if (fp->_cnt > 0) { - fp->_cnt--; - *(fp)->_ptr++ = (unsigned char)mbchar[i]; - } else { - if (_flsbuf((unsigned char)mbchar[i], fp) == EOF) { - return WEOF; - } - } - } -#else - fp->_flag |= _IODIRTY; - if (fp->_cnt > 0) { - fp->_cnt--; - *(fp)->_ptr++ = (unsigned char)c; - } else { - if (_flsbuf(c, fp) == EOF) { - return WEOF; - } - } -#endif - return c; - } - return WEOF; -} diff --git a/reactos/lib/sdk/crt/stdio/putchar.c b/reactos/lib/sdk/crt/stdio/putchar.c deleted file mode 100644 index cc2b43e45d5..00000000000 --- a/reactos/lib/sdk/crt/stdio/putchar.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/stdio/putchar.c - * PURPOSE: Writes a character to stdout - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ -#include - -#include - -#undef putc -#undef putchar -#undef putwc -#undef putwchar - -/* - * @implemented - */ -_TINT _puttchar(_TINT c) -{ - _TINT r = _puttc(c, stdout); - if (stdout->_flag & _IO_LBF) - fflush(stdout); - return r; -} - diff --git a/reactos/lib/sdk/crt/stdio/puts.c b/reactos/lib/sdk/crt/stdio/puts.c deleted file mode 100644 index 4171aa006d1..00000000000 --- a/reactos/lib/sdk/crt/stdio/puts.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#undef putchar -#undef putwchar - - -/* - * @implemented - */ -int puts(const char *s) -{ - int c; - - while ((c = *s++)) { - putchar(c); - } - return putchar('\n'); -} - -/* - * @implemented - */ -int _putws(const wchar_t *s) -{ - wint_t c; - - while ((c = *s++)) { - putwchar(c); - } - return putwchar(L'\n'); -} diff --git a/reactos/lib/sdk/crt/stdio/putw.c b/reactos/lib/sdk/crt/stdio/putw.c deleted file mode 100644 index bc2950970df..00000000000 --- a/reactos/lib/sdk/crt/stdio/putw.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1991 Free Software Foundation, Inc. - * This file is part of the GNU C Library. - * - * The GNU C Library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * The GNU C Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with the GNU C Library; see the file COPYING.LIB. If - * not, write to the Free Software Foundation, Inc., 675 Mass Ave, - * Cambridge, MA 02139, USA. */ - -#include - -/* - * Write the word (int) W to STREAM. - * - * @implemented - */ -int _putw(int w,FILE *stream) -{ - /* Is there a better way? */ - if (fwrite( &w, sizeof(w), 1, stream) < 1) - return(EOF); - return(0); -} diff --git a/reactos/lib/sdk/crt/stdio/putwchar.c b/reactos/lib/sdk/crt/stdio/putwchar.c deleted file mode 100644 index e6f31b8add2..00000000000 --- a/reactos/lib/sdk/crt/stdio/putwchar.c +++ /dev/null @@ -1,4 +0,0 @@ -#define UNICODE -#define _UNICODE - -#include "putchar.c" diff --git a/reactos/lib/sdk/crt/stdio/remove.c b/reactos/lib/sdk/crt/stdio/remove.c deleted file mode 100644 index 17b472d6d47..00000000000 --- a/reactos/lib/sdk/crt/stdio/remove.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -#ifdef _UNICODE - #define sT "S" -#else - #define sT "s" -#endif - -#define MK_STR(s) #s - -/* - * @implemented - */ -int _tremove(const _TCHAR *fn) -{ - int result = 0; - TRACE(MK_STR(_tremove)"('%"sT"')\n", fn); - if (!DeleteFile(fn)) - result = -1; - TRACE("%d\n", result); - return result; -} - - diff --git a/reactos/lib/sdk/crt/stdio/rename.c b/reactos/lib/sdk/crt/stdio/rename.c deleted file mode 100644 index 8f4abcae7ea..00000000000 --- a/reactos/lib/sdk/crt/stdio/rename.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Created - */ - -#include -#include - -/* - * @implemented - */ -int _trename(const _TCHAR* old_, const _TCHAR* new_) -{ - if (old_ == NULL || new_ == NULL) - return -1; - - if (!MoveFile(old_, new_)) - return -1; - - return 0; -} diff --git a/reactos/lib/sdk/crt/stdio/rewind.c b/reactos/lib/sdk/crt/stdio/rewind.c deleted file mode 100644 index 2c1facd695a..00000000000 --- a/reactos/lib/sdk/crt/stdio/rewind.c +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -void rewind(FILE *f) -{ - fflush(f); - _lseek(_fileno(f), 0L, SEEK_SET); - f->_cnt = 0; - f->_ptr = f->_base; - f->_flag &= ~(_IOERR|_IOEOF|_IOAHEAD); -} diff --git a/reactos/lib/sdk/crt/stdio/rmtmp.c b/reactos/lib/sdk/crt/stdio/rmtmp.c deleted file mode 100644 index e9e343c12a7..00000000000 --- a/reactos/lib/sdk/crt/stdio/rmtmp.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/stdio/rmtmp.c - * PURPOSE: remove temporary files in current directory - * PROGRAMMER: Ariadne - * UPDATE HISTORY: - * Created 19/01/99 - * NOTE Not tested. - */ -#include - -// should be replace by a closure of the tmp files -extern __file_rec *__file_rec_list; - -int _rmtmp( void ) -{ -/* -loop files and check for _tmpfname -*/ - __file_rec *fr = __file_rec_list; - __file_rec **last_fr = &__file_rec_list; - - int total_closed = 0; - 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]->_tmpfname != NULL) { - if ( _access(fr->files[i]->_tmpfname ,W_OK) ) { - strcpy(temp_name,fr->files[i]->_tmpfname ); - 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; -} diff --git a/reactos/lib/sdk/crt/stdio/setbuf.c b/reactos/lib/sdk/crt/stdio/setbuf.c deleted file mode 100644 index 48b27cb7ad9..00000000000 --- a/reactos/lib/sdk/crt/stdio/setbuf.c +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -void setbuf(FILE *f, char *buf) -{ - if (buf) - setvbuf(f, buf, _IOFBF, BUFSIZ); - else - setvbuf(f, 0, _IONBF, BUFSIZ); -} diff --git a/reactos/lib/sdk/crt/stdio/setvbuf.c b/reactos/lib/sdk/crt/stdio/setvbuf.c deleted file mode 100644 index bcaa10a5c1c..00000000000 --- a/reactos/lib/sdk/crt/stdio/setvbuf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -/* - * @implemented - */ -int setvbuf(FILE *f, char *buf, int type, size_t len) -{ - int mine=0; - if (!__validfp (f) ) { - __set_errno (EINVAL); - return 0; - } - if ( f->_base != NULL ) - fflush(f); - /* Cannot use _IOLBF as flag value because _IOLBF is equal to _IOSTRG */ - if (type == _IOLBF) - type = _IO_LBF; - - switch (type) - { - case _IOFBF: - case _IO_LBF: - if (len <= 0) { - __set_errno (EINVAL); - return EOF; - } - if (buf == 0) - { - buf = (char *)malloc(len+1); - if (buf == NULL) { - __set_errno (ENOMEM); - return -1; - } - mine = 1; - } - /* FALLTHROUGH */ - case _IONBF: - if (f->_base != NULL && f->_flag & _IOMYBUF) - free(f->_base); - f->_cnt = 0; - - f->_flag &= ~(_IONBF|_IOFBF|_IO_LBF|_IOUNGETC); - f->_flag |= type; - if (type != _IONBF) - { - if (mine) - f->_flag |= _IOMYBUF; - f->_ptr = f->_base = buf; - f->_bufsiz = len; - } - else - { - f->_base = 0; - f->_bufsiz = 0; - } - return 0; - default: - __set_errno (EINVAL); - return EOF; - } -} diff --git a/reactos/lib/sdk/crt/stdio/sprintf.c b/reactos/lib/sdk/crt/stdio/sprintf.c deleted file mode 100644 index 04c185bebc1..00000000000 --- a/reactos/lib/sdk/crt/stdio/sprintf.c +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ - -/* Copyright (C) 1991, 1995 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#include - -#include -#include - -#undef sprintf -#undef wsprintf - -/* - * @implemented - */ -int -crt_sprintf(_TCHAR *str, const _TCHAR *fmt, ...) -{ - va_list arg; - int done; - - va_start (arg, fmt); - done = _vstprintf (str, fmt, arg); - va_end (arg); - return done; -} - - -/* Write formatted output into S, according to the format - string FORMAT, writing no more than MAXLEN characters. */ -/* VARARGS3 */ -int -crt__snprintf (_TCHAR *s, size_t maxlen,const _TCHAR *format, ...) -{ - va_list arg; - int done; - - va_start (arg, format); - done = _vsntprintf(s, maxlen, format, arg); - va_end (arg); - - return done; -} - - diff --git a/reactos/lib/sdk/crt/stdio/stdhnd.c b/reactos/lib/sdk/crt/stdio/stdhnd.c deleted file mode 100644 index 3df13a18207..00000000000 --- a/reactos/lib/sdk/crt/stdio/stdhnd.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include - -FILE _iob[20] = -{ - // stdin -{ - NULL, 0, NULL, - _IOREAD | _IO_LBF , - 0, 0,0, NULL -}, - // stdout -{ - NULL, 0, NULL, - _IOWRT | _IO_LBF |_IOSTRG, - 1,0,0, NULL -}, - // stderr -{ - NULL, 0, NULL, - _IOWRT | _IONBF, - 2,0,0, NULL -} -}; - -/* - * @implemented - */ -FILE *__p__iob(void) -{ - return &_iob[0]; -} diff --git a/reactos/lib/sdk/crt/stdio/swprintf.c b/reactos/lib/sdk/crt/stdio/swprintf.c deleted file mode 100644 index a92f30e0b1d..00000000000 --- a/reactos/lib/sdk/crt/stdio/swprintf.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ - -/* Copyright (C) 1991, 1995 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#define UNICODE -#define _UNICODE -#include -#include -#include - -#undef sprintf -#undef wsprintf - -int -crt_swprintf(_TCHAR *str, const _TCHAR *fmt, ...) -{ - va_list arg; - int done; - - va_start (arg, fmt); - done = _vstprintf (str, fmt, arg); - va_end (arg); - return done; -} - - -/* Write formatted output into S, according to the format - string FORMAT, writing no more than MAXLEN characters. */ -/* VARARGS3 */ -int -crt__snwprintf (_TCHAR *s, size_t maxlen,const _TCHAR *format, ...) -{ - va_list arg; - int done; - - va_start (arg, format); - done = _vsntprintf(s, maxlen, format, arg); - va_end (arg); - - return done; -} diff --git a/reactos/lib/sdk/crt/stdio/tempnam.c b/reactos/lib/sdk/crt/stdio/tempnam.c deleted file mode 100644 index 075b702f874..00000000000 --- a/reactos/lib/sdk/crt/stdio/tempnam.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -/* - * @implemented - */ -_TCHAR* _ttempnam(const _TCHAR* dir,const _TCHAR* prefix) -{ - _TCHAR* TempFileName = malloc(MAX_PATH*sizeof(_TCHAR)); - _TCHAR* d; - - if (dir == NULL) - d = _tgetenv(_T("TMP")); - else - d = (_TCHAR*)dir; - -#ifdef _MSVCRT_LIB_ // TODO: check on difference? - if (GetTempFileName(d, prefix, 1, TempFileName) == 0) { -#else// TODO: FIXME: review which is correct - if (GetTempFileName(d, prefix, 0, TempFileName) == 0) { -#endif /*_MSVCRT_LIB_*/ - - free(TempFileName); - return NULL; - } - - return TempFileName; -} diff --git a/reactos/lib/sdk/crt/stdio/tmpfile.c b/reactos/lib/sdk/crt/stdio/tmpfile.c deleted file mode 100644 index 0cfdf7b8986..00000000000 --- a/reactos/lib/sdk/crt/stdio/tmpfile.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -#include - -#include - -FILE * __alloc_file(void); - -/* - * @implemented - */ -FILE * -tmpfile(void) -{ - int temp_fd; - FILE *f; - char *temp_name = tmpnam(0); - char *n_t_r = (char *)malloc(L_tmpnam); - - if (!n_t_r) - return 0; - - /* We could have a race condition, whereby another program - (in another virtual machine, or if the temporary file is - in a directory which is shared via a network) opens the - file returned by `tmpnam' between the call above and the - moment when we actually open the file below. This loop - retries the call to `tmpnam' until we actually succeed - to create the file which didn't exist before. */ - do { - // __set_errno ( 0 ); - temp_fd = _open(temp_name, 0, SH_DENYRW); - // if ( *_errno() == ENOENT ) -// break; - } while (temp_fd == -1 && (temp_name = tmpnam(0)) != 0); - - if (temp_name == 0) - return 0; - - /* This should have been fdopen(temp_fd, "wb+"), but `fdopen' - is non-ANSI. So we need to dump some of its guts here. Sigh... */ - f = __alloc_file(); - if (f) - { - f->_file = temp_fd; - f->_cnt = 0; - f->_bufsiz = 0; - f->_flag = _IORMONCL | _IOREAD | _IOWRT; - f->_tmpfname = n_t_r; - strcpy(f->_tmpfname , temp_name); - f->_base = f->_ptr = NULL; - } - else - { - _close(temp_fd); - remove(temp_name); - free(n_t_r); - } - return f; -} diff --git a/reactos/lib/sdk/crt/stdio/tmpnam.c b/reactos/lib/sdk/crt/stdio/tmpnam.c deleted file mode 100644 index 551ec8c4606..00000000000 --- a/reactos/lib/sdk/crt/stdio/tmpnam.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -/* - * @implemented - */ -_TCHAR* _ttmpnam(_TCHAR* s) -{ - _TCHAR PathName[MAX_PATH]; - static _TCHAR static_buf[MAX_PATH]; - - GetTempPath(MAX_PATH, PathName); - GetTempFileName(PathName, _T("ARI"), 007, static_buf); - _tcscpy(s,static_buf); - - return s; -} diff --git a/reactos/lib/sdk/crt/stdio/ungetc.c b/reactos/lib/sdk/crt/stdio/ungetc.c deleted file mode 100644 index c3018b904b4..00000000000 --- a/reactos/lib/sdk/crt/stdio/ungetc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ -/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -#include - -#include -#include - - -/* - * @implemented - */ -_TINT _ungettc(_TINT c, FILE *f) -{ - if (!__validfp (f) || !OPEN4READING(f)) { - __set_errno (EINVAL); - return _TEOF; - } - - if (c == _TEOF) - return _TEOF; - - if (f->_ptr == f->_base) - { - if (!f->_cnt == 0) - return _TEOF; - } - - fseek(f, -sizeof(_TCHAR), SEEK_CUR); - - if(*(_TCHAR*)f->_ptr != c) - *((_TCHAR*)(f->_ptr)) = c; - - return c; -} - diff --git a/reactos/lib/sdk/crt/stdio/ungetwc.c b/reactos/lib/sdk/crt/stdio/ungetwc.c deleted file mode 100644 index fe8f7fd1e9c..00000000000 --- a/reactos/lib/sdk/crt/stdio/ungetwc.c +++ /dev/null @@ -1,4 +0,0 @@ -#define UNICODE -#define _UNICODE - -#include "ungetc.c" diff --git a/reactos/lib/sdk/crt/stdio/vprintf.c b/reactos/lib/sdk/crt/stdio/vprintf.c deleted file mode 100644 index 7f1fe3ce229..00000000000 --- a/reactos/lib/sdk/crt/stdio/vprintf.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 1991, 1993, 1995 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#include -#undef __OPTIMIZE__ /* Avoid inline `vprintf' function. */ -#include -#include - -#undef vprintf -#undef vwprintf - -//#define _USE_VARARG_ - -#ifndef _USE_VARARG_ - -/* - * @implemented - */ -int _vtprintf(const _TCHAR* format, va_list arg) -{ - int ret; - - ret = _vftprintf(stdout, format, arg); - fflush(stdout); - return ret; -} - -#else - -int _vtprintf(const _TCHAR* format, ...) -{ - va_list arg; - int ret; - - va_start(arg, format); - ret = _vftprintf(stdout, format, arg); - va_end(arg); - - fflush(stdout); - return ret; -} - -#endif diff --git a/reactos/lib/sdk/crt/stdio/vswprintf.c b/reactos/lib/sdk/crt/stdio/vswprintf.c deleted file mode 100644 index 94da15ff9e7..00000000000 --- a/reactos/lib/sdk/crt/stdio/vswprintf.c +++ /dev/null @@ -1,4 +0,0 @@ -#define UNICODE -#define _UNICODE - -#include "vsprintf.c" diff --git a/reactos/lib/sdk/crt/stdio/vwprintf.c b/reactos/lib/sdk/crt/stdio/vwprintf.c deleted file mode 100644 index c578db04da1..00000000000 --- a/reactos/lib/sdk/crt/stdio/vwprintf.c +++ /dev/null @@ -1,5 +0,0 @@ -#define _UNICODE -#define UNICODE - -#include "vprintf.c" - diff --git a/reactos/lib/sdk/crt/io/waccess.c b/reactos/lib/sdk/crt/stdio/waccess.c similarity index 100% rename from reactos/lib/sdk/crt/io/waccess.c rename to reactos/lib/sdk/crt/stdio/waccess.c diff --git a/reactos/lib/sdk/crt/stdio/wfdopen.c b/reactos/lib/sdk/crt/stdio/wfdopen.c deleted file mode 100644 index aa1fcc7bc47..00000000000 --- a/reactos/lib/sdk/crt/stdio/wfdopen.c +++ /dev/null @@ -1,7 +0,0 @@ - - -#define _UNICODE -#define UNICODE - -#include "fdopen.c" - diff --git a/reactos/lib/sdk/crt/io/wfind.c b/reactos/lib/sdk/crt/stdio/wfind.c similarity index 100% rename from reactos/lib/sdk/crt/io/wfind.c rename to reactos/lib/sdk/crt/stdio/wfind.c diff --git a/reactos/lib/sdk/crt/stdio/wfopen.c b/reactos/lib/sdk/crt/stdio/wfopen.c deleted file mode 100644 index f0175d84959..00000000000 --- a/reactos/lib/sdk/crt/stdio/wfopen.c +++ /dev/null @@ -1,4 +0,0 @@ -#define UNICODE -#define _UNICODE - -#include "fopen.c" diff --git a/reactos/lib/sdk/crt/stdio/wfreopen.c b/reactos/lib/sdk/crt/stdio/wfreopen.c deleted file mode 100644 index 0453bfb6905..00000000000 --- a/reactos/lib/sdk/crt/stdio/wfreopen.c +++ /dev/null @@ -1,6 +0,0 @@ - -#define UNICODE -#define _UNICODE - -#include "freopen.c" - diff --git a/reactos/lib/sdk/crt/stdio/wfsopen.c b/reactos/lib/sdk/crt/stdio/wfsopen.c deleted file mode 100644 index 8a3266cb4ca..00000000000 --- a/reactos/lib/sdk/crt/stdio/wfsopen.c +++ /dev/null @@ -1,5 +0,0 @@ -#define _UNICODE -#define UNICODE - -#include "fsopen.c" - diff --git a/reactos/lib/sdk/crt/stdio/wprintf.c b/reactos/lib/sdk/crt/stdio/wprintf.c deleted file mode 100644 index 65419d3339d..00000000000 --- a/reactos/lib/sdk/crt/stdio/wprintf.c +++ /dev/null @@ -1,5 +0,0 @@ -#define _UNICODE -#define UNICODE - -#include "printf.c" - diff --git a/reactos/lib/sdk/crt/stdio/wremove.c b/reactos/lib/sdk/crt/stdio/wremove.c deleted file mode 100644 index ce56997314c..00000000000 --- a/reactos/lib/sdk/crt/stdio/wremove.c +++ /dev/null @@ -1,4 +0,0 @@ -#define UNICODE -#define _UNICODE - -#include "remove.c" diff --git a/reactos/lib/sdk/crt/stdio/wrename.c b/reactos/lib/sdk/crt/stdio/wrename.c deleted file mode 100644 index bb6eda1d144..00000000000 --- a/reactos/lib/sdk/crt/stdio/wrename.c +++ /dev/null @@ -1,6 +0,0 @@ - -#define _UNICODE -#define UNICODE - -#include "rename.c" - diff --git a/reactos/lib/sdk/crt/stdio/wtempnam.c b/reactos/lib/sdk/crt/stdio/wtempnam.c deleted file mode 100644 index ec9e2bd9053..00000000000 --- a/reactos/lib/sdk/crt/stdio/wtempnam.c +++ /dev/null @@ -1,6 +0,0 @@ - -#define _UNICODE -#define UNICODE - -#include "tempnam.c" - diff --git a/reactos/lib/sdk/crt/stdio/wtmpnam.c b/reactos/lib/sdk/crt/stdio/wtmpnam.c deleted file mode 100644 index be2782c301a..00000000000 --- a/reactos/lib/sdk/crt/stdio/wtmpnam.c +++ /dev/null @@ -1,5 +0,0 @@ - -#define _UNICODE -#define UNICODE - -#include "tmpnam.c" diff --git a/reactos/lib/sdk/crt/string/wcs.c b/reactos/lib/sdk/crt/string/wcs.c new file mode 100644 index 00000000000..6e1c6d38746 --- /dev/null +++ b/reactos/lib/sdk/crt/string/wcs.c @@ -0,0 +1,1030 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: LGPL - See COPYING in the top level directory + * FILE: lib/sdk/crt/string/wcs.c + * PURPOSE: wcs* CRT functions + * PROGRAMMERS: Wine team + * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org) + */ + +/* + * msvcrt.dll wide-char functions + * + * Copyright 1999 Alexandre Julliard + * Copyright 2000 Jon Griffiths + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#include +#include + +#ifndef _LIBCNT_ +#include +#endif + +#include "wine/unicode.h" +//#include "wine/debug.h" + + +//WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); + +// HACK for LIBCNT +#ifndef debugstr_w +#define debugstr_w +#endif + + +#undef sprintf +#undef wsprintf +#undef vsnprintf +#undef vprintf +#undef vwprintf + +#ifndef _LIBCNT_ +/********************************************************************* + * _wcsdup (MSVCRT.@) + */ +wchar_t* CDECL _wcsdup( const wchar_t* str ) +{ + wchar_t* ret = NULL; + if (str) + { + int size = (strlenW(str) + 1) * sizeof(wchar_t); + ret = malloc( size ); + if (ret) memcpy( ret, str, size ); + } + return ret; +} +#endif +/********************************************************************* + * _wcsicoll (MSVCRT.@) + */ +INT CDECL _wcsicoll( const wchar_t* str1, const wchar_t* str2 ) +{ + /* FIXME: handle collates */ + return strcmpiW( str1, str2 ); +} + +/********************************************************************* + * _wcsnset (MSVCRT.@) + */ +wchar_t* CDECL _wcsnset( wchar_t* str, wchar_t c, size_t n ) +{ + wchar_t* ret = str; + while ((n-- > 0) && *str) *str++ = c; + return ret; +} + +/********************************************************************* + * _wcsrev (MSVCRT.@) + */ +wchar_t* CDECL _wcsrev( wchar_t* str ) +{ + wchar_t* ret = str; + wchar_t* end = str + strlenW(str) - 1; + while (end > str) + { + wchar_t t = *end; + *end-- = *str; + *str++ = t; + } + return ret; +} + +/********************************************************************* + * _wcsset (MSVCRT.@) + */ +wchar_t* CDECL _wcsset( wchar_t* str, wchar_t c ) +{ + wchar_t* ret = str; + while (*str) *str++ = c; + return ret; +} + +/********************************************************************* + * wcstod (MSVCRT.@) + */ +double CDECL wcstod(const wchar_t* lpszStr, wchar_t** end) +{ + const wchar_t* str = lpszStr; + int negative = 0; + double ret = 0, divisor = 10.0; + + TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr), end); + + /* FIXME: + * - Should set errno on failure + * - Should fail on overflow + * - Need to check which input formats are allowed + */ + while (isspaceW(*str)) + str++; + + if (*str == '-') + { + negative = 1; + str++; + } + + while (isdigitW(*str)) + { + ret = ret * 10.0 + (*str - '0'); + str++; + } + if (*str == '.') + str++; + while (isdigitW(*str)) + { + ret = ret + (*str - '0') / divisor; + divisor *= 10; + str++; + } + + if (*str == 'E' || *str == 'e' || *str == 'D' || *str == 'd') + { + int negativeExponent = 0; + int exponent = 0; + if (*(++str) == '-') + { + negativeExponent = 1; + str++; + } + while (isdigitW(*str)) + { + exponent = exponent * 10 + (*str - '0'); + str++; + } + if (exponent != 0) + { + if (negativeExponent) + ret = ret / pow(10.0, exponent); + else + ret = ret * pow(10.0, exponent); + } + } + + if (negative) + ret = -ret; + + if (end) + *end = (wchar_t*)str; + + TRACE("returning %g\n", ret); + return ret; +} + +#ifndef _LIBCNT_ +typedef struct pf_output_t +{ + int used; + int len; + BOOL unicode; + union { + LPWSTR W; + LPSTR A; + } buf; +} pf_output; + +typedef struct pf_flags_t +{ + char Sign, LeftAlign, Alternate, PadZero; + int FieldLength, Precision; + char IntegerLength, IntegerDouble; + char WideString; + char Format; +} pf_flags; + +/* + * writes a string of characters to the output + * returns -1 if the string doesn't fit in the output buffer + * return the length of the string if all characters were written + */ +static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len ) +{ + int space = out->len - out->used; + + if( len < 0 ) + len = strlenW( str ); + if( out->unicode ) + { + LPWSTR p = out->buf.W + out->used; + + if( space >= len ) + { + memcpy( p, str, len*sizeof(WCHAR) ); + out->used += len; + return len; + } + if( space > 0 ) + memcpy( p, str, space*sizeof(WCHAR) ); + out->used += len; + } + else + { + int n = WideCharToMultiByte( CP_ACP, 0, str, len, NULL, 0, NULL, NULL ); + LPSTR p = out->buf.A + out->used; + + if( space >= n ) + { + WideCharToMultiByte( CP_ACP, 0, str, len, p, n, NULL, NULL ); + out->used += n; + return len; + } + if( space > 0 ) + WideCharToMultiByte( CP_ACP, 0, str, len, p, space, NULL, NULL ); + out->used += n; + } + return -1; +} + +static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len ) +{ + int space = out->len - out->used; + + if( len < 0 ) + len = strlen( str ); + if( !out->unicode ) + { + LPSTR p = out->buf.A + out->used; + + if( space >= len ) + { + memcpy( p, str, len ); + out->used += len; + return len; + } + if( space > 0 ) + memcpy( p, str, space ); + out->used += len; + } + else + { + int n = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 ); + LPWSTR p = out->buf.W + out->used; + + if( space >= n ) + { + MultiByteToWideChar( CP_ACP, 0, str, len, p, n ); + out->used += n; + return len; + } + if( space > 0 ) + MultiByteToWideChar( CP_ACP, 0, str, len, p, space ); + out->used += n; + } + return -1; +} + +/* pf_fill: takes care of signs, alignment, zero and field padding */ +static inline int pf_fill( pf_output *out, int len, pf_flags *flags, char left ) +{ + int i, r = 0; + + if( flags->Sign && !( flags->Format == 'd' || flags->Format == 'i' ) ) + flags->Sign = 0; + + if( left && flags->Sign ) + { + flags->FieldLength--; + if( flags->PadZero ) + r = pf_output_stringA( out, &flags->Sign, 1 ); + } + + if( ( !left && flags->LeftAlign ) || + ( left && !flags->LeftAlign )) + { + for( i=0; (i<(flags->FieldLength-len)) && (r>=0); i++ ) + { + if( left && flags->PadZero ) + r = pf_output_stringA( out, "0", 1 ); + else + r = pf_output_stringA( out, " ", 1 ); + } + } + + if( left && flags->Sign && !flags->PadZero ) + r = pf_output_stringA( out, &flags->Sign, 1 ); + + return r; +} + +static inline int pf_output_format_W( pf_output *out, LPCWSTR str, + int len, pf_flags *flags ) +{ + int r = 0; + + if( len < 0 ) + len = strlenW( str ); + + if (flags->Precision >= 0 && flags->Precision < len) + len = flags->Precision; + + r = pf_fill( out, len, flags, 1 ); + + if( r>=0 ) + r = pf_output_stringW( out, str, len ); + + if( r>=0 ) + r = pf_fill( out, len, flags, 0 ); + + return r; +} + +static inline int pf_output_format_A( pf_output *out, LPCSTR str, + int len, pf_flags *flags ) +{ + int r = 0; + + if( len < 0 ) + len = strlen( str ); + + if (flags->Precision >= 0 && flags->Precision < len) + len = flags->Precision; + + r = pf_fill( out, len, flags, 1 ); + + if( r>=0 ) + r = pf_output_stringA( out, str, len ); + + if( r>=0 ) + r = pf_fill( out, len, flags, 0 ); + + return r; +} + +static int pf_handle_string_format( pf_output *out, const void* str, int len, + pf_flags *flags, BOOL capital_letter) +{ + if(str == NULL) /* catch NULL pointer */ + return pf_output_format_A( out, "(null)", -1, flags); + + /* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */ + if(flags->WideString || flags->IntegerLength == 'l') + return pf_output_format_W( out, str, len, flags); + if(flags->IntegerLength == 'h') + return pf_output_format_A( out, str, len, flags); + + /* %s,%c -> chars in ansi functions & wchars in unicode + * %S,%C -> wchars in ansi functions & chars in unicode */ + if( capital_letter == out->unicode) /* either both TRUE or both FALSE */ + return pf_output_format_A( out, str, len, flags); + else + return pf_output_format_W( out, str, len, flags); +} + +static inline BOOL pf_is_integer_format( char fmt ) +{ + static const char float_fmts[] = "diouxX"; + if (!fmt) + return FALSE; + return strchr( float_fmts, fmt ) ? TRUE : FALSE; +} + +static inline BOOL pf_is_double_format( char fmt ) +{ + static const char float_fmts[] = "aeEfgG"; + if (!fmt) + return FALSE; + return strchr( float_fmts, fmt ) ? TRUE : FALSE; +} + +static inline BOOL pf_is_valid_format( char fmt ) +{ + static const char float_fmts[] = "acCdeEfgGinouxX"; + if (!fmt) + return FALSE; + return strchr( float_fmts, fmt ) ? TRUE : FALSE; +} + +static void pf_rebuild_format_string( char *p, pf_flags *flags ) +{ + *p++ = '%'; + if( flags->Sign ) + *p++ = flags->Sign; + if( flags->LeftAlign ) + *p++ = flags->LeftAlign; + if( flags->Alternate ) + *p++ = flags->Alternate; + if( flags->PadZero ) + *p++ = flags->PadZero; + if( flags->FieldLength ) + { + lnx_sprintf(p, "%d", flags->FieldLength); + p += strlen(p); + } + if( flags->Precision >= 0 ) + { + lnx_sprintf(p, ".%d", flags->Precision); + p += strlen(p); + } + *p++ = flags->Format; + *p++ = 0; +} + +/* pf_integer_conv: prints x to buf, including alternate formats and + additional precision digits, but not field characters or the sign */ +static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags, + LONGLONG x ) +{ + unsigned int base; + const char *digits; + + int i, j, k; + char number[40], *tmp = number; + + if( buf_len > sizeof number ) + tmp = HeapAlloc( GetProcessHeap(), 0, buf_len ); + + base = 10; + if( flags->Format == 'o' ) + base = 8; + else if( flags->Format == 'x' || flags->Format == 'X' ) + base = 16; + + if( flags->Format == 'X' ) + digits = "0123456789ABCDEFX"; + else + digits = "0123456789abcdefx"; + + if( x < 0 && ( flags->Format == 'd' || flags->Format == 'i' ) ) + { + x = -x; + flags->Sign = '-'; + } + + /* Do conversion (backwards) */ + i = 0; + if( x == 0 && flags->Precision ) + tmp[i++] = '0'; + else + while( x != 0 ) + { + j = (ULONGLONG) x % base; + x = (ULONGLONG) x / base; + tmp[i++] = digits[j]; + } + k = flags->Precision - i; + while( k-- > 0 ) + tmp[i++] = '0'; + if( flags->Alternate ) + { + if( base == 16 ) + { + tmp[i++] = digits[16]; + tmp[i++] = '0'; + } + else if( base == 8 && tmp[i-1] != '0' ) + tmp[i++] = '0'; + } + + /* Reverse for buf */ + j = 0; + while( i-- > 0 ) + buf[j++] = tmp[i]; + buf[j] = '\0'; + + /* Adjust precision so pf_fill won't truncate the number later */ + flags->Precision = strlen( buf ); + + if( tmp != number ) + HeapFree( GetProcessHeap(), 0, tmp ); + + return; +} + +/********************************************************************* + * pf_vsnprintf (INTERNAL) + * + * implements both A and W vsnprintf functions + */ +static int pf_vsnprintf( pf_output *out, const WCHAR *format, va_list valist ) +{ + int r; + LPCWSTR q, p = format; + pf_flags flags; + + TRACE("format is %s\n",debugstr_w(format)); + while (*p) + { + q = strchrW( p, '%' ); + + /* there's no % characters left, output the rest of the string */ + if( !q ) + { + r = pf_output_stringW(out, p, -1); + if( r<0 ) + return r; + p += r; + continue; + } + + /* there's characters before the %, output them */ + if( q != p ) + { + r = pf_output_stringW(out, p, q - p); + if( r<0 ) + return r; + p = q; + } + + /* we must be at a % now, skip over it */ + assert( *p == '%' ); + p++; + + /* output a single % character */ + if( *p == '%' ) + { + r = pf_output_stringW(out, p++, 1); + if( r<0 ) + return r; + continue; + } + + /* parse the flags */ + memset( &flags, 0, sizeof flags ); + while (*p) + { + if( *p == '+' || *p == ' ' ) + { + if ( flags.Sign != '+' ) + flags.Sign = *p; + } + else if( *p == '-' ) + flags.LeftAlign = *p; + else if( *p == '0' ) + flags.PadZero = *p; + else if( *p == '#' ) + flags.Alternate = *p; + else + break; + p++; + } + + /* deal with the field width specifier */ + flags.FieldLength = 0; + if( *p == '*' ) + { + flags.FieldLength = va_arg( valist, int ); + if (flags.FieldLength < 0) + { + flags.LeftAlign = '-'; + flags.FieldLength = -flags.FieldLength; + } + p++; + } + else while( isdigit(*p) ) + { + flags.FieldLength *= 10; + flags.FieldLength += *p++ - '0'; + } + + /* deal with precision */ + flags.Precision = -1; + if( *p == '.' ) + { + flags.Precision = 0; + p++; + if( *p == '*' ) + { + flags.Precision = va_arg( valist, int ); + p++; + } + else while( isdigit(*p) ) + { + flags.Precision *= 10; + flags.Precision += *p++ - '0'; + } + } + + /* deal with integer width modifier */ + while( *p ) + { + if( *p == 'h' || *p == 'l' || *p == 'L' ) + { + flags.IntegerLength = *p; + p++; + } + else if( *p == 'I' ) + { + if( *(p+1) == '6' && *(p+2) == '4' ) + { + flags.IntegerDouble++; + p += 3; + } + else if( *(p+1) == '3' && *(p+2) == '2' ) + p += 3; + else if( isdigit(*(p+1)) || *(p+1) == 0 ) + break; + else + p++; + } + else if( *p == 'w' ) + flags.WideString = *p++; + else if( *p == 'F' ) + p++; /* ignore */ + else + break; + } + + flags.Format = *p; + r = 0; + + /* output a string */ + if( flags.Format == 's' || flags.Format == 'S' ) + r = pf_handle_string_format( out, va_arg(valist, const void*), -1, + &flags, (flags.Format == 'S') ); + + /* output a single character */ + else if( flags.Format == 'c' || flags.Format == 'C' ) + { + INT ch = va_arg( valist, int ); + + r = pf_handle_string_format( out, &ch, 1, &flags, (flags.Format == 'C') ); + } + + /* output a pointer */ + else if( flags.Format == 'p' ) + { + char pointer[11]; + + flags.PadZero = 0; + if( flags.Alternate ) + lnx_sprintf(pointer, "0X%08lX", va_arg(valist, long)); + else + lnx_sprintf(pointer, "%08lX", va_arg(valist, long)); + r = pf_output_format_A( out, pointer, -1, &flags ); + } + + /* deal with %n */ + else if( flags.Format == 'n' ) + { + int *x = va_arg(valist, int *); + *x = out->used; + } + + /* deal with 64-bit integers */ + else if( pf_is_integer_format( flags.Format ) && flags.IntegerDouble ) + { + char number[40], *x = number; + + /* Estimate largest possible required buffer size: + * Chooses the larger of the field or precision + * Includes extra bytes: 1 byte for null, 1 byte for sign, + 4 bytes for exponent, 2 bytes for alternate formats, 1 byte + for a decimal, and 1 byte for an additional float digit. */ + int x_len = ((flags.FieldLength > flags.Precision) ? + flags.FieldLength : flags.Precision) + 10; + + if( x_len >= sizeof number) + x = HeapAlloc( GetProcessHeap(), 0, x_len ); + + pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) ); + + r = pf_output_format_A( out, x, -1, &flags ); + if( x != number ) + HeapFree( GetProcessHeap(), 0, x ); + } + + /* deal with integers and floats using libc's printf */ + else if( pf_is_valid_format( flags.Format ) ) + { + char fmt[20], number[40], *x = number; + + /* Estimate largest possible required buffer size: + * Chooses the larger of the field or precision + * Includes extra bytes: 1 byte for null, 1 byte for sign, + 4 bytes for exponent, 2 bytes for alternate formats, 1 byte + for a decimal, and 1 byte for an additional float digit. */ + int x_len = ((flags.FieldLength > flags.Precision) ? + flags.FieldLength : flags.Precision) + 10; + + if( x_len >= sizeof number) + x = HeapAlloc( GetProcessHeap(), 0, x_len ); + + pf_rebuild_format_string( fmt, &flags ); + + if( pf_is_double_format( flags.Format ) ) + lnx_sprintf( x, fmt, va_arg(valist, double) ); + else + lnx_sprintf( x, fmt, va_arg(valist, int) ); + + r = pf_output_stringA( out, x, -1 ); + if( x != number ) + HeapFree( GetProcessHeap(), 0, x ); + } + else + continue; + + if( r<0 ) + return r; + p++; + } + + /* check we reached the end, and null terminate the string */ + assert( *p == 0 ); + pf_output_stringW( out, p, 1 ); + + return out->used - 1; +} + +/********************************************************************* + * _vsnprintf (MSVCRT.@) + */ +int CDECL vsnprintf( char *str, unsigned int len, + const char *format, va_list valist ) +{ + DWORD sz; + LPWSTR formatW = NULL; + pf_output out; + int r; + + out.unicode = FALSE; + out.buf.A = str; + out.used = 0; + out.len = len; + + if( format ) + { + sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 ); + formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz ); + } + + r = pf_vsnprintf( &out, formatW, valist ); + + HeapFree( GetProcessHeap(), 0, formatW ); + + return r; +} + +/********************************************************************* + * vsprintf (MSVCRT.@) + */ +int CDECL vsprintf( char *str, const char *format, va_list valist) +{ + return vsnprintf(str, INT_MAX, format, valist); +} + +/********************************************************************* + * _snprintf (MSVCRT.@) + */ +int CDECL _snprintf(char *str, unsigned int len, const char *format, ...) +{ + int retval; + va_list valist; + va_start(valist, format); + retval = vsnprintf(str, len, format, valist); + va_end(valist); + return retval; +} + +/********************************************************************* + * _vsnwsprintf (MSVCRT.@) + */ +int CDECL vsnwprintf( wchar_t *str, unsigned int len, + const wchar_t *format, va_list valist ) +{ + pf_output out; + + out.unicode = TRUE; + out.buf.W = str; + out.used = 0; + out.len = len; + + return pf_vsnprintf( &out, format, valist ); +} + +/********************************************************************* + * _snwprintf (MSVCRT.@) + */ +int CDECL _snwprintf( wchar_t *str, unsigned int len, const wchar_t *format, ...) +{ + int retval; + va_list valist; + va_start(valist, format); + retval = vsnwprintf(str, len, format, valist); + va_end(valist); + return retval; +} + +/********************************************************************* + * sprintf (MSVCRT.@) + */ +int CDECL sprintf( char *str, const char *format, ... ) +{ + va_list ap; + int r; + + va_start( ap, format ); + r = vsnprintf( str, INT_MAX, format, ap ); + va_end( ap ); + return r; +} + +/********************************************************************* + * swprintf (MSVCRT.@) + */ +int CDECL swprintf( wchar_t *str, const wchar_t *format, ... ) +{ + va_list ap; + int r; + + va_start( ap, format ); + r = vsnwprintf( str, INT_MAX, format, ap ); + va_end( ap ); + return r; +} + +/********************************************************************* + * vswprintf (MSVCRT.@) + */ +int CDECL vswprintf( wchar_t* str, const wchar_t* format, va_list args ) +{ + return vsnwprintf( str, INT_MAX, format, args ); +} +#endif +/********************************************************************* + * wcscoll (MSVCRT.@) + */ +int CDECL wcscoll( const wchar_t* str1, const wchar_t* str2 ) +{ + /* FIXME: handle collates */ + return strcmpW( str1, str2 ); +} + +/********************************************************************* + * wcspbrk (MSVCRT.@) + */ +wchar_t* CDECL wcspbrk( const wchar_t* str, const wchar_t* accept ) +{ + const wchar_t* p; + while (*str) + { + for (p = accept; *p; p++) if (*p == *str) return (wchar_t*)str; + str++; + } + return NULL; +} +#ifndef _LIBCNT_ +/********************************************************************* + * wcstok (MSVCRT.@) + */ +wchar_t * CDECL wcstok( wchar_t *str, const wchar_t *delim ) +{ + MSVCRT_thread_data *data = msvcrt_get_thread_data(); + wchar_t *ret; + + if (!str) + if (!(str = data->wcstok_next)) return NULL; + + while (*str && strchrW( delim, *str )) str++; + if (!*str) return NULL; + ret = str++; + while (*str && !strchrW( delim, *str )) str++; + if (*str) *str++ = 0; + data->wcstok_next = str; + return ret; +} +#endif +#ifndef __REACTOS__ +/********************************************************************* + * wctomb (MSVCRT.@) + */ +INT CDECL wctomb( char *dst, wchar_t ch ) +{ + return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL ); +} + +/********************************************************************* + * iswalnum (MSVCRT.@) + */ +INT CDECL iswalnum( wchar_t wc ) +{ + return isalnumW( wc ); +} + +/********************************************************************* + * iswalpha (MSVCRT.@) + */ +INT CDECL iswalpha( wchar_t wc ) +{ + return isalphaW( wc ); +} + +/********************************************************************* + * iswcntrl (MSVCRT.@) + */ +INT CDECL iswcntrl( wchar_t wc ) +{ + return iscntrlW( wc ); +} + +/********************************************************************* + * iswdigit (MSVCRT.@) + */ +INT CDECL iswdigit( wchar_t wc ) +{ + return isdigitW( wc ); +} + +/********************************************************************* + * iswgraph (MSVCRT.@) + */ +INT CDECL iswgraph( wchar_t wc ) +{ + return isgraphW( wc ); +} + +/********************************************************************* + * iswlower (MSVCRT.@) + */ +INT CDECL iswlower( wchar_t wc ) +{ + return islowerW( wc ); +} + +/********************************************************************* + * iswprint (MSVCRT.@) + */ +INT CDECL iswprint( wchar_t wc ) +{ + return isprintW( wc ); +} + +/********************************************************************* + * iswpunct (MSVCRT.@) + */ +INT CDECL iswpunct( wchar_t wc ) +{ + return ispunctW( wc ); +} + +/********************************************************************* + * iswspace (MSVCRT.@) + */ +INT CDECL iswspace( wchar_t wc ) +{ + return isspaceW( wc ); +} + +/********************************************************************* + * iswupper (MSVCRT.@) + */ +INT CDECL iswupper( wchar_t wc ) +{ + return isupperW( wc ); +} + +/********************************************************************* + * iswxdigit (MSVCRT.@) + */ +INT CDECL iswxdigit( wchar_t wc ) +{ + return isxdigitW( wc ); +} +#endif +#ifndef _LIBCNT_ +/********************************************************************* + * wcscpy_s (MSVCRT.@) + */ +INT CDECL wcscpy_s( wchar_t* wcDest, size_t numElement, const wchar_t *wcSrc) +{ + INT size = 0; + + if(!wcDest || !numElement) + return EINVAL; + + wcDest[0] = 0; + + if(!wcSrc) + { + return EINVAL; + } + + size = strlenW(wcSrc) + 1; + + if(size > numElement) + { + return ERANGE; + } + + if(size > numElement) + size = numElement; + + memcpy( wcDest, wcSrc, size*sizeof(WCHAR) ); + + return 0; +} +#endif diff --git a/reactos/lib/sdk/crt/string/wcstod.c b/reactos/lib/sdk/crt/string/wcstod.c index 89029c1a5c1..365fb99ef8e 100644 --- a/reactos/lib/sdk/crt/string/wcstod.c +++ b/reactos/lib/sdk/crt/string/wcstod.c @@ -6,6 +6,7 @@ /* * @implemented */ +#if 0 //FIXME: Compare with wcstod in wcs.c double wcstod(const wchar_t *s, wchar_t **sret) { long double r; /* result */ @@ -96,3 +97,4 @@ double wcstod(const wchar_t *s, wchar_t **sret) *sret = (wchar_t *)s; return r * sign; } +#endif diff --git a/reactos/lib/sdk/crt/sys_stat/fstat.c b/reactos/lib/sdk/crt/sys_stat/fstat.c deleted file mode 100644 index c402d3fa9e1..00000000000 --- a/reactos/lib/sdk/crt/sys_stat/fstat.c +++ /dev/null @@ -1,79 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/sys/fstat.c - * PURPOSE: Gather file information - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ - -#include -#include - -/* - * @implemented - */ -int _fstat(int fd, struct _stat* statbuf) -{ - BY_HANDLE_FILE_INFORMATION FileInformation; - DWORD dwFileType; - void* handle; - - if (!statbuf) { - __set_errno(EINVAL); - return -1; - } - - if ((void*)-1 == (handle = (void*)_get_osfhandle(fd))) - { - __set_errno(EBADF); - return -1; - } - - fflush(NULL); - - memset (statbuf, 0, sizeof(struct stat)); - - dwFileType = GetFileType(handle); - - if (dwFileType == FILE_TYPE_DISK) - { - if (!GetFileInformationByHandle(handle,&FileInformation)) - { - __set_errno(EBADF); - return -1; - } - statbuf->st_ctime = FileTimeToUnixTime(&FileInformation.ftCreationTime,NULL); - statbuf->st_atime = FileTimeToUnixTime(&FileInformation.ftLastAccessTime,NULL); - statbuf->st_mtime = FileTimeToUnixTime(&FileInformation.ftLastWriteTime,NULL); - - statbuf->st_dev = fd; - statbuf->st_size = FileInformation.nFileSizeLow; - statbuf->st_mode = S_IREAD; - if (FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - statbuf->st_mode |= S_IFDIR; - else - statbuf->st_mode |= S_IFREG; - if (!(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - statbuf->st_mode |= S_IWRITE; - } - else if (dwFileType == FILE_TYPE_CHAR) - { - statbuf->st_dev = fd; - statbuf->st_mode = S_IFCHR; - } - else if (dwFileType == FILE_TYPE_PIPE) - { - statbuf->st_dev = fd; - statbuf->st_mode = -1; //S_IFIFO; - } - else - { - // dwFileType is FILE_TYPE_UNKNOWN or has a bad value - __set_errno(EBADF); - return -1; - } - return 0; -} diff --git a/reactos/lib/sdk/crt/sys_stat/fstati64.c b/reactos/lib/sdk/crt/sys_stat/fstati64.c deleted file mode 100644 index 4a5b47ff292..00000000000 --- a/reactos/lib/sdk/crt/sys_stat/fstati64.c +++ /dev/null @@ -1,86 +0,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/sys/fstat.c - * PURPOSE: Gather file information - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 28/12/98: Created - */ - -#include -#include - -/* - * @implemented - */ -int _fstati64(int fd, struct _stati64* statbuf) -{ - BY_HANDLE_FILE_INFORMATION FileInformation; - DWORD dwFileType; - void *handle; - - if (!statbuf) - { - __set_errno(EINVAL); - return -1; - } - - if ((void*)-1 == (handle = (void*)_get_osfhandle(fd))) - { - __set_errno(EBADF); - return -1; - } - - fflush(NULL); - - memset(statbuf, 0, sizeof(struct _stati64)); - - dwFileType = GetFileType(handle); - - if (dwFileType == FILE_TYPE_DISK) - { - if (!GetFileInformationByHandle(handle,&FileInformation)) - { - __set_errno(EBADF); - return -1; - } - statbuf->st_ctime = FileTimeToUnixTime(&FileInformation.ftCreationTime,NULL); - statbuf->st_atime = FileTimeToUnixTime(&FileInformation.ftLastAccessTime,NULL); - statbuf->st_mtime = FileTimeToUnixTime(&FileInformation.ftLastWriteTime,NULL); - - statbuf->st_dev = fd; - statbuf->st_size = (((__int64)FileInformation.nFileSizeHigh) << 32) + - FileInformation.nFileSizeLow; - statbuf->st_mode = S_IREAD; - if (FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - statbuf->st_mode |= S_IFDIR; - else - statbuf->st_mode |= S_IFREG; - if (!(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) statbuf->st_mode |= S_IWRITE; - } - else if (dwFileType == FILE_TYPE_CHAR) - { - statbuf->st_dev = fd; - statbuf->st_mode = S_IFCHR; - } - else if (dwFileType == FILE_TYPE_PIPE) - { - statbuf->st_dev = fd; - statbuf->st_mode = S_IFIFO; - } - else - { - // dwFileType is FILE_TYPE_UNKNOWN or has a bad value - __set_errno(EBADF); - return -1; - } - return 0; -} - -int _fstat64(int fd, struct __stat64* buf) -{ - FIXME("stub\n"); - return -1; -} diff --git a/reactos/lib/sdk/crt/sys_stat/futime.c b/reactos/lib/sdk/crt/sys_stat/futime.c deleted file mode 100644 index f9125eb16b9..00000000000 --- a/reactos/lib/sdk/crt/sys_stat/futime.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Added license header - */ - -#include -#include - -/* - * @implemented - */ -int _futime (int nHandle, struct _utimbuf *pTimes) -{ - FILETIME LastAccessTime; - FILETIME LastWriteTime; - - // check for stdin / stdout handles ?? - if (nHandle == -1) { - __set_errno(EBADF); - return -1; - } - - if (pTimes == NULL) { - pTimes = _alloca(sizeof(struct _utimbuf)); - time(&pTimes->actime); - time(&pTimes->modtime); - } - - if (pTimes->actime < pTimes->modtime) { - __set_errno(EINVAL); - return -1; - } - - UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0); - UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0); - if (!SetFileTime((HANDLE)_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime)) { - __set_errno(EBADF); - return -1; - } - - return 0; -} diff --git a/reactos/lib/sdk/crt/sys_stat/stat.c b/reactos/lib/sdk/crt/sys_stat/stat.c deleted file mode 100644 index 1dae23e7521..00000000000 --- a/reactos/lib/sdk/crt/sys_stat/stat.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Added license header - */ - -#include -#include -#include - -/* for stat mode, permissions apply to all,owner and group */ -#define ALL_S_IREAD (S_IREAD | (S_IREAD >> 3) | (S_IREAD >> 6)) -#define ALL_S_IWRITE (S_IWRITE | (S_IWRITE >> 3) | (S_IWRITE >> 6)) -#define ALL_S_IEXEC (S_IEXEC | (S_IEXEC >> 3) | (S_IEXEC >> 6)) - -/* - * @implemented - */ -int _stat(const char* path, struct _stat* buffer) -{ - WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; - char* ext; - - if (!buffer) - { - __set_errno(EINVAL); - return -1; - } - - if (strchr(path, '*') || strchr(path, '?')) - { - __set_errno(ENOENT); - return -1; - } - - if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fileAttributeData)) - { - __set_errno(ENOENT); - return -1; - } - - memset (buffer, 0, sizeof(struct stat)); - - buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL); - buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL); - buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL); - -// statbuf->st_dev = fd; - buffer->st_size = fileAttributeData.nFileSizeLow; - buffer->st_mode = S_IREAD; - if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - buffer->st_mode |= S_IFDIR; - else - { - buffer->st_mode |= S_IFREG; - ext = strrchr(path, '.'); - if (ext && (!_stricmp(ext, ".exe") || - !_stricmp(ext, ".com") || - !_stricmp(ext, ".bat") || - !_stricmp(ext, ".cmd"))) - buffer->st_mode |= S_IEXEC; - } - if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - buffer->st_mode |= S_IWRITE; - - return 0; -} - -/* - * @implemented - */ -int _stati64 (const char *path, struct _stati64 *buffer) -{ - WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; - char* ext; - - if (!buffer) - { - __set_errno(EINVAL); - return -1; - } - - if(strchr(path, '*') || strchr(path, '?')) - { - __set_errno(ENOENT); - return -1; - } - - if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fileAttributeData)) - { - __set_errno(ENOENT); - return -1; - } - - memset (buffer, 0, sizeof(struct _stati64)); - - buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL); - buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL); - buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL); - -// statbuf->st_dev = fd; - buffer->st_size = ((((__int64)fileAttributeData.nFileSizeHigh) << 16) << 16) + - fileAttributeData.nFileSizeLow; - buffer->st_mode = S_IREAD; - if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - buffer->st_mode |= S_IFDIR; - else - { - buffer->st_mode |= S_IFREG; - ext = strrchr(path, '.'); - if (ext && (!_stricmp(ext, ".exe") || - !_stricmp(ext, ".com") || - !_stricmp(ext, ".bat") || - !_stricmp(ext, ".cmd"))) - buffer->st_mode |= S_IEXEC; - } - if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - buffer->st_mode |= S_IWRITE; - - return 0; -} - -/********************************************************************* - * _stat64 (MSVCRT.@) - */ -int CDECL _stat64(const char* path, struct __stat64 * buf) -{ - DWORD dw; - WIN32_FILE_ATTRIBUTE_DATA hfi; - unsigned short mode = ALL_S_IREAD; - int plen; - - if (!GetFileAttributesExA(path, GetFileExInfoStandard, &hfi)) - { - ERR("failed (%d)\n",GetLastError()); - *_errno() = ERROR_FILE_NOT_FOUND; - return -1; - } - memset(buf,0,sizeof(struct __stat64)); - - /* FIXME: rdev isn't drive num, despite what the docs say-what is it? - Bon 011120: This FIXME seems incorrect - Also a letter as first char isn't enough to be classified - as a drive letter - */ - if (isalpha(*path)&& (*(path+1)==':')) - buf->st_dev = buf->st_rdev = toupper(*path) - 'A'; /* drive num */ - else - buf->st_dev = buf->st_rdev = _getdrive() - 1; - - plen = strlen(path); - - /* Dir, or regular file? */ - if ((hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || - (path[plen-1] == '\\')) - mode |= (S_IFDIR | ALL_S_IEXEC); - else - { - mode |= S_IFREG; - /* executable? */ - if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */ - { - char* ext = strrchr(path, '.'); - if (ext && (!_stricmp(ext, ".exe") || !_stricmp(ext, ".com") || !_stricmp(ext, ".bat") || - !_stricmp(ext, ".cmd"))) - mode |= S_IEXEC; - } - } - - - if (!(hfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - mode |= ALL_S_IWRITE; - - buf->st_mode = mode; - buf->st_nlink = 1; - buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow; - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastAccessTime, &dw); - buf->st_atime = dw; - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastWriteTime, &dw); - buf->st_mtime = buf->st_ctime = dw; - - TRACE("%d %d 0x%08lx%08lx %ld %ld %ld\n", buf->st_mode,buf->st_nlink, - (long)(buf->st_size >> 32),(long)buf->st_size, - (long)buf->st_atime,(long)buf->st_mtime,(long)buf->st_ctime); - - return 0; -} - - diff --git a/reactos/lib/sdk/crt/sys_stat/wstat.c b/reactos/lib/sdk/crt/sys_stat/wstat.c deleted file mode 100644 index 5dfd59a07fe..00000000000 --- a/reactos/lib/sdk/crt/sys_stat/wstat.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Added license header - */ - -#include -#include -#include -#include - -/* for stat mode, permissions apply to all,owner and group */ -#define ALL_S_IREAD (S_IREAD | (S_IREAD >> 3) | (S_IREAD >> 6)) -#define ALL_S_IWRITE (S_IWRITE | (S_IWRITE >> 3) | (S_IWRITE >> 6)) -#define ALL_S_IEXEC (S_IEXEC | (S_IEXEC >> 3) | (S_IEXEC >> 6)) - -/* - * @implemented - */ -int _wstat (const wchar_t *path, struct _stat *buffer) -{ - WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; - wchar_t *ext; - - if (!buffer) - { - __set_errno(EINVAL); - return -1; - } - - if(wcschr(path, L'*') || wcschr(path, L'?')) - { - __set_errno(ENOENT); - return -1; - } - - if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fileAttributeData)) - { - __set_errno(ENOENT); - return -1; - } - - memset (buffer, 0, sizeof(struct stat)); - - buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL); - buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL); - buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL); - -// statbuf->st_dev = fd; - buffer->st_size = fileAttributeData.nFileSizeLow; - buffer->st_mode = S_IREAD; - if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - buffer->st_mode |= S_IFDIR; - else - { - buffer->st_mode |= S_IFREG; - ext = wcsrchr(path, L'.'); - if (ext && (!_wcsicmp(ext, L".exe") || - !_wcsicmp(ext, L".com") || - !_wcsicmp(ext, L".bat") || - !_wcsicmp(ext, L".cmd"))) - buffer->st_mode |= S_IEXEC; - } - if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - buffer->st_mode |= S_IWRITE; - - return 0; -} - -/* - * @implemented - */ -int _wstati64 (const wchar_t *path, struct _stati64 *buffer) -{ - WIN32_FILE_ATTRIBUTE_DATA fileAttributeData; - wchar_t *ext; - - if (!buffer) - { - __set_errno(EINVAL); - return -1; - } - - if(wcschr(path, L'*') || wcschr(path, L'?')) - { - __set_errno(ENOENT); - return -1; - } - - if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fileAttributeData)) - { - __set_errno(ENOENT); - return -1; - } - - memset (buffer, 0, sizeof(struct _stati64)); - - buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL); - buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL); - buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL); - -// statbuf->st_dev = fd; - buffer->st_size = ((((__int64)fileAttributeData.nFileSizeHigh) << 16) << 16) + - fileAttributeData.nFileSizeLow; - buffer->st_mode = S_IREAD; - if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - buffer->st_mode |= S_IFDIR; - else - { - buffer->st_mode |= S_IFREG; - ext = wcsrchr(path, L'.'); - if (ext && (!_wcsicmp(ext, L".exe") || - !_wcsicmp(ext, L".com") || - !_wcsicmp(ext, L".bat") || - !_wcsicmp(ext, L".cmd"))) - buffer->st_mode |= S_IEXEC; - } - if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - buffer->st_mode |= S_IWRITE; - - return 0; -} - -/********************************************************************* -* _wstat64 (MSVCRT.@) -*/ -int CDECL _wstat64(const wchar_t* path, struct __stat64 * buf) -{ - DWORD dw; - WIN32_FILE_ATTRIBUTE_DATA hfi; - unsigned short mode = ALL_S_IREAD; - int plen; - - if (!GetFileAttributesExW(path, GetFileExInfoStandard, &hfi)) - { - __set_errno(ERROR_FILE_NOT_FOUND); - return -1; - } - - memset(buf,0,sizeof(struct __stat64)); - - /* FIXME: rdev isn't drive num, despite what the docs says-what is it? */ - if (iswalpha(*path)) - buf->st_dev = buf->st_rdev = towupper(*path - 'A'); /* drive num */ - else - buf->st_dev = buf->st_rdev = _getdrive() - 1; - - plen = wcslen(path); - - /* Dir, or regular file? */ - if ((hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || - (path[plen-1] == '\\')) - mode |= (S_IFDIR | ALL_S_IEXEC); - else - { - mode |= S_IFREG; - /* executable? */ - if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */ - - { - wchar_t* ext = wcsrchr(path, L'.'); - if (ext && (!_wcsicmp(ext, L".exe") || !_wcsicmp(ext, L".com") || - !_wcsicmp(ext, L".bat") || !_wcsicmp(ext, L".cmd"))) - mode |= S_IEXEC; - } - } - - if (!(hfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - mode |= ALL_S_IWRITE; - - buf->st_mode = mode; - buf->st_nlink = 1; - buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow; - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastAccessTime, &dw); - buf->st_atime = dw; - RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastWriteTime, &dw); - buf->st_mtime = buf->st_ctime = dw; - - return 0; -} diff --git a/reactos/lib/sdk/crt/wstring/wcscoll.c b/reactos/lib/sdk/crt/wstring/wcscoll.c index c5237882b13..e399c2f2267 100644 --- a/reactos/lib/sdk/crt/wstring/wcscoll.c +++ b/reactos/lib/sdk/crt/wstring/wcscoll.c @@ -10,24 +10,6 @@ #include -/* - * @unimplemented - */ -int wcscoll(const wchar_t *a1,const wchar_t *a2) -{ - /* FIXME: handle collates */ - return wcscmp(a1,a2); -} - -/* - * @unimplemented - */ -int _wcsicoll(const wchar_t *a1,const wchar_t *a2) -{ - /* FIXME: handle collates */ - return _wcsicmp(a1,a2); -} - /* * @unimplemented */ diff --git a/reactos/lib/sdk/crt/wstring/wcsdup.c b/reactos/lib/sdk/crt/wstring/wcsdup.c deleted file mode 100644 index 4679f8f874c..00000000000 --- a/reactos/lib/sdk/crt/wstring/wcsdup.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Added license header - */ - -#include - -/* - * @implemented - */ -wchar_t* _wcsdup(const wchar_t* ptr) -{ - wchar_t* dup; - - dup = malloc((wcslen(ptr) + 1) * sizeof(wchar_t)); - if (dup == NULL) { - __set_errno(ENOMEM); - return NULL; - } - wcscpy(dup, ptr); - return dup; -} diff --git a/reactos/lib/sdk/crt/wstring/wcspbrk.c b/reactos/lib/sdk/crt/wstring/wcspbrk.c deleted file mode 100644 index e3b7c92c6be..00000000000 --- a/reactos/lib/sdk/crt/wstring/wcspbrk.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Added license header - */ - -#include - -/* - * @implemented - */ -wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2) -{ - const wchar_t *scanp; - int c, sc; - - while ((c = *s1++) != 0) - { - for (scanp = s2; (sc = *scanp++) != 0;) - if (sc == c) { - return (wchar_t *)(--s1); - } - } - return 0; -} diff --git a/reactos/lib/sdk/crt/wstring/wcsrev.c b/reactos/lib/sdk/crt/wstring/wcsrev.c deleted file mode 100644 index 20f5c51bdbb..00000000000 --- a/reactos/lib/sdk/crt/wstring/wcsrev.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/crt/?????? - * PURPOSE: Unknown - * PROGRAMER: Unknown - * UPDATE HISTORY: - * 25/11/05: Added license header - */ - -#include - -/* - * @implemented - */ -wchar_t * _wcsrev(wchar_t *s) -{ - wchar_t *e; - wchar_t a; - e=s; - while (*e) - e++; - while (s - -/* - * @implemented - */ -wchar_t* _wcsnset (wchar_t* wsToFill, wchar_t wcFill, size_t sizeMaxFill) -{ - wchar_t *t = wsToFill; - size_t i = 0; - while( *wsToFill != 0 && i < sizeMaxFill) - { - *wsToFill = wcFill; - wsToFill++; - i++; - - } - return t; -} - -/* - * @implemented - */ -#ifndef _MSC_VER -wchar_t* _wcsset (wchar_t* wsToFill, wchar_t wcFill) -{ - wchar_t *t = wsToFill; - while( *wsToFill != 0 ) - { - *wsToFill = wcFill; - wsToFill++; - - } - return t; -} -#endif