Declares the commonly used things in `libc` (`C` standard library).

Collection Info

View Source
Collection
core
Path
c/libc
Entries
660

Source Files

Constants

96

EXIT_SUCCESS #

Source
EXIT_SUCCESS :: 0

C does not declare what these values should be, as an implementation is free to use any two distinct values it wants to indicate success or failure. However, nobody actually does and everyone appears to have agreed upon these values.

FP_NAN #

Source
FP_NAN :: 0

Number classification constants. These do not have to match libc since we implement our own classification functions as libc requires they be macros, which means libc does not export standard functions for them.

INT8_MAX #

Source
INT8_MAX :: c.INT8_MAX

Copy C's rules for type promotion here by forcing the type on the literals.

math_errhandling #

Source
math_errhandling :: 2

Windows, Linux, macOS all use this mode.

memory_order_acq_rel #

Source
memory_order_acq_rel :: memory_order.acq_rel

memory_order_acquire #

Source
memory_order_acquire :: memory_order.acquire

memory_order_consume #

Source
memory_order_consume :: memory_order.consume

memory_order_relaxed #

Source
memory_order_relaxed :: memory_order.relaxed

memory_order_release #

Source
memory_order_release :: memory_order.release

memory_order_seq_cst #

Source
memory_order_seq_cst :: memory_order.seq_cst

TSS_DTOR_ITERATIONS #

Source
TSS_DTOR_ITERATIONS :: 4

_TSS_DTOR_ITERATIONS_IMP

WINT_MIN #

Source
WINT_MIN :: 0

Calculate these values correctly regardless of what type wchar_t actually is.

Types

117

div_t #

Source
div_t :: div_t

C does not declare which order 'quot' and 'rem' should be for the divide structures. An implementation could put 'rem' first. However, nobody actually does and everyone appears to have agreed upon this layout.

float_t #

Source
float_t :: f32

On amd64 Windows and Linux, float_t and double_t are respectively both their usual types. On x86 it's not possible to define these types correctly since they would be long double which Odin does NOT have support for.

jmp_buf #

Source
jmp_buf :: jmp_buf

The C99 Rationale describes jmp_buf as being an array type for backward compatibility. Odin does not need to honor this and couldn't as arrays in Odin don't decay to pointers. It is somewhat easy for us to bind this, we just need to ensure the structure contains enough storage with appropriate alignment. Since there are no types in C with an alignment larger than that of max_align_t, which cannot be larger than sizeof(long double) as any other exposed type wouldn't be valid C, the maximum alignment possible in a strictly conformant C implementation is 16 on the platforms we care about. The choice of 4096 bytes for storage of this type is more than enough on all relevant platforms.

wint_t #

Source
wint_t :: distinct wint_t

Odin does not have default argument promotion so the need for a separate type here isn't necessary, though make it distinct just to be safe.

Procedures

329

abort #

Source
abort :: proc "c" () ---

7.22.4 Communication with the environment

asctime #

Source
asctime :: proc "c" (timeptr: ^tm) -> [^]u8 ---

7.27.3 Time conversion functions

atomic_compare_exchange_strong #

Source
atomic_compare_exchange_strong :: proc(object, expected: ^$T, desired: $T) -> bool {…}

C does not allow failure memory order to be order_release or acq_rel. Similarly, it does not allow the failure order to be stronger than success order. Since consume and acquire are both monotonic, we can count them as one, for a total of three memory orders that are relevant in compare exchange. relaxed, acquire (consume), seq_cst. The requirement that the failure order cannot be stronger than success limits the valid combinations for the failure order to this table: [success = seq_cst, failure = seq_cst] => _ [success = acquire, failure = seq_cst] => acq [success = release, failure = seq_cst] => rel [success = acq_rel, failure = seq_cst] => acqrel [success = relaxed, failure = relaxed] => relaxed [success = seq_cst, failure = relaxed] => failrelaxed [success = seq_cst, failure = acquire] => failacq [success = acquire, failure = relaxed] => acq_failrelaxed [success = acq_rel, failure = relaxed] => acqrel_failrelaxed

atomic_compare_exchange_strong_explicit #

Source
atomic_compare_exchange_strong_explicit :: proc(object, expected: ^$T, desired: $T, success, failure: memory_order) -> bool {…}

