Varying-length data and null termination

When you work with varying-length data, keep the following restrictions in mind:
  • Do not assume that the data in a varying-length structure is null-terminated.
  • Do not assume that you can use any DataBlade® API functions or system calls that operate on a null-terminated string to operate on varying-length data.

Instead, always use the data length (which you can obtain with the mi_get_varlen() function) for all operations on varying-length data.

The varying-length accessor functions in Varying-length accessor functions do not automatically interpret a null-terminator character. Instead, they transfer the number of bytes that the data length in the varying-length descriptor specifies, as follows:
  • The mi_set_vardata() and mi_set_vardata_align() functions copy the number of bytes that the data length specifies from their string argument to a varying-length structure.
  • The mi_get_vardata() and mi_get_vardata_align() functions obtain the data pointer from the varying-length descriptor. Use the data length to move through the varying-length data.

To convert between null-terminated strings and an mi_lvarchar structure, use the mi_string_to_lvarchar() and mi_lvarchar_to_string() functions.