Logo Search packages:      
Sourcecode: dballe version File versions

dba_err dba_record_copy ( dba_record  dest,
dba_record  source 
)

Copy all data from the record source into dest. At the end of the function, dest will contain the same data as source.

Parameters:
dest The record to copy data into.
source The record to copy data from.
Returns:
The error indicator for the function.

Definition at line 223 of file dba_record.c.

References DBA_RUN_OR_RETURN.

{
      int i;
      assert_is_dba_record(dest);
      assert_is_dba_record(source);

      /* Prevent self-copying */
      if (dest == source)
            return dba_error_ok();

      /* Copy the keyword table first */
      for (i = 0; i < KEYWORD_TABLE_SIZE; i++)
      {
            if (dest->keydata[i] != NULL)
            {
                  free(dest->keydata[i]);
                  dest->keydata[i] = NULL;
            }
            if (source->keydata[i] != NULL)
                  DBA_RUN_OR_RETURN(dba_var_copy(source->keydata[i], &(dest->keydata[i])));
      }

      /* Then the variable list */
      if (dest->vars)
            dba_record_clear_vars(dest);

      if (source->vars)
      {
            dba_item* t = &(dest->vars);
            dba_item c;
            for (c = source->vars; c != NULL; c = c->next)
            {
                  (*t) = (dba_item)calloc(1, sizeof(struct _dba_item));
                  if ((*t) == NULL)
                        return dba_error_alloc("creating new dba_item");

                  DBA_RUN_OR_RETURN(dba_var_copy(c->var, &((*t)->var)));
                  t = &((*t)->next);
            }
      }
      return dba_error_ok();
}


Generated by  Doxygen 1.6.0   Back to index