atomic_compare_exchange_weak #

Source
atomic_compare_exchange_weak :: proc(object, expected: ^$T, desired: $T) -> bool {…}

atomic_compare_exchange_weak_explicit #

Source
atomic_compare_exchange_weak_explicit :: proc(object, expected: ^$T, desired: $T, success, failure: memory_order) -> bool {…}

atomic_exchange #

Source
atomic_exchange :: proc(object: ^$T, desired: $T) -> $$deferred_return {…}

atomic_exchange_explicit #

Source
atomic_exchange_explicit :: proc(object: ^$T, desired: $T, order: memory_order) -> $$deferred_return {…}

atomic_fetch_add #

Source
atomic_fetch_add :: proc(object: ^$T, operand: $T) -> $$deferred_return {…}

7.17.7.5 The atomic_fetch and modify generic functions

atomic_fetch_add_explicit #

Source
atomic_fetch_add_explicit :: proc(object: ^$T, operand: $T, order: memory_order) -> $$deferred_return {…}

atomic_fetch_and #

Source
atomic_fetch_and :: proc(object: ^$T, operand: $T) -> $$deferred_return {…}

atomic_fetch_and_explicit #

Source
atomic_fetch_and_explicit :: proc(object: ^$T, operand: $T, order: memory_order) -> $$deferred_return {…}

atomic_fetch_or #

Source
atomic_fetch_or :: proc(object: ^$T, operand: $T) -> $$deferred_return {…}

atomic_fetch_or_explicit #

Source
atomic_fetch_or_explicit :: proc(object: ^$T, operand: $T, order: memory_order) -> $$deferred_return {…}

atomic_fetch_sub #

Source
atomic_fetch_sub :: proc(object: ^$T, operand: $T) -> $$deferred_return {…}

atomic_fetch_sub_explicit #

Source
atomic_fetch_sub_explicit :: proc(object: ^$T, operand: $T, order: memory_order) -> $$deferred_return {…}

atomic_fetch_xor #

Source
atomic_fetch_xor :: proc(object: ^$T, operand: $T) -> $$deferred_return {…}

atomic_fetch_xor_explicit #

Source
atomic_fetch_xor_explicit :: proc(object: ^$T, operand: $T, order: memory_order) -> $$deferred_return {…}

atomic_is_lock_free #

Source
atomic_is_lock_free :: proc(obj: ^$T) -> bool {…}

7.17.5 Lock-free property

atomic_load #

Source
atomic_load :: proc(object: ^$T) -> $$deferred_return {…}

atomic_store #

Source
atomic_store :: proc(object: ^$T, desired: $T) {…}

7.17.7 Operations on atomic types

ATOMIC_VAR_INIT #

Source
ATOMIC_VAR_INIT :: proc(value: $T) -> $$deferred_return {…}

7.17.2 Initialization

call_once #

Source
@(link_name="_Call_once")
call_once :: proc "c" (flag: ^once_flag, func: proc "c" ()) ---

7.26.2 Initialization functions

clearerr #

Source
clearerr :: proc "c" (stream: ^FILE) ---

7.21.10 Error-handling functions

cnd_broadcast #

Source
@(link_name="_Cnd_broadcast")
cnd_broadcast :: proc "c" (cond: ^cnd_t) -> i32 ---

7.26.3 Condition variable functions

errno #

Source
errno :: proc "contextless" () -> ^i32 {…}

Odin has no way to make an identifier "errno" behave as a function call to read the value, or to produce an lvalue such that you can assign a different error value to errno. To work around this, just expose it as a function like it actually is.

fwprintf #

Source
fwprintf :: proc "c" (stream: ^FILE, format: [^]u16, arg: ..any) -> i32 ---

7.29.2 Formatted wide character input/output functions

isgreater #

Source
isgreater :: proc(x, y: $T) -> bool {…}

These are special in that they avoid float exceptions. They cannot just be implemented as the relational comparisons, as that would produce an invalid "sticky" state that propagates and affects maths results. These need to be implemented natively in Odin assuming isunordered to prevent that.

kill_dependency #

Source
kill_dependency :: proc(value: $T) -> $$deferred_return {…}

localeconv #

Source
localeconv :: proc "c" () -> ^lconv ---

