Beispiel #1
0
/* Convert an array of chars to a nul-terminated string. */
static char* chars_to_string(c4snet_data_t *c4data)
{
  size_t size = C4SNetArraySize(c4data);
  char* str = SNetMemAlloc(size + 1);

  memcpy(str, C4SNetGetData(c4data), size);
  str[size] = '\0';
  return str;
}
Beispiel #2
0
/* Get a copy of an unterminated char array as a proper C string. */
char* C4SNetGetString(c4snet_data_t *data)
{
  if (data->type != CTYPE_char && data->type != CTYPE_uchar) {
    SNetUtilDebugFatal("[%s]: Not a char array type %d.", __func__, data->type);
    return NULL; /* NOT REACHED */
  } else {
    size_t size = C4SNetArraySize(data);
    char* str = SNetMemAlloc(size + 1);
    memcpy(str, C4SNetGetData(data), size);
    str[size] = '\0';
    return str;
  }
}
Beispiel #3
0
static size_t AllocatedSpace(c4snet_data_t *d)
{ return d->vtype == VTYPE_array ? C4SNetArraySize(d) * C4SNetSizeof(d) : 0; }