From db69b4ae79a89575b15fc1cbeba3c92d70e0f177 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Mon, 1 Apr 2002 21:47:31 +0000 Subject: [PATCH] Fixed initialization of new fileno_modes in __fileno_alloc(). Added setting of errno in _open(). Added debug messages. svn path=/trunk/; revision=2796 --- reactos/lib/msvcrt/io/open.c | 52 +++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/reactos/lib/msvcrt/io/open.c b/reactos/lib/msvcrt/io/open.c index 30417892910..949ff1e688a 100644 --- a/reactos/lib/msvcrt/io/open.c +++ b/reactos/lib/msvcrt/io/open.c @@ -13,6 +13,9 @@ // possibly store extra information at the handle #include +#if !defined(NDEBUG) && defined(DBG) +#include +#endif #include #include #include @@ -20,6 +23,10 @@ #include #include #include +#include + +#define NDEBUG +#include typedef struct _fileno_modes_type { @@ -43,11 +50,23 @@ char __is_text_file(FILE *p) int _open(const char *_path, int _oflag,...) { +#if !defined(NDEBUG) && defined(DBG) + va_list arg; + int pmode; +#endif HANDLE hFile; DWORD dwDesiredAccess = 0; DWORD dwShareMode = 0; DWORD dwCreationDistribution = 0; DWORD dwFlagsAndAttributes = 0; + DWORD dwLastError; + +#if !defined(NDEBUG) && defined(DBG) + va_start(arg, _oflag); + pmode = va_arg(arg, int); +#endif + + DPRINT("_open('%s', %x, (%x))\n", _path, _oflag, pmode); if (( _oflag & S_IREAD ) == S_IREAD) dwShareMode = FILE_SHARE_READ; @@ -97,10 +116,16 @@ int _open(const char *_path, int _oflag,...) dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN; if (( _oflag & _O_TEMPORARY ) == _O_TEMPORARY ) + { dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; + DPRINT("FILE_FLAG_DELETE_ON_CLOSE\n"); + } if (( _oflag & _O_SHORT_LIVED ) == _O_SHORT_LIVED ) + { dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; + DPRINT("FILE_FLAG_DELETE_ON_CLOSE\n"); + } hFile = CreateFileA(_path, dwDesiredAccess, @@ -110,19 +135,44 @@ int _open(const char *_path, int _oflag,...) dwFlagsAndAttributes, NULL); if (hFile == (HANDLE)-1) + { + dwLastError = GetLastError(); + if (dwLastError == ERROR_ALREADY_EXISTS) + { + DPRINT("ERROR_ALREADY_EXISTS\n"); + __set_errno(EEXIST); + } + else + { + DPRINT("%x\n", dwLastError); + __set_errno(ENOFILE); + } return -1; + } + DPRINT("OK\n"); return __fileno_alloc(hFile,_oflag); } int _wopen(const wchar_t *_path, int _oflag,...) { +#if !defined(NDEBUG) && defined(DBG) + va_list arg; + int pmode; +#endif HANDLE hFile; DWORD dwDesiredAccess = 0; DWORD dwShareMode = 0; DWORD dwCreationDistribution = 0; DWORD dwFlagsAndAttributes = 0; +#if !defined(NDEBUG) && defined(DBG) + va_start(arg, _oflag); + pmode = va_arg(arg, int); +#endif + + DPRINT("_wopen('%S', %x, (%x))\n", _path, _oflag, pmode); + if (( _oflag & S_IREAD ) == S_IREAD) dwShareMode = FILE_SHARE_READ; else if ( ( _oflag & S_IWRITE) == S_IWRITE ) { @@ -223,7 +273,7 @@ __fileno_alloc(HANDLE hFile, int mode) memcpy(fileno_modes, old_fileno_modes, oldcount * sizeof(fileno_modes_type)); free ( old_fileno_modes ); } - memset(fileno_modes + oldcount, 0, (maxfno-oldcount)*sizeof(fileno_modes)); + memset(fileno_modes + oldcount, -1, (maxfno-oldcount)*sizeof(fileno_modes)); } /* Fill in the value */