Beispiel #1
0
void
str_list_add(struct mystr_list* p_list, const struct mystr* p_str,
             const struct mystr* p_sort_key_str)
{
  struct mystr_list_node* p_node;
  /* Expand the node allocation if we have to */
  if (p_list->list_len == p_list->alloc_len)
  {
    if (p_list->alloc_len == 0)
    {
      p_list->alloc_len = 32;
      p_list->p_nodes = vsf_sysutil_malloc(p_list->alloc_len *
                                           sizeof(struct mystr_list_node));
    }
    else
    {
      p_list->alloc_len *= 2;
      p_list->p_nodes = vsf_sysutil_realloc(p_list->p_nodes,
                                            p_list->alloc_len *
                                            sizeof(struct mystr_list_node));
    }
  }
  p_node = &p_list->p_nodes[p_list->list_len];
  p_node->str = s_null_str;
  p_node->sort_key_str = s_null_str;
  str_copy(&p_node->str, p_str);
  if (p_sort_key_str)
  {
    str_copy(&p_node->sort_key_str, p_sort_key_str);
  }
  p_list->list_len++;
}
Beispiel #2
0
void
str_reserve(struct mystr* p_str, unsigned int res_len)
{
  if (res_len > p_str->alloc_bytes)
  {
    p_str->p_buf = vsf_sysutil_realloc(p_str->p_buf, res_len);
    p_str->alloc_bytes = res_len;
  }
}
Beispiel #3
0
void
str_reserve(struct mystr* p_str, unsigned int res_len)
{
  /* Reserve space for the trailing zero as well. */
  res_len++;
  if (res_len > p_str->alloc_bytes)
  {
    p_str->p_buf = vsf_sysutil_realloc(p_str->p_buf, res_len);
    p_str->alloc_bytes = res_len;
  }
  p_str->p_buf[res_len - 1] = '\0';
}
Beispiel #4
0
void
private_str_append_memchunk(struct mystr* p_str, const char* p_src,
                            unsigned int len)
{
  unsigned int buf_needed = p_str->len + len + 1;
  if (buf_needed > p_str->alloc_bytes)
  {
    p_str->p_buf = vsf_sysutil_realloc(p_str->p_buf, buf_needed);
    p_str->alloc_bytes = buf_needed;
  }
  vsf_sysutil_memcpy(p_str->p_buf + p_str->len, p_src, len);
  p_str->p_buf[p_str->len + len] = '\0';
  p_str->len += len;
}
Beispiel #5
0
void
private_str_append_memchunk(struct mystr* p_str, const char* p_src,
                            unsigned int len)
{
  unsigned int buf_needed;
  if (len + p_str->len < len)
  {
    bug("integer overflow");
  }
  buf_needed = len + p_str->len;
  if (buf_needed + 1 < buf_needed)
  {
    bug("integer overflow");
  }
  buf_needed++;
  if (buf_needed > p_str->alloc_bytes)
  {
    p_str->p_buf = vsf_sysutil_realloc(p_str->p_buf, buf_needed);
    p_str->alloc_bytes = buf_needed;
  }
  vsf_sysutil_memcpy(p_str->p_buf + p_str->len, p_src, len);
  p_str->p_buf[p_str->len + len] = '\0';
  p_str->len += len;
}