gtpc2mfg | C/C++ Language Support User's Guide |
This function retrieves the key value from the item that the cursor is currently pointing to and returns it in the specified buffer. The current key is returned for dictionaries, key bags, key sets, and key sorted bags.
Format
#include <c$to2.h> TO2_BUF_PTR TO2_keyWithBuffer (const TO2_PID_PTR cursorPidPtr, TO2_ENV_PTR env_ptr, const long *bufferLength, TO2_BUF_PTR buffer);
Normal Return
For a normal return, this buffer contains a C header file followed by a copy of the data requested. The normal return is a pointer (TO2_BUF_PTR) to a structure (buffer) of type TO2_BUF_HDR (see Type Definitions).
Error Return
An error return is indicated by a zero. When zero 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
Programming Considerations
Examples
The following example shows how the key value is retrieved from the item to which the cursor is currently pointing and returns it in the specified buffer.
#include <c$to2.h> /* Needed for TO2 API Functions */ #include <stdio.h> /* APIs for standard I/O functions */ #define KEY_SIZE 16 TO2_PID cursor; TO2_ENV_PTR env_ptr; TO2_BUF_PTR buffer_ptr; /* Pointer to TO2 environment */ u_char *key=NULL; /* The key of the element */ TO2_ERR_CODE err_code; /* TO2 error code value */ TO2_ERR_TEXT_PTR err_text_ptr; /* TO2 error code text pointer */ long buffer_length;
·
·
·
/**********************************************************************/ /* Retrieve the key from the item pointed to by the cursor */ /* and return it in the supplied buffer. */ /**********************************************************************/ buffer_length = KEY_SIZE + sizeof(TO2_BUF_HDR); if ((buffer_ptr=malloc(buffer_length)) == NULL) { printf("malloc() failed!\n"); return(0); } if ((buffer_ptr=TO2_keyWithBuffer(&cursor, env_ptr, &buffer_length, buffer_ptr)) == NULL) { printf("TO2_keyWithBuffer failed!\n"); process_error(env_ptr); } else { if (buffer_length < (KEY_SIZE + sizeof(TO2_BUF_HDR))) { printf("Key returned did not fit in allocated buffer.\n"); } else { printf("TO2_keyWithBuffer successful!\n"); key = buffer_ptr->data; } }
Related Information