gtpc2mc7 | C/C++ Language Support User's Guide |
This function returns the data at the specified index in the specified collection in the supplied buffer. If the collection is an array and the position is marked as empty, this method returns a data length of 0 and an update sequence counter of 0.
Format
#include <c$to2.h> TO2_BUF_PTR TO2_atWithBuffer (const TO2_PID_PTR pid_ptr, TO2_ENV_PTR env_ptr, const long *index, const long *bufferLength, TO2_BUF_PTR buffer);
Normal Return
The normal return value is the address of the same buffer that the you specified when calling the function. The normal return is a pointer (TO2_BUF_PTR) to a structure (buffer) of type TO2_BUF_HDR (see Type Definitions).
If the length of the data is greater than the length of the buffer, only the amount of data that will fit is placed in the buffer. The length is returned in the buffer and is the actual length of the data element. It is the responsibility of the caller to check the returned length against the length of the supplied buffer to determine if the entire element has been returned.
Error Return
An error return is indicated by a NULL pointer. When a NULL pointer is returned, use the TO2_getErrorCode function to determine the specific error code. For more information, see Error Handling.
The following error codes are common for this function:
TO2_ERROR_BUFFER_SIZE
TO2_ERROR_DATA_LGH
TO2_ERROR_EMPTY
TO2_ERROR_ENV
TO2_ERROR_EODAD
TO2_ERROR_INDEX
TO2_ERROR_METHOD
TO2_ERROR_NOT_INIT
TO2_ERROR_PID
TO2_ERROR_ZERO_PID
Programming Considerations
This function does not use TPF transaction services on behalf of the caller.
Examples
The following example copies the third element of a specified collection into the specified buffer.
#include <c$to2.h> /* Needed for TO2 API functions */ #include <stdio.h> /* APIs for standard I/O functions */ char [100]; long my_bufL; TO2_PID collect; TO2_ENV_PTR env_ptr; /* Pointer to the TO2 environment */ long position=3; /* We will try to get third element */ TO2_ERROR_CODE err_code;
·
·
·
/***********************************************************************/ /* Copy the element at the specified position. */ /***********************************************************************/ my_bufL = sizeof(my_buf); if (TO2_atWithBuffer == NULL (&collect, env_ptr &position, &my_bufL, my_buf)); if (my_buf == NULL) { err_code = TO2_getErrorCode(env_ptr); if (err_code != TO2_ERROR_EODAD) { printf("TO2_atWithBuffer failed!\n"); process_error(env_ptr); } } else { printf("TO2_atWithBuffer successful!\n"); }
Related Information