3 This file is part of the Public Domain C Library (PDCLib).
\r
4 Permission is granted to use, modify, and / or redistribute at will.
\r
10 #include <_PDCLIB_glue.h>
\r
12 #include <windows.h>
\r
14 #if _PDCLIB_C_MIN(2011)
\r
15 _Static_assert(SEEK_SET == FILE_BEGIN, "SEEK_SET is incorrect");
\r
16 _Static_assert(SEEK_CUR == FILE_CURRENT, "SEEK_CUR is incorrect");
\r
17 _Static_assert(SEEK_END == FILE_END, "SEEK_END is incorrect");
\r
20 void _PDCLIB_w32errno(void);
\r
22 static bool readf( _PDCLIB_fd_t self, void * buf, size_t length,
\r
23 size_t * numBytesRead )
\r
25 DWORD dwLen = length > INT32_MAX ? INT32_MAX : length;
\r
27 if(ReadFile(self.pointer, buf, dwLen, &dwBytesRead, NULL)) {
\r
28 *numBytesRead = dwBytesRead;
\r
36 static bool writef( _PDCLIB_fd_t self, const void * buf, size_t length,
\r
37 size_t * numBytesWritten )
\r
39 DWORD dwLen = length > INT32_MAX ? INT32_MAX : length;
\r
40 DWORD dwBytesWritten;
\r
42 if(WriteFile(self.pointer, buf, dwLen, &dwBytesWritten, NULL)) {
\r
43 *numBytesWritten = dwBytesWritten;
\r
50 static bool seekf( _PDCLIB_fd_t self, int_fast64_t offset, int whence,
\r
51 int_fast64_t* newPos )
\r
53 LARGE_INTEGER liOffset;
\r
54 liOffset.QuadPart = offset;
\r
55 if(!SetFilePointerEx( self.pointer, liOffset, &liOffset, whence )) {
\r
60 *newPos = liOffset.QuadPart;
\r
64 static void closef( _PDCLIB_fd_t self )
\r
66 CloseHandle( self.pointer );
\r
69 const _PDCLIB_fileops_t _PDCLIB_fileops = {
\r
79 #include <_PDCLIB_test.h>
\r
83 // Tested by stdio test cases
\r
84 return TEST_RESULTS;
\r