function: lx_alloc()
USAGE:
char lx_alloc(lx_s *s, unsigned int elem)
Allocate elem bytes for use in s. String struct s
should not be allocated; s->s should have a value of 0.
This function is not commonly used, though there is no reason why it
shouldn't be. More common is lx_setalloc(), which checks whether
s has been previously allocated.
Note that if string struct s has been previously allocated,
the previously allocated memory will be left as-is, and a completely new
memory block will be allocated for s. If you do not keep a
reference to the previously allocated block of memory, you will never be able
to free it.
PROPERTIES |
return value |
0 on success (1 on out-of-memory error) |
allocation ensured |
explicit |
previous allocation required |
no' |
SEE ALSO:
EXAMPLE:
{
lx_s ns = {0};
char *stuff = "some string longer than 20 characters";
lx_alloc (&ns, 20);
memcpy (ns.s, stuff, 20);
ns.len = 20;
lx_strout (1, &ns);
}