gd_add(3)

NAME
gd_add, gd_madd — add a field to a Dirfile

SYNOPSIS
#include <getdata.h>

int gd_add(DIRFILE *dirfile, const gd_entry_t *entry);

int gd_madd(DIRFILE *dirfile, const gd_entry_t *entry, const char *parent);

DESCRIPTION
The function adds the field described by to the dirfile specified by The function behaves similarly, but adds the field as a metafield under the field indicated by the field code The form of is described in detail on the man page. All relevant members of for the field type specified must be properly initialised. If specifies a CONST or CARRAY field, the field's data will be set to zero. If specifies a STRING field, the field data will be set to the empty string. The only flags in the member which are honoured are GD_EN_HIDDEN, which should be set or cleared to set the hiddenness of the entry (see 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 with containing only the metafield's name, or else by calling with the fully formed "<parent-field>/<meta-field>" field code in Regardless of which interface is used, when adding a metafield the value of 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 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 elements should be set to NULL. If using an element of a CARRAY field, should also be set.

RETURN VALUE
On success, and return zero. On error, a negative-valued error code is returned. Possible error codes are: The specified dirfile was opened read-only. The library was unable to allocate memory. The field name provided in contained invalid characters; or it or an input field did not contain the affected fragment's prefix or suffix. Alternately, the 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 or the caller attempted to add a field of type RAW as a metafield. The parameter was out of range. The parameter provided with a RAW entry, or the parameter provided with a CONST or CARRAY entry, was invalid. The field name provided in 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.

The error code is also stored in the DIRFILE object and may be retrieved after this function returns by calling A descriptive error string for the error may be obtained by calling

HISTORY
The functions and appeared in GetData-0.4.0. In GetData-0.7.0, the functions were renamed to and In GetData-0.8.0, first allowed adding metafields by providing the full (slashed) field name. This was the first version supporting fragment affixes, and in this version, would apply the destination fragment's affixes to the supplied name. In GetData-0.8.1, this changed: now assumes contains the full field name, including any necessary affixes. In GetData-0.10.0, the error return from these functions changed from -1 to a negative-valued error code. See for the history of the gd_entry_t structure.

SEE ALSO
dirfile-format(5)