---
name: "gd_add_spec"
section: "3"
platform: "linux"
package: "libgetdata-doc"
version: "0.11.0-15"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/gd_add_spec"
---

# gd\_add\_spec(3)

add a field to a Dirfile

## NAME

gd\_add\_spec, gd\_madd\_spec — add a field to a Dirfile

## SYNOPSIS

**#include \<getdata.h\>**

**int gd\_add\_spec(DIRFILE \****dirfile***, const char \****line***,** **int** *fragment\_index***);**

**int gd\_madd\_spec(DIRFILE \****dirfile***, const char \****line***,** **const char \****parent***);**

## DESCRIPTION

The **gd\_add\_spec**() function adds the field described by the field specification line in *line* to the dirfile specified by *dirfile*. The **gd\_madd\_spec**() function behaves similarly, but adds the field as a metafield under the field indicated by the field *parent*. Field specification lines are described in detail in [dirfile-format(5)](/dirfile-format/5.md). Since Standards Version 7 (see [dirfile(5)](/dirfile/5.md)) permits specifying metafield without the use of the **/META** directive, **gd\_add\_spec**() may also be used to add metafields, by specifying the metafield's full field code.  See [dirfile-format(5)](/dirfile-format/5.md) for full details.

When using **gd\_madd\_spec**(), *line* should only contain a field specification, and not a **/META** directive.

Passing these functions a directive line instead of a field specification line will result in a syntax error.  These functions never call the registered parser callback function, even if *line* contains a syntax error.

## RETURN VALUE

On success, **gd\_add\_spec**() and **gd\_madd\_spec**() return zero.   On error, a negative-valued error code is returned.  Possible error codes are:\
  .TP 8 **GD\_E\_ACCMODE** The specified dirfile was opened read-only.\
  .TP 8 **GD\_E\_ALLOC** The library was unable to allocate memory.\
  .TP 8 **GD\_E\_BAD\_CODE** The *parent* field code was not found, or was already a metafield.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_BAD\_INDEX** The *fragment\_index* argument was out of range.\
  .TP 8 **GD\_E\_FORMAT** A syntax error was encountered in *line*.\
  .TP 8 **GD\_E\_IO** An I/O error occurred while creating an empty binary file to be associated with a newly added **RAW** field.\
  .TP 8 **GD\_E\_LINE\_TOO\_LONG** The supplied *line* was longer than the parser was able to deal with.  Line lengths are limited by the storage size of **size\_t**.\
  .TP 8 **GD\_E\_PROTECTED** 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.\
  .TP 8 **GD\_E\_UNKNOWN\_ENCODING** 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.\
  .TP 8 **GD\_E\_UNSUPPORTED** 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 [**gd\_error**(3)](/gd_error/3.md). A descriptive error string for the error may be obtained by calling [**gd\_error\_string**(3)](/gd_error_string/3.md).

## HISTORY

The functions **dirfile\_add\_spec**() and **dirfile\_madd\_spec**() appeared in GetData-0.4.0.

In GetData-0.7.0, these functions were renamed to **gd\_add\_spec**() and **gd\_madd\_spec**().

In GetData-0.10.0, the error return from these functions changed from -1 to a negative-valued error code.

## SEE ALSO

[**gd\_add**(3)](/gd_add/3.md), all the **gd\_add\_**\<entry-type\> functions (e.g., [**gd\_add\_bit**(3)](/gd_add_bit/3.md)), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_madd**(3)](/gd_madd/3.md), all the **gd\_madd\_**\<entry-type\> functions (e.g., [**gd\_madd\_bit**(3)](/gd_madd_bit/3.md)), [**gd\_metaflush**(3)](/gd_metaflush/3.md), [**gd\_open**(3)](/gd_open/3.md), [dirfile-format(5)](/dirfile-format/5.md)
