cc [ flag ... ] file ... -lnsl [ library ... ]
#include <tiuser.h>
char *t_alloc(int fildes, int struct_type, int fields);
MT-Safe
The structure to allocate is specified by struct_type, and can be one of the following:
where each of these structures may subsequently be used as an argument to one or more transport functions.
Each of the above structures, except T_INFO , contains at least one field of type struct netbuf. netbuf is described in t_connect(3N) . For each field of this type, the user may specify that the buffer for that field should be allocated as well. The fields argument specifies this option, where the argument is the bitwise-OR of any of the following:
For each field specified in
fields, t_alloc() will allocate memory for the buffer associated with the
field, and initialize the buf pointer and maxlen (see netbuf in t_connect(3N)
for description of buf and maxlen) field accordingly. The length of the
buffer allocated will be based on the same size information that is returned
to the user on t_open(3N)
and t_getinfo(3N)
. Thus, fildes must refer to
the transport endpoint through which the newly allocated structure will
be passed, so that the appropriate size information can be accessed. If
the size value associated with any specified field is -1, the underlying
service provider can support a buffer of unlimited size. If this is the
case, t_alloc() will allocate a buffer with the default size 1024 bytes.
See the NOTES section for information regarding memory allocation for
buffers other than 1024 bytes. If the size value is -2, t_alloc() will
set the buffer pointer to NULL
and the buffer maximum size to 0, and
then will return success (see t_open(3N)
or t_getinfo(3N)
).
For any field not specified in fields, buf will be set to NULL
and maxlen
will be set to zero.
Use of t_alloc() to allocate structures will help ensure the compatibility of user programs with future releases of the transport interface.
On failure, t_errno will be set to one of the following:
If the underlying service provider supports a buffer of unlimited size in the netbuf structure (see t_connect(3N) ), t_alloc() will return a buffer of size 1024 bytes. If a larger size buffer is required, it will need to be allocated separately using a memory allocation routine such as malloc(3C) . The buf and maxlen fields of the netbuf data structure can then be updated with the address of the new buffer and the 1024 byte buffer originally allocated by t_alloc() can be freed using free(3C) .
This interface is safe in multithreaded applications.