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

# gd\_carray\_len(3)

returns the length of a CARRAY or SARRAY field in a Dirfile

Part of [gd\_array\_len(3)](/gd_array_len/3.md).

## NAME

gd\_array\_len — returns the length of a CARRAY or SARRAY field in a Dirfile

## SYNOPSIS

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

**size\_t gd\_array\_len(DIRFILE \****dirfile***, const char \****field\_code***);**

## DESCRIPTION

The **gd\_array\_len**() function queries a [dirfile(5)](/dirfile/5.md) database specified by *dirfile* and calculates the length of the **CARRAY**, **CONST**, **STRING**, or **SARRAY** field called *field\_code*. If *field\_code* contains a valid representation suffix, it will be ignored.

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

## RETURN VALUE

Upon successful completion, **gd\_array\_len**() returns a positive integer indicating the array length of the field specified. (The length of a **CONST** or a **STRING** field is always 1.) On error, it returns a negative-valued error code.  Possible error codes are:\
  .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\_BAD\_FIELD\_TYPE** The field specified by *field\_code* was not of one of the field types listed above.

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 **gd\_carray\_len**() function appeared in GetData-0.7.0.  It was restricted to **CONST** and **CARRAY** entries.

In GetData-0.9.0, this function was renamed to **gd\_array\_len**, and **STRING** entries were now valid for this function.

Before GetData-0.10.0, this function could also fail with the error code **GD\_E\_ALLOC**.

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\_open**(3)](/gd_open/3.md), [**gd\_error**(3)](/gd_error/3.md), [**gd\_error\_string**(3)](/gd_error_string/3.md)