Sets the components of an object with the type lconv with the values appropriate for the formatting of numeric quantities (monetary and otherwise) according to the rules of the current locale. Returns: a pointer to the lconv structure, might be invalidated by subsequent calls to localeconv() and setlocale() [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html ]]

longjmp #

Source
@(link_name=LLONGJMP)
longjmp :: proc "c" (env: ^jmp_buf, val: i32) -> ! ---

7.13.2 Restore calling environment

mtx_destroy #

Source
@(link_name="_Mtx_destroy")
mtx_destroy :: proc "c" (mtx: ^mtx_t) ---

7.26.4 Mutex functions

rand #

Source
rand :: proc "c" () -> i32 ---

7.22.2 Pseudo-random sequence generation functions

setjmp #

Source
@(link_name="_setjmp")
setjmp :: proc "c" (env: ^jmp_buf, hack: rawptr = nil) -> i32 ---

7.13.1 Save calling environment NOTE(dweiler): C11 requires setjmp be a macro, which means it won't necessarily export a symbol named setjmp but rather _setjmp in the case of musl, glibc, BSD libc, and msvcrt. / NOTE(dweiler): UCRT has two implementations of longjmp. One that performs stack unwinding and one that doesn't. The choice of which to use depends on a flag which is set inside the jmp_buf structure given to setjmp. The default behavior is to unwind the stack. Within Odin, we cannot use the stack unwinding version as the unwinding information isn't present. To opt-in to the regular non-unwinding version we need a way to set this flag. Since the location of the flag within the struct is not defined or part of the ABI and can change between versions of UCRT, we must rely on setjmp to set it. It turns out that setjmp receives this flag in the RDX register on Win64, this just so happens to coincide with the second argument of a function in the Win64 ABI. By giving our setjmp a second argument with the value of zero, the RDX register will contain zero and correctly set the flag to disable stack unwinding.

setlocale #

Source
@(link_name=LSETLOCALE)
setlocale :: proc "c" (category: Locale_Category, locale: cstring) -> cstring ---

Selects the appropriate piece of the global locale, as specified by the category and locale arguments, and can be used to change or query the entire global locale or portions thereof. Returns: the current locale if `locale` is `nil`, the set locale otherwise [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html ]]

thrd_exit #

Source
@(link_name="_Thrd_exit")
thrd_exit :: proc "c" (res: i32) -> ! ---

thrd_yield #

Source
@(link_name="_Thrd_yield")
thrd_yield :: proc "c" () ---

wcscat #

Source
wcscat :: proc "c" (s1, s2: [^]u16) -> [^]u16 ---

7.29.4.3 Wide string concatenation functions

wcscmp #

Source
wcscmp :: proc "c" (s1, s2: [^]u16) -> i32 ---

7.29.4.4 Wide string comparison functions

wcscpy #

Source
wcscpy :: proc "c" (s1, s2: [^]u16) -> [^]u16 ---

7.29.4.2 Wide string copying functions

wcsftime #

Source
wcsftime :: proc "c" (s: [^]u16, maxsize: uint, format: [^]u16, timeptr: ^tm) -> uint ---

7.29.5 Wide character time conversion functions

wcstod #

Source
wcstod :: proc "c" (nptr: [^]u16, endptr: ^[^]u16) -> f64 ---

7.29.4 General wide string utilities

Procedure Groups

114

acos #

Source
acos :: proc{
	libc_acos,
	libc_acosf,
	cacos,
	cacosf,
}

Emulate tgmath.h behavior with explicit procedure overloading here.

acosf #

Source
acosf :: proc{
	libc_acosf,
}

But retain the 'f' suffix-variant functions as well so they can be used, a trick is used here where we use explicit procedural overloading of one procedure. This is done because the foreign block is marked @(private) and aliasing functions does not remove privateness from the entity.

nan #

Source
nan :: proc{
	libc_nan,
}

These two functions are special and not made type generic in tgmath.h since they only differ by their return type.

nearbyint #

Source
nearbyint :: proc{
	libc_nearbyint,
	libc_nearbyintf,
}

nextafter #

Source
nextafter :: proc{
	libc_nextafter,
	libc_nextafterf,
}

remainder #

Source
remainder :: proc{
	libc_remainder,
	libc_remainderf,
}

Variables

4