ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mkbookimg_names.h File Reference

Derive an on-card file name from a source book path (long-name capable). More...

#include <stddef.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for mkbookimg_names.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  mkbookimg_name_limit_t : uint32_t { k_mkbookimg_name_cap = 256U }
 Bound on a derived on-card file name. More...

Functions

static const char * mkbookimg_basename (const char *path)
 Return the basename of path: the run after its last '/'.
static bool mkbookimg_dest_name (const char *path, char *out, size_t cap)
 Derive the on-card destination name for a source book path.

Detailed Description

Derive an on-card file name from a source book path (long-name capable).

mkbookimg packs each input book onto the FAT card under a HUMAN-READABLE name: the source file's own basename, stored verbatim now that ra8_fs writes VFAT long names (#600). Before that landed the tool emitted BOOK01, BOOK02, ... under a forced 8.3 extension and threw the real name away (#633 removed that workaround).

This header is the pure, board-free name derivation the tool and its host round-trip test both call, so the test exercises the SAME logic the packer ships rather than a copy of it.

Since
0.1.0

Definition in file mkbookimg_names.h.

Enumeration Type Documentation

◆ mkbookimg_name_limit_t

enum mkbookimg_name_limit_t : uint32_t

Bound on a derived on-card file name.

The buffer must hold the widest VFAT long name ra8_fs will file (247 characters) plus a NUL, so 256 clears it with headroom while keeping the derivation on a fixed, statically-bounded buffer.

Since
0.1.0
Enumerator
k_mkbookimg_name_cap 

Destination-name buffer bytes incl.

NUL (>= FAT 247 + 1).

Definition at line 34 of file mkbookimg_names.h.

Function Documentation

◆ mkbookimg_basename()

const char * mkbookimg_basename ( const char * path)
inlinestatic

Return the basename of path: the run after its last '/'.

Scans path once for the final path separator and returns a pointer just past it, so content/library/Meditations.rabook yields Meditations.rabook and a already-bare name is returned unchanged. Only '/' is treated as a separator (the tool takes POSIX host paths on its command line).

Parameters
[in]pathNUL-terminated source path (non-NULL).
Returns
Pointer into path at the first character after the last '/', or path itself when it contains no separator.
Return values
non-NULLAlways a valid pointer within path (never past its NUL).
Precondition
path is non-NULL and NUL-terminated.
path is a host filesystem path (separators are '/').
Postcondition
The returned pointer aliases path; no bytes are copied or modified.
The result points at a NUL when path ends in '/'.
Note
Thread-safe: pure function over its argument.
Since
0.1.0

Definition at line 61 of file mkbookimg_names.h.

Referenced by internal_duplicate_name(), and mkbookimg_dest_name().

◆ mkbookimg_dest_name()

bool mkbookimg_dest_name ( const char * path,
char * out,
size_t cap )
inlinestatic

Derive the on-card destination name for a source book path.

Copies the source's basename (mkbookimg_basename) verbatim into out and NUL-terminates it, so the name the caller sees on the card is the name they packed. The copy is rejected – rather than truncated – when the basename is empty or does not fit cap, so a name is either filed in full or refused.

Parameters
[in]pathSource path on the host (non-NULL, NUL-terminated).
[out]outDestination-name buffer; receives the NUL-terminated name.
[in]capCapacity of out in bytes (> 0; use k_mkbookimg_name_cap).
Returns
Whether a usable destination name was written.
Return values
trueA non-empty basename that fit cap was written and terminated.
falsepath / out is NULL, cap is 0, the basename is empty, or it does not fit cap (nothing usable is left in out).
Precondition
path is non-NULL and NUL-terminated.
out points at cap writable bytes.
Postcondition
On true, out holds the basename of path including its terminator.
On false, out is not relied upon (no truncated name is filed).
Note
Thread-safe: writes only out.
Since
0.1.0

Definition at line 99 of file mkbookimg_names.h.

References memcpy(), mkbookimg_basename(), and strlen().

Referenced by internal_write_books().