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

# gd\_sync(3)

write all pending Dirfile changes to disk or close open raw fields

Part of [gd\_flush(3)](/gd_flush/3.md).

## NAME

gd\_flush gd\_raw\_close gd\_sync — write all pending Dirfile changes to disk or close open raw fields

## SYNOPSIS

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

**int gd\_flush(DIRFILE \****dirfile***, const char \****field\_code***);**

**int gd\_raw\_close(DIRFILE \****dirfile***, const char \****field\_code***);**

**int gd\_sync(DIRFILE \****dirfile***, const char \****field\_code***);**

## DESCRIPTION

The **gd\_sync**() function flushes all pending writes to disk of raw data files associated with *field\_code*, or its input(s), in the dirfile specified by *dirfile*. If the *field\_code* contains a valid representation suffix, it will be ignored.

As a special case, if NULL is passed to **gd\_sync**() as *field\_code*, all fields in *dirfile* will be flushed.  In this special case, modified metadata will also be flushed to disk as if [**gd\_metaflush**(3)](/gd_metaflush/3.md) had been called.  If the dirfile has been opened read-only, this function does nothing.  Additionally, some encoding schemes may implement this as a NOP.

The **gd\_raw\_close**() function closes any raw data files which GetData has opened associated with *field\_code*, or its input(s).  Again, if *field\_code* is NULL, all open data files are closed.  The I/O pointer of any **RAW** field which is closed is reset to the beginning-of-field.

Calling **gd\_flush**() is essentially equivalent to calling first **gd\_sync**() and then **gd\_raw\_close**() (ie. it does both tasks), although, if *field\_code* is NULL, the order of operations if may be different than making the two explicit calls.

## RETURN VALUE

On success, these functions return zero.   On error, a negative-valued error code is returned.  Possible error codes are:\
  .TP 8 **GD\_E\_ALLOC** The library was unable to allocate memory.\
  .TP 8 **GD\_E\_BAD\_CODE** The field specified by *field\_code* was not found in the database.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_IO** An I/O error occurred while trying to write modified data or metadata to disk.\
  .TP 8 **GD\_E\_LINE\_TOO\_LONG** While attempting to flush modified metadata to disk, a field specification line exceeded the maximum allowed length.  On most platforms, the maximum length is at least 2\*\*31 bytes, so this typically indicates something pathological happening.\
  .TP 8 **GD\_E\_RECURSE\_LEVEL** Too many levels of recursion were encountered while trying to resolve *field\_code*. This usually indicates a circular dependency in field specification in the dirfile.

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 **dirfile\_flush**() function appeared in GetData-0.3.0.

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

The **gd\_raw\_close**() and **gd\_sync**() functions 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\_close**(3)](/gd_close/3.md), [**gd\_dirfile\_standards**(3)](/gd_dirfile_standards/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md), [**gd\_metaflush**(3)](/gd_metaflush/3.md), [**gd\_open**(3)](/gd_open/3.md)
