C Package v0.1.0

Source
Unstable API
The package is under active development and its API is not yet stable. Names, signatures, and behavior may change between releases, and this documentation will be updated to match.

Thin bindings to the platform C standard library for Rux programs.

Package: C

Source: github.com/rux-lang/Rux/tree/main/Packages/C

The package links the platform C library through #Link and exposes its functions directly — the math library (libm), standard I/O, the general utilities, and the time functions. Each entry is a 1:1 binding to the C function of the same name, so the authoritative behavior is the C standard and the linked reference on every page.

Requirements

  • A target with a C standard library — every supported OS (BSD, Linux, macOS, Windows) ships one, selected automatically per target.

Each function follows the C calling convention and the C contract exactly: no argument checking, no errno decoding, and no memory management beyond what the C function itself does. Prefer the cross-platform packages (Math, Io, Memory) for portable application code, and reach for these bindings when you need the C library specifically.

Installation

rux add C
rux install

Then import the symbols you need:

import C::{ printf, malloc, free };

Types

TypeDescription
time_tArithmetic type representing a calendar time.
clock_tArithmetic type representing processor time.
tmCalendar time broken into its components.
timespecA time in seconds and nanoseconds.

Math

FunctionDescription
acosfComputes arc cosine.
acosComputes arc cosine.
acoshfComputes inverse hyperbolic cosine.
acoshComputes inverse hyperbolic cosine.
asinfComputes arc sine.
asinComputes arc sine.
asinhfComputes inverse hyperbolic sine.
asinhComputes inverse hyperbolic sine.
atanfComputes arc tangent.
atanComputes arc tangent.
atan2fComputes arc tangent, using signs to determine quadrants.
atan2Computes arc tangent, using signs to determine quadrants.
atanhfComputes inverse hyperbolic tangent.
atanhComputes inverse hyperbolic tangent.
cbrtfComputes cube root.
cbrtComputes cube root.
ceilfComputes smallest integer not less than the given value.
ceilComputes smallest integer not less than the given value.
copysignfCopies the sign of a floating-point value.
copysignCopies the sign of a floating-point value.
cosfComputes cosine.
cosComputes cosine.
coshfComputes hyperbolic cosine.
coshComputes hyperbolic cosine.
erffComputes error function.
erfComputes error function.
erfcfComputes complementary error function.
erfcComputes complementary error function.
expfComputes e raised to the given power.
expComputes e raised to the given power.
exp2fComputes 2 raised to the given power.
exp2Computes 2 raised to the given power.
expm1fComputes e raised to the given power, minus one.
expm1Computes e raised to the given power, minus one.
fabsComputes the absolute value of a floating-point value.
fdimfComputes positive difference of two floating-point values.
fdimComputes positive difference of two floating-point values.
floorfComputes largest integer not greater than the given value.
floorComputes largest integer not greater than the given value.
fmafComputes fused multiply-add.
fmaComputes fused multiply-add.
fmaxfComputes larger of two floating-point values.
fmaxComputes larger of two floating-point values.
fminfComputes smaller of two floating-point values.
fminComputes smaller of two floating-point values.
fmodfComputes remainder of the floating-point division operation.
fmodComputes remainder of the floating-point division operation.
frexpDecomposes a number into significand and a power of two.
hypotComputes square root of the sum of the squares of two given numbers.
ilogbfExtracts exponent of the number.
ilogbExtracts exponent of the number.
ldexpMultiplies a number by 2 raised to an integer power.
lgammafComputes natural logarithm of the absolute value of the gamma function.
lgammaComputes natural logarithm of the absolute value of the gamma function.
llrintfRounds to nearest integer using current rounding mode.
llrintRounds to nearest integer using current rounding mode.
llroundfRounds to nearest integer, rounding away from zero in halfway cases.
llroundRounds to nearest integer, rounding away from zero in halfway cases.
logfComputes natural (base e) logarithm.
logComputes natural (base e) logarithm.
log10fComputes common (base 10) logarithm.
log10Computes common (base 10) logarithm.
log1pfComputes natural logarithm of 1 plus the given number.
log1pComputes natural logarithm of 1 plus the given number.
log2fComputes base 2 logarithm.
log2Computes base 2 logarithm.
logbfExtracts exponent of the number.
logbExtracts exponent of the number.
lrintfRounds to nearest integer using current rounding mode.
lrintRounds to nearest integer using current rounding mode.
lroundfRounds to nearest integer, rounding away from zero in halfway cases.
lroundRounds to nearest integer, rounding away from zero in halfway cases.
modffDecomposes a number into integer and fractional parts.
modfDecomposes a number into integer and fractional parts.
nanfGenerates a quiet NaN.
nanGenerates a quiet NaN.
nearbyintfRounds to nearest integer using current rounding mode without raising the inexact exception.
nearbyintRounds to nearest integer using current rounding mode without raising the inexact exception.
nextafterfDetermines next representable floating-point value toward the given value.
nextafterDetermines next representable floating-point value toward the given value.
powfComputes a number raised to the given power.
powComputes a number raised to the given power.
remainderfComputes signed remainder of the floating-point division operation.
remainderComputes signed remainder of the floating-point division operation.
remquofComputes signed remainder as well as the three last bits of the division operation.
remquoComputes signed remainder as well as the three last bits of the division operation.
rintfRounds to nearest integer using current rounding mode.
rintRounds to nearest integer using current rounding mode.
roundfRounds to nearest integer, rounding away from zero in halfway cases.
roundRounds to nearest integer, rounding away from zero in halfway cases.
scalbnfMultiplies a number by FLT_RADIX raised to an integer power.
scalbnMultiplies a number by FLT_RADIX raised to an integer power.
sinfComputes sine.
sinComputes sine.
sinhfComputes hyperbolic sine.
sinhComputes hyperbolic sine.
sqrtfComputes square root.
sqrtComputes square root.
tanfComputes tangent.
tanComputes tangent.
tanhfComputes hyperbolic tangent.
tanhComputes hyperbolic tangent.
tgammafComputes gamma function.
tgammaComputes gamma function.
truncfRounds to nearest integer not greater in magnitude than the given value.
truncRounds to nearest integer not greater in magnitude than the given value.

