Author: akhaldi
Date: Sat May 17 10:41:36 2014
New Revision: 63322
URL:
http://svn.reactos.org/svn/reactos?rev=63322&view=rev
Log:
[CRT]
* Update _sopen_s().
* Fixes some msvcrt tests.
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?r…
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Sat May 17 10:41:36 2014
@@ -1842,94 +1842,15 @@
*/
int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmode )
{
- DWORD access = 0, creation = 0, attrib;
- 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;
- }
-
- *fd = -1;
- 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)
- {
- 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 EINVAL;
- }
- 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 *_errno();
- }
-
- *fd = alloc_fd(hand, wxflag);
-
- TRACE(":fd (%d) handle (%p)\n", *fd, hand);
- return 0;
+ wchar_t *pathW;
+ int ret;
+
+ if(!MSVCRT_CHECK_PMT(path && (pathW = msvcrt_wstrdupa(path))))
+ return EINVAL;
+
+ ret = _wsopen_s(fd, pathW, oflags, shflags, pmode);
+ free(pathW);
+ return ret;
}
/*********************************************************************