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

# gd\_fragment\_index(3)

retrieve the fragment containing a Dirfile field

## NAME

gd\_fragment\_index — retrieve the fragment containing a Dirfile field

## SYNOPSIS

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

**int gd\_fragment\_index(const DIRFILE \****dirfile***, const char** **\****entry\_name***);**

## DESCRIPTION

The **gd\_fragment\_index**() function queries a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* and returns the index number of the fragment defining the field or alias named *entry\_name*.

This is one of the few GetData functions which does not resolve aliases: supplying the name of an alias as *entry\_name* will return the index of the fragment containing the alias itself and not that of its target.

## RETURN VALUE

Upon successful completion, **gd\_fragment\_index**() returns the requested fragment index, which is never negative.  On error, **gd\_fragment\_index**() returns a negative-valued error code.  Possible error codes are:\
  .TP 8 **GD\_E\_BAD\_CODE** The entry specified by *entry\_name* was not found in the database.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.

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 **get\_fragment\_index**() function appeared in GetData-0.5.0.

In GetData-0.7.0, this function was renamed to **gd\_fragment\_index**().

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

## SEE ALSO

[**gd\_open**(3)](/gd_open/3.md), [**gd\_entry**(3)](/gd_entry/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_fragmentname**(3)](/gd_fragmentname/3.md), [**gd\_parent\_fragment**(3)](/gd_parent_fragment/3.md), [dirfile(5)](/dirfile/5.md)
