mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 23:06:00 +00:00
[CRT]
* Update _sopen_s(). * Fixes some msvcrt tests. CORE-8080 svn path=/trunk/; revision=63322
This commit is contained in:
parent
fa9bf9ef6e
commit
778c8e998c
1 changed files with 7 additions and 86 deletions
|
@ -1842,94 +1842,15 @@ int CDECL _wsopen( const wchar_t *path, int oflags, int shflags, ... )
|
||||||
*/
|
*/
|
||||||
int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmode )
|
int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmode )
|
||||||
{
|
{
|
||||||
DWORD access = 0, creation = 0, attrib;
|
wchar_t *pathW;
|
||||||
DWORD sharing;
|
int ret;
|
||||||
int wxflag;
|
|
||||||
HANDLE hand;
|
|
||||||
SECURITY_ATTRIBUTES sa;
|
|
||||||
|
|
||||||
TRACE("fd*: %p file: (%s) oflags: 0x%04x shflags: 0x%04x pmode: 0x%04x\n",
|
if(!MSVCRT_CHECK_PMT(path && (pathW = msvcrt_wstrdupa(path))))
|
||||||
fd, path, oflags, shflags, pmode);
|
|
||||||
|
|
||||||
if (!fd)
|
|
||||||
{
|
|
||||||
MSVCRT_INVALID_PMT("null out fd pointer", EINVAL);
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
*fd = -1;
|
ret = _wsopen_s(fd, pathW, oflags, shflags, pmode);
|
||||||
wxflag = split_oflags(oflags);
|
free(pathW);
|
||||||
switch (oflags & (_O_RDONLY | _O_WRONLY | _O_RDWR))
|
return ret;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue