| STK(3) | C LIBRARY FUNCTIONS | STK(3) |
|---|
#include <stk.h>Stk_t *stkopen(int flags); Stk_t *stkinstall(Stk_t *stack, char *(overflow)(int)); int stkclose(Stk_t *stack); void stklink(Stk_t *stack)
char *stkalloc(Stk_t *stack, unsigned size); char *stkcopy(Stk_t *stack, const char *string); char *stkset(Stk_t *stack, char *address, unsigned offset);
char *stkseek(Stk_t *stack, unsigned offset); int stktell(Stk_t *stack); char *stkptr(Stk_t *stack, unsigned offset); char *stkfreeze(Stk_t *stack, unsigned extra); int stkon(Stk *stack, char* addr)
stk is a package of routines designed to provide efficient
stack oriented dynamic storage.
A stack abstraction consists of an ordered list of contiguous
memory regions, called stack frames, that can hold objects of
arbitrary size.
A stack is represented by the type Stk_t
defined in header <stk.h>.
The type Stk_t is compatible with the type Sfio_t
defined by the
There is a preset initial active stack.
To use an additional stack, it is necessary to create it and to
install it as the active stack.
A stack is created with the stkopen() function.
A flags argument of STK_SMALL indicates that unused
space on the stack should be freed whenever this stack ceases
to be the active stack.
If successful,
stkopen() returns a pointer to a stack whose reference
count is 1.
Otherwise, stkopen() returns a null pointer.
The stklink() function increases the reference count for the
given stack.
The stkinstall() function
makes the specified stack the active stack and returns a pointer
to the previous active stack.
When the overflow argument is not null,
it specifies a function that will
be called whenever
The
stkalloc() function returns an aligned pointer to space on the
active stack that can be used to hold any object of the given size.
stkalloc() is similar to
The stkcopy() function copies the given string onto the stack and returns a pointer to the string on the stack. stkcopy() causes the offset of the current object to be set to zero.
The stkset() function finds the frame containing the given address, frees all frames that were created after the one containing the given address, and sets the current object to the given address. The top of the current object is set to offset bytes from current object. If address is not the address of an object on the stack the result is undefined.
The
The stkptr() function converts the given offset for the current object into a memory address on the stack. This address is only valid until another stack operation is given. The result is not defined if offset exceeds the size of the current object. The stkfreeze() function terminates the current object on the stack and returns a pointer to the beginning of this object. If extra is non-zero, extra bytes are added to the stack before the current object is terminated. The first added byte will contain zero and the contents of the remaining bytes are undefined.
The stkon() function returns non-zero if the address given by addr is on the stack stack and 0 otherwise.
David Korn
| July 23, 2008 |