libxtc
0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
os_errno.h
1
/*-
2
* Copyright (c) 2026, The XTC Project
3
* Use of this source code is governed by the ISC License.
4
*
5
* src/inc/os_errno.h
6
* Canonical POSIX errno -> XTC_E_* translation for the OS layer
7
* (INTERNAL, __os_* surface), plus an internal override hook whose
8
* eventual audience is an embedder that shims the underlying
9
* syscalls (a custom VFS, a hosted/sandboxed libc); that hook gets a
10
* public xtc_* wrapper if/when a real embedder needs it (see the
11
* hook comment below). See M1_CLAIMS.md, Tm-errno.
12
*
13
* The rest of the runtime works exclusively in the XTC_E_* error
14
* space; this module is the ONE place a raw errno crosses into it.
15
* OS-layer wrappers call __os_errno_map(errno) at the syscall
16
* boundary instead of hand-rolling a per-file switch. Hot-path
17
* control-flow checks on a single specific value (e.g. EAGAIN ->
18
* XTC_E_AGAIN in the readiness loop) stay inline by design -- this
19
* module is for GENERAL failure translation, not fast-path branches.
20
*/
21
22
#ifndef XTC_OS_ERRNO_H
23
#define XTC_OS_ERRNO_H
24
25
#include "xtc_export.h"
26
27
/*
28
* Translate a POSIX errno value into a stable XTC_E_* code. Passing 0
29
* (no error) or an unrecognized value maps to XTC_E_IO -- the mapper is
30
* only ever consulted on a KNOWN failure, so "no mapping" means "some
31
* I/O-class error we do not distinguish", never success. Callers that
32
* need XTC_OK check the syscall return BEFORE calling this.
33
*
34
* If an embedder installed a hook, the hook is consulted first; a hook
35
* return of 0 means "defer to the built-in table".
36
*
37
* PUBLIC: int __os_errno_map __P((int));
38
*/
39
XTC_API
int
__os_errno_map(
int
posix_errno);
40
41
/*
42
* Translation-override hook (INTERNAL, __os_* surface). fn receives the
43
* raw errno and returns an XTC_E_* code, or 0 to fall through to the
44
* built-in table. Installing NULL restores the default (built-in table
45
* only). Thread-safe: the swap is a single atomic pointer store.
46
*
47
* Audience note: the eventual audience for overriding the errno mapping
48
* is an EMBEDDER that shims the underlying syscalls (a custom VFS, a
49
* hosted/sandboxed libc). That is a consumer action, and consumers use
50
* only the public xtc_* API (never __os_*), so when a real embedder
51
* needs this it gets a thin public wrapper (xtc_errno_set_hook /
52
* _get_hook) in an installed header -- exactly the pattern the
53
* allocator hook (__os_alloc_set_hook) follows. Until then this stays
54
* __os_*-internal rather than shipping a public API with no caller
55
* (YAGNI); __os_errno_map itself is unconditionally internal (library
56
* OS wrappers call it directly).
57
*
58
* PUBLIC: void __os_errno_set_hook __P((int (*)(int)));
59
* PUBLIC: int (*__os_errno_get_hook __P((void)))(int);
60
*/
61
XTC_API
void
__os_errno_set_hook(
int
(*fn)(
int
posix_errno));
62
XTC_API int (*__os_errno_get_hook(
void
))(
int
posix_errno);
63
64
#endif
/* XTC_OS_ERRNO_H */
src
inc
os_errno.h
Generated by
1.9.8