CoreLib

Introducing CoreLib (ex libOS): A Modular C Library for RISC OS System Programming.

CoreLib is a modular ANSI C99 library for RISC OS that provides safe, structured wrappers around the native SWI interface. It is designed to support system-level C development by offering POSIX-inspired APIs, argument validation, and modular layout, all while following RISC OS conventions.


Key Features

 

Typed and Validated SWI Wrappers

Every function wraps one or more SWIs using clearly typed arguments and strict validation. Invalid pointers, buffer sizes, or values are checked before issuing the SWI call. Errors are returned as -1 with errno set via os_map_error().

POSIX-Like Function Signatures

Function names and semantics follow familiar Unix patterns, each prefixed with os_ for namespace clarity:

int os_open(const char *path, int flags, int mode);
int os_read(int fd, void *buf, size_t count);
int os_stat(const char *path, struct os_stat_t *st);

This simplifies porting and improves readability.

Combined Operations for Faster Development

Common sequences of operations are provided as utility functions. For example, to open, read, and close a file into memory:

char *buffer = NULL;
size_t buf_len = 0;
if (os_read_and_close(os_open("@.MyFile", O_RDONLY, 0), (void **) buffer, buf_len) >= 0) {
    // process buffer...
    
    free(buffer);
}

This helps reduce boilerplate and supports rapid development cycles.

Modular Layout

CoreLib is split into domains matching the SWI categories:

  • fs.c: file system
  • proc.c: environment and process variables
  • mem.c: memory operations
  • term.c: terminal I/O
  • event.c, service.c: system events and services

This structure makes the library easier to understand and extend.


Roadmap: CLib Independence

One of the long-term goals of CoreLib is to remove all dependency on the SharedCLibrary. This will enable use in low-level components such as standalone binaries, including Utility (Transient) file types.

While this is not yet complete, the design and implementation aim to make this transition straightforward.


Documentation


CoreLib brings structure and validation to the RISC OS API, improving system robustness and reliability. It makes low-level development safer, more portable (with future 64-bit support in mind), and easier to maintain.