Standard I/O

FunctionDescription
clearerrClears the end-of-file and error indicators for the given stream.
fcloseCloses the given file stream.
feofChecks if the end-of-file indicator is set for the given stream.
ferrorChecks if the error indicator is set for the given stream.
fflushWrites any unwritten data from the stream's buffer to the file.
fgetcReads the next character from the given stream.
fgetposGets the current file position of the stream.
fgetsReads at most count-1 characters from the stream into a string.
fopenOpens a file indicated by filename with the given mode.
fprintfPrints formatted output to a file stream.
fputcWrites a character to the given stream.
fputsWrites a string to the given stream.
freadReads up to count objects of the given size from the stream into a buffer.
freopenReopens a stream with a different file or mode.
fscanfReads formatted input from a file stream.
fseekSets the file position indicator for the stream.
fsetposSets the file position of the stream to the given position.
ftellReturns the current file position of the stream.
fwriteWrites count objects of the given size from a buffer to the stream.
getcReads the next character from the given stream.
getcharReads the next character from stdin.
perrorPrints an error message describing the last error to stderr.
printfPrints formatted output to stdout.
putcWrites a character to the given stream.
putcharWrites a character to stdout.
putsWrites a string followed by a newline to stdout.
removeDeletes the file identified by the given path.
renameRenames a file, moving it if necessary.
rewindMoves the file position indicator to the beginning of the stream.
scanfReads formatted input from stdin.
setbufSets the buffer to be used by the given stream.
setvbufSets the buffering mode and buffer to be used by the given stream.
sprintfPrints formatted output to a string.
sscanfReads formatted input from a string.
tmpfileCreates and opens a temporary file with a unique name.
tmpnamGenerates a unique filename that does not name an existing file.
ungetcPuts a character back into the given stream.

Standard library

FunctionDescription
abortCauses abnormal program termination without cleaning up.
absComputes the absolute value of an integer value.
atofConverts a byte string to a floating point value.
atoiConverts a byte string to an integer value.
atolConverts a byte string to a long integer value.
atollConverts a byte string to a long long integer value.
callocAllocates memory for an array of num objects of size and zero-initializes it.
exitCauses normal program termination with cleanup.
freeDeallocates the memory previously allocated by malloc, calloc or realloc.
getenvReturns the value of an environment variable.
labsComputes the absolute value of a long integer value.
llabsComputes the absolute value of a long long integer value.
mallocAllocates size bytes of uninitialized memory.
randReturns a pseudo-random integer value between 0 and RAND_MAX.
reallocChanges the size of the memory block pointed to by ptr to size bytes.
srandSeeds the pseudo-random number generator used by rand.
systemCalls the host environment's command processor.

Time

FunctionDescription
asctimeConverts a tm object to a textual representation.
clockReturns the approximate processor time used by the program.
ctimeConverts a time_t object to a textual representation.
difftimeComputes the difference in seconds between two calendar times.
gmtimeConverts a time_t object to calendar time expressed as UTC.
localtimeConverts a time_t object to calendar time expressed as local time.
mktimeConverts calendar time to a time_t object, normalizing the tm structure.
strftimeConverts a tm object to a custom textual representation.
timeReturns the current calendar time since the epoch.