コード例 #1
0
ファイル: meta_data.c プロジェクト: ajdiaz/collectd
int meta_data_add_boolean(meta_data_t *md, /* {{{ */
                          const char *key, _Bool value) {
  meta_entry_t *e;

  if ((md == NULL) || (key == NULL))
    return (-EINVAL);

  e = md_entry_alloc(key);
  if (e == NULL)
    return (-ENOMEM);

  e->value.mv_boolean = value;
  e->type = MD_TYPE_BOOLEAN;

  return (md_entry_insert(md, e));
} /* }}} int meta_data_add_boolean */
コード例 #2
0
ファイル: meta_data.c プロジェクト: ajdiaz/collectd
int meta_data_add_double(meta_data_t *md, /* {{{ */
                         const char *key, double value) {
  meta_entry_t *e;

  if ((md == NULL) || (key == NULL))
    return (-EINVAL);

  e = md_entry_alloc(key);
  if (e == NULL)
    return (-ENOMEM);

  e->value.mv_double = value;
  e->type = MD_TYPE_DOUBLE;

  return (md_entry_insert(md, e));
} /* }}} int meta_data_add_double */
コード例 #3
0
ファイル: meta_data.c プロジェクト: ajdiaz/collectd
int meta_data_add_unsigned_int(meta_data_t *md, /* {{{ */
                               const char *key, uint64_t value) {
  meta_entry_t *e;

  if ((md == NULL) || (key == NULL))
    return (-EINVAL);

  e = md_entry_alloc(key);
  if (e == NULL)
    return (-ENOMEM);

  e->value.mv_unsigned_int = value;
  e->type = MD_TYPE_UNSIGNED_INT;

  return (md_entry_insert(md, e));
} /* }}} int meta_data_add_unsigned_int */
コード例 #4
0
ファイル: meta_data.c プロジェクト: BrianB2/collectd
static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
{
  meta_entry_t *copy;

  if (orig == NULL)
    return (NULL);

  copy = md_entry_alloc (orig->key);
  copy->type = orig->type;
  if (copy->type == MD_TYPE_STRING)
    copy->value.mv_string = strdup (orig->value.mv_string);
  else
    copy->value = orig->value;

  copy->next = md_entry_clone (orig->next);
  return (copy);
} /* }}} meta_entry_t *md_entry_clone */
コード例 #5
0
ファイル: meta_data.c プロジェクト: ajdiaz/collectd
/*
 * Add functions
 */
int meta_data_add_string(meta_data_t *md, /* {{{ */
                         const char *key, const char *value) {
  meta_entry_t *e;

  if ((md == NULL) || (key == NULL) || (value == NULL))
    return (-EINVAL);

  e = md_entry_alloc(key);
  if (e == NULL)
    return (-ENOMEM);

  e->value.mv_string = md_strdup(value);
  if (e->value.mv_string == NULL) {
    ERROR("meta_data_add_string: md_strdup failed.");
    md_entry_free(e);
    return (-ENOMEM);
  }
  e->type = MD_TYPE_STRING;

  return (md_entry_insert(md, e));
} /* }}} int meta_data_add_string */
コード例 #6
0
ファイル: meta_data.c プロジェクト: ajdiaz/collectd
/* XXX: The lock on md must be held while calling this function! */
static meta_entry_t *md_entry_clone_contents(const meta_entry_t *orig) /* {{{ */
{
  meta_entry_t *copy;

  /* WARNINGS :
   *  - we do not check that orig != NULL here. You should have done it before.
   *  - we do not set copy->next. DO NOT FORGET TO SET copy->next IN YOUR
   * FUNCTION
   */

  copy = md_entry_alloc(orig->key);
  if (copy == NULL)
    return (NULL);
  copy->type = orig->type;
  if (copy->type == MD_TYPE_STRING)
    copy->value.mv_string = strdup(orig->value.mv_string);
  else
    copy->value = orig->value;

  return (copy);
} /* }}} meta_entry_t *md_entry_clone_contents */