---
name: "gd_add_alias"
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_alias"
---

# gd\_add\_alias(3)

add a field to a Dirfile

## NAME

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

## SYNOPSIS

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

**int gd\_add\_alias(DIRFILE \****dirfile***, const char \****alias\_name***,** **const char \****target\_code***, int** *fragment\_index***);**

**int gd\_madd\_alias(DIRFILE \****dirfile***, const char \****parent***,** **const char \****alias\_name***, const char \****target\_code***);**

## DESCRIPTION

The **gd\_add\_alias**() function adds the alias named *alias\_name* pointing to *target\_code* to the fragment indexed by *fragment\_index* in the dirfile specified by *dirfile*. The **gd\_madd\_alias**() function behaves similarly, but adds the field as a meta-entry under the field indicated by the field code *parent*.

## RETURN VALUE

On success, **gd\_add\_alias**() and **gd\_madd\_alias**() 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** Either the *alias\_name* was invalid: containing an invalid character or lacking the containing fragment's namespace or affixes, or else 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* specified was out of range.\
  .TP 8 **GD\_E\_DUPLICATE** The *alias\_name* parameter duplicated that of an already existing entry.\
  .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.

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 **gd\_add\_alias**() and **gd\_madd\_alias**() appeared in GetData-0.8.0.

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), [**gd\_alias\_target**(3)](/gd_alias_target/3.md), [**gd\_entry**(3)](/gd_entry/3.md), [**gd\_madd**(3)](/gd_madd/3.md), [**gd\_metaflush**(3)](/gd_metaflush/3.md), [**gd\_open**(3)](/gd_open/3.md), [dirfile-format(5)](/dirfile-format/5.md)
