Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_mem_util.h File Reference

Thin, MISRA-visible wrappers over the three raw memory-block primitives (fill/copy/compare) every other safeAPIFreamwork or downstream-application module needs but has no business calling libc's <string.h> directly for - sapi_mem_set()/sapi_mem_copy()/ sapi_mem_compare() are the ONE sanctioned call site for each underlying libc function, so an audit for "does this codebase call libc string/memory functions directly" has exactly one file to check instead of grepping every translation unit for <string.h>. Deliberately NOT a "safe string library" (no strcpy/strcat/strlen-style variable-length text handling) - this framework and every application built on it work in fixed-size buffers throughout (CLAUDE.md: no malloc/free), so the only primitives actually needed are fixed-length block operations. More...

#include <stddef.h>
#include <string.h>
Include dependency graph for sapi_mem_util.h:

Go to the source code of this file.

Functions

static void sapi_mem_set (void *dest, int value, size_t count)
 Fills count bytes starting at dest with value - the one sanctioned call site for libc memset() in this framework (see this file's own doc).
static void sapi_mem_copy (void *dest, const void *src, size_t count)
 Copies count bytes from src to dest - the one sanctioned call site for libc memcpy() in this framework (see this file's own doc).
static int sapi_mem_compare (const void *a, const void *b, size_t count)
 Byte-for-byte compares count bytes of a against b - the one sanctioned call site for libc memcmp() in this framework (see this file's own doc).

Detailed Description

Thin, MISRA-visible wrappers over the three raw memory-block primitives (fill/copy/compare) every other safeAPIFreamwork or downstream-application module needs but has no business calling libc's <string.h> directly for - sapi_mem_set()/sapi_mem_copy()/ sapi_mem_compare() are the ONE sanctioned call site for each underlying libc function, so an audit for "does this codebase call libc string/memory functions directly" has exactly one file to check instead of grepping every translation unit for <string.h>. Deliberately NOT a "safe string library" (no strcpy/strcat/strlen-style variable-length text handling) - this framework and every application built on it work in fixed-size buffers throughout (CLAUDE.md: no malloc/free), so the only primitives actually needed are fixed-length block operations.

static inline, header-only, no backend/.c file: these are trivial, stateless wrappers with no OS dependency at all (unlike the seven real OAL services - sapi_timer, sapi_nvm, sapi_memory, etc. - see sapi_appmanager.h's own note on that distinction) - same convention as sapi_notify.h's SAFEAPI_DECLARE_CALLBACK_LIST (ADR-030).

Definition in file sapi_mem_util.h.

Function Documentation

◆ sapi_mem_set()

void sapi_mem_set ( void * dest,
int value,
size_t count )
inlinestatic

Fills count bytes starting at dest with value - the one sanctioned call site for libc memset() in this framework (see this file's own doc).

Parameters
destCaller-owned storage, at least count bytes. Must not be NULL unless count is 0.
valueByte value to write, same truncation-to-unsigned-char convention as memset() itself.
countNumber of bytes to fill; 0 is a no-op.

Definition at line 39 of file sapi_mem_util.h.

◆ sapi_mem_copy()

void sapi_mem_copy ( void * dest,
const void * src,
size_t count )
inlinestatic

Copies count bytes from src to dest - the one sanctioned call site for libc memcpy() in this framework (see this file's own doc).

Parameters
destDestination, caller-owned, at least count bytes. Must not be NULL unless count is 0.
srcSource, caller-owned, at least count bytes. Must not overlap dest (same contract as memcpy() itself - use a genuinely overlap-safe primitive instead if that is ever needed; none is provided here since nothing in this codebase currently copies overlapping ranges). Must not be NULL unless count is 0.
countNumber of bytes to copy; 0 is a no-op.

Definition at line 56 of file sapi_mem_util.h.

◆ sapi_mem_compare()

int sapi_mem_compare ( const void * a,
const void * b,
size_t count )
inlinestatic

Byte-for-byte compares count bytes of a against b - the one sanctioned call site for libc memcmp() in this framework (see this file's own doc).

Parameters
a,bCaller-owned, at least count bytes each. Must not be NULL unless count is 0.
countNumber of bytes to compare; 0 always returns 0.
Returns
0 if every byte matches; nonzero otherwise. Callers should only rely on the zero/nonzero distinction, not the sign - this framework never orders byte buffers by memcmp()'s sign.

Definition at line 70 of file sapi_mem_util.h.