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

# gd\_put\_string(3)

write a STRING or SARRAY element to a Dirfile database

## NAME

gd\_put\_string — write a STRING or SARRAY element to a Dirfile database

## SYNOPSIS

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

**int gd\_put\_string(DIRFILE \****dirfile***, const char \****field\_code***,** **const char \****data\_in***);**

## DESCRIPTION

The **gd\_put\_string**() function queries a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* and stores the character string *data\_in* in the **STRING** or **SARRAY** scalar field, specified by *field\_code*. If *field\_code* specifies a **SARRAY** field, the supplied string is stored as the first element.

The  *dirfile* argument must point to a valid DIRFILE object previously created by a call to [**gd\_open**(3)](/gd_open/3.md).

Because string values are stored in the dirfile metadata, the new value of *field\_code* won't be written to disk until the dirfile metadata is flushed with [**gd\_metaflush**(3)](/gd_metaflush/3.md), or until the dirfile is closed with [**gd\_close**(3)](/gd_close/3.md).

The [**gd\_put\_sarray**(3)](/gd_put_sarray/3.md) function provides another way of storing **STRING** and **SARRAY** data to a Dirfile.

## RETURN VALUE

On success, **gd\_put\_string**() returns zero.  On error, this a negative-valued error code.  Possible error codes are:\
  .TP 8 **GD\_E\_ACCMODE** The specified *dirfile* was opened read-only.\
  .TP 8 **GD\_E\_BAD\_CODE** The field specified by *field\_code* was not found in the database.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** An invalid *dirfile* was supplied.\
  .TP 8 **GD\_E\_BAD\_FIELD\_TYPE** The supplied *field\_code* referred to a field of type other than **SARRAY** or **STRING**.\
  .TP 8 **GD\_E\_INTERNAL\_ERROR** An internal error occurred in the library while trying to perform the task. This indicates a bug in the library.  Please report the incident to the maintainer.\
  .TP 8 **GD\_E\_PROTECTED** The fragment containing the string was protected from change.

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 **put\_string**() function apepared in GetData-0.4.0.  It returned a **size\_t** cotnaining length of the string written, or zero on error.

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

In GetData-0.10.0, this function's return value changed to zero on success, or or else a negative-valued error code.

## SEE ALSO

[dirfile(5)](/dirfile/5.md), [**gd\_close**(3)](/gd_close/3.md), [**gd\_get\_string**(3)](/gd_get_string/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), [**gd\_put\_sarray**(3)](/gd_put_sarray/3.md).
