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

POSIX / C stdio backend implementation of the osal_file module. More...

#include "internal/osal_file_internal.h"
#include "osal/file/osal_file_ops.h"
#include "osal/mem/osal_mem_ops.h"
#include "osal/mem/osal_mem.h"
#include "policy/lexleo_cstd_lib.h"
#include "policy/lexleo_cstd_io.h"
#include "policy/lexleo_cstd_errno.h"
#include "policy/lexleo_assert.h"
Include dependency graph for osal_file_posix.c:

Go to the source code of this file.

Functions

static osal_file_status_t osal_file_map_errno (int errnum)
 Map a platform errno value to an osal_file_status_t.
 
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 POSIX / C stdio 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 POSIX / C stdio OSAL file operations table.
 

Detailed Description

This translation unit provides the active low-level osal_file operations for POSIX-like platforms through the C standard I/O runtime.

It implements:

  • platform-to-OSAL status mapping for errno,
  • file acquisition through fopen(),
  • 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_posix.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 POSIX-like backend.

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

Definition at line 379 of file osal_file_posix.c.

◆ osal_file_default_ops()

const osal_file_ops_t * osal_file_default_ops ( void  )

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 401 of file osal_file_posix.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 POSIX-like backend.

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

Definition at line 353 of file osal_file_posix.c.

◆ osal_file_map_errno()

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

Definition at line 47 of file osal_file_posix.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 POSIX-like backend.

Parameters
[out]outReceives the acquired OSAL_FILE handle on success.
pathnamePathname of the file resource to open.
modePortable file access mode string.
mem_opsMemory operations table used to allocate the OSAL file wrapper.
Returns
OSAL_FILE_STATUS_OK on success, or an error status on failure.

Definition at line 190 of file osal_file_posix.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 POSIX-like 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 259 of file osal_file_posix.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 POSIX-like 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 312 of file osal_file_posix.c.