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

# gd\_parent\_fragment(3)

retrieve the parent fragment of a fragment in a Dirfile

## NAME

gd\_parent\_fragment — retrieve the parent fragment of a fragment in a Dirfile

## SYNOPSIS

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

**int gd\_parent\_fragment(DIRFILE \****dirfile***, int** *fragment\_index***);**

## DESCRIPTION

The **gd\_parent\_fragment**() function queries a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* and returns the index of the fragment which contains the **INCLUDE** directive for the fragment indexed by *fragment\_index*.

Since the primary format specification fragment is not included in any other fragment, passing zero for *fragment\_index* will result in an error.

## RETURN VALUE

On success, **gd\_parent\_fragment**() returns the index of the specified fragment's parent.  On error, **gd\_parent\_fragment**() returns a negative-valued error code.  Possible error codes are:\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_BAD\_INDEX** The supplied index was out of range, or was equal to zero.

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

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

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

## SEE ALSO

[dirfile(5)](/dirfile/5.md), [**gd\_include**(3)](/gd_include/3.md), [**gd\_open**(3)](/gd_open/3.md), [**gd\_fragmentname**(3)](/gd_fragmentname/3.md), [**gd\_nfragments**(3)](/gd_nfragments/3.md)
