Obtain data as a null-terminated string
The mi_lvarchar_to_string() function obtains the data from a varying-length structure and converts it to a null-terminated string.
This function performs the following steps:
- Allocates a new buffer to hold the null-terminated stringServer only: The mi_lvarchar_to_string() function allocates the string that it creates with the current memory duration.
- Copies the data in the data portion of the varying-length structure
to the newly allocated buffer
The mi_lvarchar_to_string() function automatically copies the number of bytes that the data length in the varying-length descriptor specifies. It then appends a null terminator to the string.
- Returns a pointer to the newly allocated null-terminated string
Suppose you have the varying-length structure that Figure 1 shows.
The following code fragment uses the mi_lvarchar_to_string() function
to obtain this varying-length data as a null-terminated string:
mi_lvarchar *lvarch;
char *var_str;
...
var_str = mi_lvarchar_to_string(lvarch);
The code fragment does not need to allocate memory for the var_str string
because the mi_lvarchar_to_string() function allocates
memory for the new string. After the call to mi_lvarchar_to_string() completes
successfully, the var_str variable contains the following null-terminated
string:
A varying-length structure stores data in a data portion, which is separate
from the varying-length structure.