int gd_add(DIRFILE *dirfile, const gd_entry_t *entry);
- int gd_madd(DIRFILE *dirfile, const gd_entry_t *entry, const char *parent);
The form of entry is described in detail on the gd_entry(3) man page. All relevant members of entry for the field type specified must be properly initialised. If entry specifies a CONST or CARRAY field, the field's data will be set to zero. If entry specifies a STRING field, the field data will be set to the empty string.
The only flags in the entry->flags member which are honoured are GD_EN_HIDDEN, which should be set or cleared to set the hiddenness of the entry (see gd_hidden(3)), and GD_EN_COMPSCAL, which indicates whether scalar parameters are initialised from the complex valued or purely real member, which both are present (LINCOM, POLYNOM, RECIP).
A metafield may be added either by calling gd_madd() with entry->field containing only the metafield's name, or else by calling gd_add() with the fully formed <parent-field>/<meta-field> field code in entry->field. Regardless of which interface is used, when adding a metafield the value of entry->fragment_index is ignored and GetData will add the new metafield to the same format specification fragment in which the parent field is defined. If the specified parent field name is an alias, the canonical name of the field will be substituted.
Fields added with this interface may contain either literal parameters or parameters based on scalar fields. If an element of the entry->scalar array defined for the specified field type is non-NULL, this element will be used as the scalar field code, and the corresponding numerical member will be ignored, and need not be initialised. Conversely, if numerical parameters are intended, the corresponding entry->scalar elements should be set to NULL. If using an element of a CARRAY field, entry->scalar_ind should also be set.
RETURN VALUEOn success, gd_add() and gd_madd() return zero. On error, -1 is returned and the dirfile error is set to a non-zero error value. Possible error values are:
- The specified dirfile was opened read-only.
- The library was unable to allocate memory.
- The field name provided in entry->field contained invalid characters; or it or an input field did not contain the affected fragment's prefix or suffix. Alternately, the parent field code was not found, or was already a metafield.
- The supplied dirfile was invalid.
- There was an error in the specification of the field described by entry, or the caller attempted to add a field of type RAW as a metafield.
- The entry->fragment_index parameter was out of range.
- The entry->data_type parameter provided with a RAW entry, or the entry->const_type parameter provided with a CONST or CARRAY entry, was invalid.
- The field name provided in entry->field duplicated that of an already existing field.
- An internal error occurred in the library while trying to perform the task. This indicates a bug in the library. Please report the incident to the GetData developers.
- An I/O error occurred while creating an empty binary file to be associated with a newly added RAW field.
- The metadata of the fragment was protected from change. Or, the creation of a RAW field was attempted and the data of the fragment was protected.
- The encoding scheme of the indicated format specification fragment is not known to the library. As a result, the library was unable to create an empty binary file to be associated with a newly added RAW field.
- The encoding scheme of the indicated format specification fragment does not support creating an empty binary file to be associated with a newly added RAW field.