libporty - the host package
The host package is a collection of misc calls related to how the host
represents time, pointers and the file system.
libporty/host/time.h
For querying the current local time (no time zones involved) there are
two calls, P_dtime() and P_ltime(). Both returns time in seconds since
Epoch, the first one using a single double, the second one using two
integers. For the integers type P_time_t should be used (unsigned long int
at the moment, which would be able to represent seconds until 2106).
call
| level
| summary
|
P_dtime
| low
| return current time in seconds as double
|
P_ltime
| low
| return current time in seconds as a pair of integers
|
Similar to queries, sleep has 2 different calls for double and integer:
P_dsleep() and P_usleep(). However, in this case the two calls are not
fully equivalent. The fundamental difference is that P_usleep() is limited
to short, interruptible periods of sleep, while P_dsleep() has no time
limitation and guarantees to sleep long enough even if syscalls are
interrupted. However, P_dsleep() has higher overhead thus should not be
used for very short sleeps.
call
| level
| summary
|
P_dsleep
| low
| (uninterruptible) sleep for a specific amount of seconds (dobule)
|
P_usleep
| low
| (interruptible) sleep for a limited amount of microseconds (integer)
|
libporty/host/pointers.h
In standard C there is no reliable way to print and scan pointers. For
printing, %p may or may not exist, and appending 0x prefix with %p or %x
varies too. Many scanf implementation do not support %p at all. Converting
pointers to integers is also problematic, as sizes may differ.
To overcome these problems, libporty provides a pair of calls, print and scan,
for converting pointers to strings and back. The prefix is Px and the number
is a fixed width hex representation of the pointer. This implementation
doesn't convert the pointer to integer but reads it character by character,
knowing the width of pointers and byte order on the given platform.
call
| level
| summary
|
P_ptr_print
| low
| print pointer in an user-allocated string
|
P_ptr_aprint
| low
| print pointer in an automatically allocated string
|
P_ptr_scan
| low
| read pointer from a string
|
libporty/host/fs.h
The fs subsystem provides limited, but portable abstraction for basic
file system operations. When assambling paths, the caller should use
constant (char) P_path_sep instead of / or \ as separator.
call
| level
| summary
|
P_open_dir
| low
| start listing files of a directory
|
P_read_dir
| low
| return next file name of a directory listing
|
P_close_dir
| low
| close a directory listing query
|
P_file_size
| low
| return size of a file (in wide-enough integer type P_filesize_t)
|