msvcrt: Added support for commit flag in fopen.

oldstable
Piotr Caban 2013-01-18 11:03:13 +01:00 committed by Alexandre Julliard
parent 89f044db15
commit 7f4e1c65b1
2 changed files with 42 additions and 28 deletions

View File

@ -764,6 +764,34 @@ int CDECL MSVCRT__wunlink(const MSVCRT_wchar_t *path)
return -1;
}
/*********************************************************************
* _commit (MSVCRT.@)
*/
int CDECL MSVCRT__commit(int fd)
{
HANDLE hand = msvcrt_fdtoh(fd);
TRACE(":fd (%d) handle (%p)\n",fd,hand);
if (hand == INVALID_HANDLE_VALUE)
return -1;
if (!FlushFileBuffers(hand))
{
if (GetLastError() == ERROR_INVALID_HANDLE)
{
/* FlushFileBuffers fails for console handles
* so we ignore this error.
*/
return 0;
}
TRACE(":failed-last error (%d)\n",GetLastError());
msvcrt_set_errno(GetLastError());
return -1;
}
TRACE(":ok\n");
return 0;
}
/* flush_all_buffers calls MSVCRT_fflush which calls flush_all_buffers */
int CDECL MSVCRT_fflush(MSVCRT_FILE* file);
@ -811,6 +839,9 @@ int CDECL MSVCRT_fflush(MSVCRT_FILE* file)
MSVCRT__lock_file(file);
res = msvcrt_flush_buffer(file);
if(!res && (file->_flag & MSVCRT__IOCOMMIT))
res = MSVCRT__commit(file->_file) ? MSVCRT_EOF : 0;
MSVCRT__unlock_file(file);
return res;
@ -851,34 +882,6 @@ int CDECL MSVCRT__close(int fd)
return ret;
}
/*********************************************************************
* _commit (MSVCRT.@)
*/
int CDECL MSVCRT__commit(int fd)
{
HANDLE hand = msvcrt_fdtoh(fd);
TRACE(":fd (%d) handle (%p)\n",fd,hand);
if (hand == INVALID_HANDLE_VALUE)
return -1;
if (!FlushFileBuffers(hand))
{
if (GetLastError() == ERROR_INVALID_HANDLE)
{
/* FlushFileBuffers fails for console handles
* so we ignore this error.
*/
return 0;
}
TRACE(":failed-last error (%d)\n",GetLastError());
msvcrt_set_errno(GetLastError());
return -1;
}
TRACE(":ok\n");
return 0;
}
/*********************************************************************
* _dup2 (MSVCRT.@)
* NOTES
@ -1284,6 +1287,8 @@ static int msvcrt_get_flags(const MSVCRT_wchar_t* mode, int *open_flags, int* st
return -1;
}
*stream_flags |= MSVCRT__commode;
while (*mode && *mode!=',')
switch (*mode++)
{
@ -1301,6 +1306,12 @@ static int msvcrt_get_flags(const MSVCRT_wchar_t* mode, int *open_flags, int* st
case 'T':
*open_flags |= MSVCRT__O_SHORT_LIVED;
break;
case 'c':
*stream_flags |= MSVCRT__IOCOMMIT;
break;
case 'n':
*stream_flags &= ~MSVCRT__IOCOMMIT;
break;
case '+':
case ' ':
case 'a':

View File

@ -238,6 +238,8 @@ extern MSVCRT_wchar_t ** msvcrt_SnapshotOfEnvironmentW(MSVCRT_wchar_t **) DECLSP
MSVCRT_wchar_t *msvcrt_wstrdupa(const char *) DECLSPEC_HIDDEN;
extern unsigned int MSVCRT__commode;
/* FIXME: This should be declared in new.h but it's not an extern "C" so
* it would not be much use anyway. Even for Winelib applications.
*/
@ -713,6 +715,7 @@ struct MSVCRT__stat64 {
#define MSVCRT__IOERR 0x0020
#define MSVCRT__IOSTRG 0x0040
#define MSVCRT__IORW 0x0080
#define MSVCRT__IOCOMMIT 0x4000
#define MSVCRT__S_IEXEC 0x0040
#define MSVCRT__S_IWRITE 0x0080