LexLeo 0.0.0-dev+f8e5087-dirty
Technical documentation
Loading...
Searching...
No Matches
osal_file_win32.c File Reference

Win32 / CRT backend implementation of the osal_file module. More...

Include dependency graph for osal_file_win32.c:

Go to the source code of this file.

Functions

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_win32_error (DWORD err)
 Map a Win32 error code to an osal_file_status_t.
 
static const wchar_t * osal_file_mode_w (const char *mode)
 Return the wide-character mode string matching a portable file mode.
 
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 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 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_flush (OSAL_FILE *stream)
 Flush buffered output associated with an open OSAL_FILE.
 
static osal_file_status_t osal_file_close (OSAL_FILE *stream)
 Close an open OSAL_FILE and release its associated wrapper.
 
const osal_file_ops_tosal_file_default_ops (void)
 Return the default Win32 / CRT OSAL file operations table.
 

Detailed Description

This translation unit provides the active low-level osal_file operations for Windows platforms.

It implements:

  • platform-to-OSAL status mapping for CRT errno values,
  • platform-to-OSAL status mapping for Win32 GetLastError() values,
  • UTF-8 to UTF-16 pathname conversion for wide-character file opening,
  • file acquisition through _wfopen(),
  • element-oriented reads and writes through fread() and fwrite(),
  • buffered output flushing through fflush(),
  • resource release through fclose(),
  • publication of the default osal_file_ops_t table for this backend.

Definition in file osal_file_win32.c.

Function Documentation

◆ osal_file_close()

static osal_file_status_t osal_file_close ( OSAL_FILE stream)
static

This private callback implements the public osal_file_ops_t::close contract for the active Windows backend.

Parameters
streamOpen OSAL_FILE handle to close.
Returns
OSAL_FILE_STATUS_OK on success, or an error status on failure.

Definition at line 555 of file osal_file_win32.c.

◆ osal_file_default_ops()

const osal_file_ops_t * osal_file_default_ops ( void  )

Return the default POSIX / C stdio OSAL file operations table.

Return the default OSAL file operations for the active platform.

Returns
A pointer to the default osal_file_ops_t table for this backend.

Definition at line 575 of file osal_file_win32.c.

◆ osal_file_flush()

static osal_file_status_t osal_file_flush ( OSAL_FILE stream)
static

This private callback implements the public osal_file_ops_t::flush contract for the active Windows backend.

Parameters
streamOpen OSAL_FILE handle.
Returns
OSAL_FILE_STATUS_OK on success, or an error status on failure.

Definition at line 531 of file osal_file_win32.c.

◆ osal_file_map_errno()

static osal_file_status_t osal_file_map_errno ( int  errnum)
static
Parameters
errnumCRT error value to translate.
Returns
The corresponding portable OSAL file status.
Note
Unrecognized CRT errors are mapped to OSAL_FILE_STATUS_IO.

Definition at line 52 of file osal_file_win32.c.

◆ osal_file_mode_w()

static const wchar_t * osal_file_mode_w ( const char *  mode)
static
Parameters
modePortable file access mode string.
Returns
The corresponding wide-character mode string, or NULL if mode is not supported by the portable osal_file contract.

Definition at line 248 of file osal_file_win32.c.

◆ osal_file_open()

static osal_file_status_t osal_file_open ( OSAL_FILE **  out,
const char *  pathname,
const char *  mode,
const osal_mem_ops_t mem_ops 
)
static

This private callback implements the public osal_file_ops_t::open contract for the active Windows backend.

Parameters
[out]outReceives the acquired OSAL_FILE handle on success.
pathnamePathname of the file resource to open, expressed as a project-level UTF-8 string.
modePortable file access mode string.
mem_opsMemory operations table used to allocate the OSAL file wrapper and temporary pathname conversion buffers.
Returns
OSAL_FILE_STATUS_OK on success, or an error status on failure.

Definition at line 352 of file osal_file_win32.c.

◆ osal_file_read()

static size_t osal_file_read ( void *  ptr,
size_t  size,
size_t  nmemb,
OSAL_FILE stream,
osal_file_status_t st 
)
static

This private callback implements the public osal_file_ops_t::read contract for the active Windows backend.

Parameters
ptrDestination buffer.
sizeSize in bytes of each element.
nmembNumber of elements to read.
streamOpen OSAL_FILE handle.
[out]stReceives the operation status.
Returns
The number of elements successfully read.

Definition at line 437 of file osal_file_win32.c.

◆ osal_file_win32_error()

static osal_file_status_t osal_file_win32_error ( DWORD  err)
static
Parameters
errWin32 error code to translate.
Returns
The corresponding portable OSAL file status.
Note
Unrecognized Win32 errors are mapped to OSAL_FILE_STATUS_IO.

Definition at line 185 of file osal_file_win32.c.

◆ osal_file_write()

static size_t osal_file_write ( const void *  ptr,
size_t  size,
size_t  nmemb,
OSAL_FILE stream,
osal_file_status_t st 
)
static

This private callback implements the public osal_file_ops_t::write contract for the active Windows backend.

Parameters
ptrSource buffer.
sizeSize in bytes of each element.
nmembNumber of elements to write.
streamOpen OSAL_FILE handle.
[out]stReceives the operation status.
Returns
The number of elements successfully written.

Definition at line 490 of file osal_file_win32.c.

◆ osal_utf8_to_utf16_dup()

static osal_file_status_t osal_utf8_to_utf16_dup ( wchar_t **  out_wstr,
const char *  utf8,
const osal_mem_ops_t mem_ops 
)
static
Parameters
[out]out_wstrReceives the allocated UTF-16 duplicate on success.
utf8Source UTF-8 string.
mem_opsMemory operations table used to allocate the duplicate.
Returns
OSAL_FILE_STATUS_OK on success, or an error status on failure.
Note
This helper uses MultiByteToWideChar() with CP_UTF8 and MB_ERR_INVALID_CHARS.

Definition at line 281 of file osal_file_win32.c.