t_alloc() — Allocate a library structure

Standards

Standards / Extensions C or C++ Dependencies
XPG4.2 both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <xti.h>

char *t_alloc(int fd, int struct_type, int fields);

General description

Dynamically allocates memory for the various transport function argument structures as specified below. t_alloc() allocates memory for the specified structure, and memory for buffers referenced by the structure.

The structure to allocate is specified by struct_type and must be one of the following:
        T_BIND       struct t_bind
        T_CALL       struct t_call
        T_OPTMGMT    struct t_optmgmt
        T_DIS        struct t_discon
        T_UNITDATA   struct t_unitdata
        T_UDERROR    struct t_uderr
        T_INFO       struct t_info
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. For each field of this type, the user may specify that the buffer for that field should be allocated as well. The length of the buffer allocated will be equal to or greater than the appropriate size as returned in the info argument of t_open() or t_getinfo() . The relevant fields of the info argument are described in the following list. The fields argument specifies which buffers to allocate, where the argument is the bitwise OR of any of the following:
T_ADDR
The addr field of the t_bind, t_call, t_unitdata or t_uderr structures.
T_OPT
The opt field of the t_optmgmt, t_call, t_unitdata or t_uderr structures.
T_UDATA
The udata field of the t_call, t_discon or t_unitdata structures.
T_ALL
All relevant fields of the given structure. Fields which are not supported by the transport provider specified by fd will not be allocated.

For each relevant field specified in fields, t_alloc() allocates memory for the buffer associated with the field, and initializes the len field to zero and the buf pointer and maxlen field accordingly. Irrelevant or unknown values passed in fields are ignored. Since the length of the buffer allocated will be based on the same size information that is returned to the user on a call to t_open() and t_getinfo(), fd must refer to the transport endpoint through which the newly allocated structure will be passed. In this way the appropriate size information can be accessed. If the size value associated with any specified field is -1 or -2 (see t_open() or t_getinfo() ), t_alloc() will be unable to determine the size of the buffer to allocate and will fail, setting t_errno to TSYSERR and errno to EINVAL. For any field not specified in fields, buf will be set to the NULL pointer and len and maxlen will be set to zero.

Use of t_alloc() to allocate structures helps ensure the compatibility of user programs with future releases of the transport interface functions.

Valid states: All - except for T_UNINIT

Returned value

If successful, t_alloc() returns a pointer to the newly allocated structure.

If unsuccessful, t_alloc() returns a NULL pointer and sets errno to one of the following values:
Error Code
Description
TBADF
The specified file descriptor does not refer to a transport endpoint.
TNOSTRUCTYPE
Unsupported struct_type requested. This can include a request for a structure type which is inconsistent with the transport provider type specified, that is, connection-oriented or connectionless.
TPROTO
This error indicates that a communication problem has been detected between XTI and the transport provider for which there is no other suitable XTI (t_errno).
TSYSERR
A system error has occurred during execution of this function.

Related information