- support library for standalone executables
library provides a set of supporting functions for standalone
applications, mimicking where possible the standard
The following sections group these functions by kind.
Unless specifically described here, see the corresponding section 3
manpages for the given functions.
String functions are available as documented in
malloc (size_t size);
bytes of memory from the heap using a best-fit algorithm.
free (void *ptr);
Free the allocated object at
Fa ptr .
setheap (void *start void *limit);
Initialise the heap.
This function must be called before calling
for the first time.
The region between
will be used for the heap; attempting to allocate beyond this will result
in a panic.
sbrk (int junk);
Provides the behaviour of
sbrk (0 ,);
i.e., returns the highest point that the heap has reached.
This value can
be used during testing to determine the actual heap usage.
argument is ignored.
A set of functions are provided for manipulating a flat variable space similar
to the traditional shell-supported environment.
Major enhancements are support
for set/unset hook functions.
getenv (const char *name);
setenv (const char *name const char *value int overwrite);
putenv (const char *string);
unsetenv (const char *name);
These functions behave similarly to their standard library counterparts.
struct env_var *
env_getenv (const char *name);
Looks up a variable in the environment and returns its entire
env_setenv (const char *name int flags const void *value ev_sethook_t sethook ev_unsethook_t unsethook);
Creates a new or sets an existing environment variable called
Fa name .
If creating a new variable, the
arguments may be specified.
The set hook is invoked whenever an attempt
is made to set the variable, unless the EV_NOHOOK flag is set.
a set hook will validate the
argument, and then call
again with EV_NOHOOK set to actually save the value.
The predefined function
may be specified to refuse all attempts to set a variable.
The unset hook is invoked when an attempt is made to unset a variable.
returns zero, the variable will be unset.
The predefined function
may be used to prevent a variable being unset.
strtol (const char *nptr char **endptr int base);
srandom (unsigned long seed);
strerror (int error);
Returns error messages for the subset of errno values supported by
Fn assert expression
In assert.h .
setjmp (jmp_buf env);
longjmp (jmp_buf env int val);
respectively as there is no signal state to manipulate.
In setjmp.h .
gets (char *buf);
Read characters from the console into
Fa buf .
All of the standard cautions apply to this function.
ngets (char *buf int size);
Read at most
- 1 characters from the console into
Fa buf .
is less than 1, the function's behaviour is as for
fgetstr (char *buf int size int fd);
Read a line of at most
Fa buf .
Line terminating characters are stripped, and the buffer is always
Returns the number of characters in
if successful, or -1 if a read error occurs.
The *printf functions implement a subset of the standard
family functionality and some extensions.
The following standard conversions
are supported: c,d,n,o,p,s,u,x.
The following modifiers are supported:
conversion is provided to decode error registers.
Its usage is:
Qq reg=%b\n ,
where <base> is the output expressed as a control character, e.g. \10 gives
octal, \20 gives hex.
Each <arg> is a sequence of characters, the first of
which gives the bit number to be inspected (origin 1) and the next characters
(up to a character less than 32) give the text to be displayed if the bit is set.
Qq %*D ,
Qq XX XX XX ...
CHARACTER TESTS AND CONVERSIONS
isupper (int c);
islower (int c);
isspace (int c);
isdigit (int c);
isxdigit (int c);
isascii (int c);
isalpha (int c);
toupper (int c);
tolower (int c);
open (const char *path int flags);
Similar to the behaviour as specified in
except that file creation is not supported, so the mode parameter is not
argument may be one of O_RDONLY, O_WRONLY and O_RDWR (although no file systems
currently support writing).
close (int fd);
Close all open files.
read (int fd void *buf size_t len);
write (int fd void *buf size_t len);
(No file systems currently support writing.)
lseek (int fd off_t offset int whence);
Files being automatically uncompressed during reading cannot seek backwards
from the current point.
stat (const char *path struct stat *sb);
fstat (int fd struct stat *sb);
functions only fill out the following fields in the
file system cannot provide meaningful values for this call, and the
file system always reports files having uid/gid of zero.
library supplies a simple internal pager to ease reading the output of large
Initialises the pager and tells it that the next line output will be the top of the
The environment variable LINES is consulted to determine the number of
lines to be displayed before pausing.
Closes the pager.
pager_output (const char *lines);
Sends the lines in the
NUL -terminated buffer at
to the pager.
Newline characters are counted in order to determine the number
of lines being output (wrapped lines are not accounted for).
function will return zero when all of the lines have been output, or nonzero
if the display was paused and the user elected to quit.
pager_file (const char *fname);
Attempts to open and display the file
Fa fname .
Returns -1 on error, 0 at EOF, or 1 if the user elects to quit while reading.
Successive calls emit the characters in the sequence |,/,-,\ followed by a
backspace in order to provide reassurance to the user.
REQUIRED LOW-LEVEL SUPPORT
The following resources are consumed by
- stack, heap, console and devices.
The stack must be established before
functions can be invoked.
Stack requirements vary depending on the functions
and file systems used by the consumer and the support layer functions detailed
The heap must be established before calling
Heap usage will vary depending on the number of simultaneously open files,
as well as client behaviour.
Automatic decompression will allocate more
than 64K of data per open file.
Console access is performed via the
functions detailed below.
Device access is initiated via
and is performed through the
functions in the device switch structure that
The consumer must provide the following support functions:
Return a character from the console, used by
and pager functions.
Returns nonzero if a character is waiting from the console.
Write a character to the console, used by
Fn *printf ,
and thus by many other functions for debugging and informational output.
Open the appropriate device for the file named in
Fa name ,
a pointer to the remaining body of
which does not refer to the device.
will be set to point to the
structure for the opened device if successful.
Device identifiers must
always precede the path component, but may otherwise be arbitrarily formatted.
and thus for all device-related I/O.
devclose (struct open_file *of);
Close the device allocated for
Fa of .
The device driver itself will already have been called for the close; this call
should clean up any allocation made by devopen only.
panic (const char *msg ...);
Signal a fatal and unrecoverable error condition.
Fa msg ...
arguments are as for
INTERNAL FILE SYSTEMS
Internal file systems are enabled by the consumer exporting the array
Vt struct fs_ops *file_system ,
which should be initialised with pointers
Vt struct fs_ops
The following file system handlers are supplied by
the consumer may supply other file systems of their own:
Linux ext2fs file system.
File access via TFTP.
File access via NFS.
ISO 9660 (CD-ROM) file system.
Stacked file system supporting gzipped files.
When trying the gzipfs file system,
to the end of the filename, and then tries to locate the file using the other
Placement of this file system in the
array determines whether gzipped files will be opened in preference to non-gzipped
It is only possible to seek a gzipped file forwards, and
on gzipped files will report an invalid length.
The same as
The array of
Vt struct fs_ops
pointers should be terminated with a NULL.
Devices are exported by the supporting code via the array
Vt struct devsw *devsw
which is a NULL terminated array of pointers to device switch structures.
library contains contributions from many sources, including: