25#include "internal/osal_file_internal.h"
27#include "osal/file/osal_file_ops.h"
191 case ERROR_FILE_NOT_FOUND:
192 case ERROR_PATH_NOT_FOUND:
195 case ERROR_ACCESS_DENIED:
196 case ERROR_SHARING_VIOLATION:
199 case ERROR_ALREADY_EXISTS:
200 case ERROR_FILE_EXISTS:
203 case ERROR_DISK_FULL:
204 case ERROR_HANDLE_DISK_FULL:
207 case ERROR_FILENAME_EXCED_RANGE:
210 case ERROR_DIRECTORY:
213 case ERROR_INVALID_NAME:
214 case ERROR_BAD_PATHNAME:
215 case ERROR_INVALID_PARAMETER:
216 case ERROR_NO_UNICODE_TRANSLATION:
219 case ERROR_TOO_MANY_OPEN_FILES:
222 case ERROR_NOT_READY:
223 case ERROR_DEV_NOT_EXIST:
226 case ERROR_OUTOFMEMORY:
227 case ERROR_NOT_ENOUGH_MEMORY:
230 case ERROR_WRITE_PROTECT:
294 int wlen = MultiByteToWideChar(
296 MB_ERR_INVALID_CHARS,
305 size_t bytes = (size_t)wlen *
sizeof(
wchar_t);
307 wchar_t *tmp = mem_ops->
malloc(bytes);
311 int converted = MultiByteToWideChar(
313 MB_ERR_INVALID_CHARS,
319 if (converted <= 0) {
354 const char *pathname,
361 || pathname[0] ==
'\0'
381 wchar_t *wpath = NULL;
386 FILE *fp = _wfopen(wpath, wmode);
388 mem_ops->
free(wpath);
457 size_t ret = fread(ptr, size, nmemb, stream->
fp);
459 if (ret < nmemb && ferror(stream->
fp))
510 size_t ret = fwrite(ptr, size, nmemb, stream->
fp);
512 if (ret < nmemb && ferror(stream->
fp))
533 if (!stream || !stream->
fp)
536 if (fflush(stream->
fp) != 0)
557 if (!stream || !stream->
fp)
560 if (fclose(stream->
fp) != 0)
@ OSAL_FILE_STATUS_EXISTS
@ OSAL_FILE_STATUS_NAMETOOLONG
@ OSAL_FILE_STATUS_INVALID
@ OSAL_FILE_STATUS_NOTDIR
#define LEXLEO_ASSERT(expr)
int osal_strcmp(const char *s1, const char *s2)
static size_t osal_file_read(void *ptr, size_t size, size_t nmemb, OSAL_FILE *stream, osal_file_status_t *st)
Read elements from an open OSAL_FILE.
static size_t osal_file_write(const void *ptr, size_t size, size_t nmemb, OSAL_FILE *stream, osal_file_status_t *st)
Write elements to an open OSAL_FILE.
static osal_file_status_t osal_file_map_errno(int errnum)
Map a CRT errno value to an osal_file_status_t.
static osal_file_status_t osal_file_close(OSAL_FILE *stream)
Close an open OSAL_FILE and release its associated wrapper.
static osal_file_status_t osal_utf8_to_utf16_dup(wchar_t **out_wstr, const char *utf8, const osal_mem_ops_t *mem_ops)
Duplicate a UTF-8 string as a UTF-16 wide-character string.
static const wchar_t * osal_file_mode_w(const char *mode)
Return the wide-character mode string matching a portable file mode.
const osal_file_ops_t * osal_file_default_ops(void)
Return the default Win32 / CRT OSAL file operations table.
static osal_file_status_t osal_file_open(OSAL_FILE **out, const char *pathname, const char *mode, const osal_mem_ops_t *mem_ops)
Open a file resource through the Win32 / CRT backend.
static osal_file_status_t osal_file_win32_error(DWORD err)
Map a Win32 error code to an osal_file_status_t.
static osal_file_status_t osal_file_flush(OSAL_FILE *stream)
Flush buffered output associated with an open OSAL_FILE.
Private representation of an acquired OSAL file handle.
FILE * fp
Underlying C standard I/O file handle.
const osal_mem_ops_t * mem_ops
Memory operations table used to release this wrapper.
Operations table for the low-level OSAL file abstraction.
osal_file_status_t(* open)(OSAL_FILE **out, const char *pathname, const char *mode, const osal_mem_ops_t *mem_ops)
Open a file resource.
void *(* malloc)(size_t size)