Author: akhaldi Date: Mon May 12 20:10:38 2014 New Revision: 63267
URL: http://svn.reactos.org/svn/reactos?rev=63267&view=rev Log: [CRT] * Reorder some functions. No code changes! CORE-8080
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?re... ============================================================================== --- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Mon May 12 20:10:38 2014 @@ -1657,24 +1657,20 @@ }
/********************************************************************* - * _sopen_s (MSVCRT.@) - */ -int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmode ) + * _wsopen_s (MSVCRT.@) + */ +int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int pmode ) { DWORD access = 0, creation = 0, attrib; + SECURITY_ATTRIBUTES sa; DWORD sharing; int wxflag; HANDLE hand; - SECURITY_ATTRIBUTES sa; - - TRACE("fd*: %p file: (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n", - fd, path, oflags, shflags, pmode); - - if (!fd) - { - MSVCRT_INVALID_PMT("null out fd pointer", EINVAL); - return EINVAL; - } + + TRACE("fd*: %p :file (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n", + fd, debugstr_w(path), oflags, shflags, pmode); + + if (!MSVCRT_CHECK_PMT( fd != NULL )) return EINVAL;
*fd = -1; wxflag = split_oflags(oflags); @@ -1736,25 +1732,89 @@
sa.nLength = sizeof( SECURITY_ATTRIBUTES ); sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = (oflags & _O_NOINHERIT) ? FALSE : TRUE; - - hand = CreateFileA(path, access, sharing, &sa, creation, attrib, 0); + sa.bInheritHandle = !(oflags & _O_NOINHERIT); + + if ((oflags&(_O_WTEXT|_O_U16TEXT|_O_U8TEXT)) + && (creation==OPEN_ALWAYS || creation==OPEN_EXISTING) + && !(access&GENERIC_READ)) + { + hand = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, + &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + if (hand != INVALID_HANDLE_VALUE) + { + oflags = check_bom(hand, oflags, FALSE); + CloseHandle(hand); + } + else + oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT); + } + + hand = CreateFileW(path, access, sharing, &sa, creation, attrib, 0); if (hand == INVALID_HANDLE_VALUE) { - WARN(":failed-last error (%d)\n", GetLastError()); + WARN(":failed-last error (%d)\n",GetLastError()); _dosmaperr(GetLastError()); return *_errno(); }
+ if (oflags & (_O_WTEXT|_O_U16TEXT|_O_U8TEXT)) + { + if ((access & GENERIC_WRITE) && (creation==CREATE_NEW + || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING + || (creation==OPEN_ALWAYS && GetLastError()==ERROR_ALREADY_EXISTS))) + { + if (oflags & _O_U8TEXT) + { + DWORD written = 0, tmp; + + while(written!=sizeof(utf8_bom) && WriteFile(hand, (char*)utf8_bom+written, + sizeof(utf8_bom)-written, &tmp, NULL)) + written += tmp; + if (written != sizeof(utf8_bom)) { + WARN("error writing BOM\n"); + CloseHandle(hand); + _dosmaperr(GetLastError()); + return *_errno(); + } + } + else + { + DWORD written = 0, tmp; + + while(written!=sizeof(utf16_bom) && WriteFile(hand, (char*)utf16_bom+written, + sizeof(utf16_bom)-written, &tmp, NULL)) + written += tmp; + if (written != sizeof(utf16_bom)) + { + WARN("error writing BOM\n"); + CloseHandle(hand); + _dosmaperr(GetLastError()); + return *_errno(); + } + } + } + else if (access & GENERIC_READ) + oflags = check_bom(hand, oflags, TRUE); + } + *fd = alloc_fd(hand, wxflag); + if (*fd == -1) + return *_errno(); + + if (oflags & _O_WTEXT) + get_ioinfo(*fd)->exflag |= EF_UTF16|EF_UNK_UNICODE; + else if (oflags & _O_U16TEXT) + get_ioinfo(*fd)->exflag |= EF_UTF16; + else if (oflags & _O_U8TEXT) + get_ioinfo(*fd)->exflag |= EF_UTF8;
TRACE(":fd (%d) handle (%p)\n", *fd, hand); return 0; }
/********************************************************************* - * _sopen (MSVCRT.@) - */ -int CDECL _sopen( const char *path, int oflags, int shflags, ... ) + * _wsopen (MSVCRT.@) + */ +int CDECL _wsopen( const wchar_t *path, int oflags, int shflags, ... ) { int pmode; int fd; @@ -1770,25 +1830,29 @@ else pmode = 0;
- _sopen_s(&fd, path, oflags, shflags, pmode); + _wsopen_s(&fd, path, oflags, shflags, pmode); return fd; }
/********************************************************************* - * _wsopen_s (MSVCRT.@) - */ -int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int pmode ) + * _sopen_s (MSVCRT.@) + */ +int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmode ) { DWORD access = 0, creation = 0, attrib; - SECURITY_ATTRIBUTES sa; DWORD sharing; int wxflag; HANDLE hand; - - TRACE("fd*: %p :file (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n", - fd, debugstr_w(path), oflags, shflags, pmode); - - if (!MSVCRT_CHECK_PMT( fd != NULL )) return EINVAL; + SECURITY_ATTRIBUTES sa; + + TRACE("fd*: %p file: (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n", + fd, path, oflags, shflags, pmode); + + if (!fd) + { + MSVCRT_INVALID_PMT("null out fd pointer", EINVAL); + return EINVAL; + }
*fd = -1; wxflag = split_oflags(oflags); @@ -1850,89 +1914,25 @@
sa.nLength = sizeof( SECURITY_ATTRIBUTES ); sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = !(oflags & _O_NOINHERIT); - - if ((oflags&(_O_WTEXT|_O_U16TEXT|_O_U8TEXT)) - && (creation==OPEN_ALWAYS || creation==OPEN_EXISTING) - && !(access&GENERIC_READ)) - { - hand = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, - &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (hand != INVALID_HANDLE_VALUE) - { - oflags = check_bom(hand, oflags, FALSE); - CloseHandle(hand); - } - else - oflags &= ~(_O_WTEXT|_O_U16TEXT|_O_U8TEXT); - } - - hand = CreateFileW(path, access, sharing, &sa, creation, attrib, 0); + 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()); + WARN(":failed-last error (%d)\n", GetLastError()); _dosmaperr(GetLastError()); return *_errno(); }
- if (oflags & (_O_WTEXT|_O_U16TEXT|_O_U8TEXT)) - { - if ((access & GENERIC_WRITE) && (creation==CREATE_NEW - || creation==CREATE_ALWAYS || creation==TRUNCATE_EXISTING - || (creation==OPEN_ALWAYS && GetLastError()==ERROR_ALREADY_EXISTS))) - { - if (oflags & _O_U8TEXT) - { - DWORD written = 0, tmp; - - while(written!=sizeof(utf8_bom) && WriteFile(hand, (char*)utf8_bom+written, - sizeof(utf8_bom)-written, &tmp, NULL)) - written += tmp; - if (written != sizeof(utf8_bom)) { - WARN("error writing BOM\n"); - CloseHandle(hand); - _dosmaperr(GetLastError()); - return *_errno(); - } - } - else - { - DWORD written = 0, tmp; - - while(written!=sizeof(utf16_bom) && WriteFile(hand, (char*)utf16_bom+written, - sizeof(utf16_bom)-written, &tmp, NULL)) - written += tmp; - if (written != sizeof(utf16_bom)) - { - WARN("error writing BOM\n"); - CloseHandle(hand); - _dosmaperr(GetLastError()); - return *_errno(); - } - } - } - else if (access & GENERIC_READ) - oflags = check_bom(hand, oflags, TRUE); - } - *fd = alloc_fd(hand, wxflag); - if (*fd == -1) - return *_errno(); - - if (oflags & _O_WTEXT) - get_ioinfo(*fd)->exflag |= EF_UTF16|EF_UNK_UNICODE; - else if (oflags & _O_U16TEXT) - get_ioinfo(*fd)->exflag |= EF_UTF16; - else if (oflags & _O_U8TEXT) - get_ioinfo(*fd)->exflag |= EF_UTF8;
TRACE(":fd (%d) handle (%p)\n", *fd, hand); return 0; }
/********************************************************************* - * _wsopen (MSVCRT.@) - */ -int CDECL _wsopen( const wchar_t *path, int oflags, int shflags, ... ) + * _sopen (MSVCRT.@) + */ +int CDECL _sopen( const char *path, int oflags, int shflags, ... ) { int pmode; int fd; @@ -1948,7 +1948,7 @@ else pmode = 0;
- _wsopen_s(&fd, path, oflags, shflags, pmode); + _sopen_s(&fd, path, oflags, shflags, pmode); return fd; }