ReactOS 0.4.16-dev-981-g80eb313
commit.cpp
Go to the documentation of this file.
1//
2// commit.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines _commit(), which flushes a file buffer to disk.
7//
9
10
11
12// Flushes the buffer for the given file to disk.
13//
14// On success, 0 is returned. On failure, -1 is returned and errno is set.
15extern "C" int __cdecl _commit(int const fh)
16{
17 _CHECK_FH_RETURN(fh, EBADF, -1);
18 _VALIDATE_RETURN((fh >= 0 && (unsigned)fh < (unsigned)_nhandle), EBADF, -1);
19 _VALIDATE_RETURN((_osfile(fh) & FOPEN), EBADF, -1);
20
21 return __acrt_lowio_lock_fh_and_call(fh, [&]()
22 {
23 if (_osfile(fh) & FOPEN)
24 {
25 if (FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(fh))))
26 return 0; // Success
27
29 }
30
31 errno = EBADF;
32
33 _ASSERTE(("Invalid file descriptor. File possibly closed by a different thread",0));
34 return -1;
35 });
36}
#define EBADF
Definition: acclib.h:82
#define __cdecl
Definition: accygwin.h:79
int __cdecl _commit(int const fh)
Definition: commit.cpp:15
#define _CHECK_FH_RETURN(handle, errorcode, retexpr)
int _nhandle
Definition: ioinit.cpp:34
auto __acrt_lowio_lock_fh_and_call(int const fh, Action &&action) -> decltype(action())
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
#define FOPEN
#define _doserrno
Definition: stdlib.h:131
#define errno
Definition: errno.h:18
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)
#define _osfile(i)
Definition: internal.h:72
DWORD WINAPI GetLastError(void)
Definition: except.c:1042