2.5 Checking for Buffer Type

The tptypes(3c) function returns the type and subtype (if one exists) of a buffer. The tptypes() function signature is as follows:

long
tptypes(char *ptr, char *type, char *subtype)

The following table describes the arguments to the tptypes() function.

Table 2-4 tptypes() Function Arguments

Argument Description
ptr Pointer to a data buffer. This pointer must have been originally allocated by a call to tpalloc() or tprealloc(), it may not be NULL, and it must be cast as a character type; otherwise, the tptypes() function reports an invalid argument error.
type Pointer to the type of the data buffer. type is of character type.
subtype Pointer to the subtype of the data buffer, if one exists. subtype is of character type. For all types other than VIEW, VIEW32, RECORD, X_C_TYPE, and X_COMMON, upon return the subtype parameter points to a character array containing the NULL string.

Note:

For RECORD typed buffer, the maximum length of record name (subtype) is 32 bytes. If the length of record name is greater than 16, tptypes() will populate the first 16 bytes of subtype, but RECORD * pointer will point to the beginning of full-length record name.

Upon success, the tptypes() function returns the length of the buffer in the form of a long integer.

In the event of an error, tptypes() returns a value of -1 and sets tperrno(5) to the appropriate error code. For a list of these error codes, refer to the “Introduction to the C Language Application-to-Transaction Monitor Interface” and tpalloc(3c) in the Oracle Tuxedo ATMI C Function Reference.

You can use the size value returned by tptypes() upon success to determine whether the default buffer size is large enough to hold your data, as shown in the following listing.

Listing Getting Buffer Size

. . .
iptr = (FBFR *)tpalloc("FML", NULL, 0);
ilen = tptypes(iptr, NULL, NULL);
. . .
if (ilen < mydatasize)
     iptr=tprealloc(iptr, mydatasize);

See Also: