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