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

# gd\_rename(3)

change the name of a Dirfile field or alias

## NAME

gd\_rename — change the name of a Dirfile field or alias

## SYNOPSIS

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

**int gd\_rename(DIRFILE \****dirfile***, const char** **\****old\_code***, const char \****new\_name***, unsigned int** *flags***);**

## DESCRIPTION

The **gd\_rename**() function changes the name of the field or alias specified by *old\_code*, which should not contain a representation suffix, defined in the dirfile specified by *dirfile* to *new\_name*. If the new name is the same as the old name, this function does nothing and returns no error.

When renaming a metafield, the metafield should be specified in *old\_code* by its full (slashed) field code, while *new\_name* should only contain the new name (without slash).

If  *old\_code* specifies a top-level field with meta subfields, the subfields will be renamed, too.  By default, this function also updates **ALIAS** entries whose target contains *old\_code* to point to the new field.  Similarly, specifying the **GD\_REN\_UPDB** flag will cause this function to modify any field entry containing *old\_code*. As a result, this function may cause more than one metadata fragment to be modified.

The *flags* parameter should be zero or more of the following flags, bitwise or'd together:\
  .TP 8 **GD\_REN\_DANGLE** Don't update **ALIAS** entries, instead turning them into dangling aliases.\
  .TP 8 **GD\_REN\_DATA** if *old\_code* specifies a **RAW** field, the binary file associated with the field will be renamed as well. Without this flag, no changes are made to the binary file.  In this case, the field's I/O pointer will be reset to the beginning-of-frame.  If *field\_code* specifies a field of type other than **RAW**, this flag is ignored.\
  .TP 8 **GD\_REN\_FORCE** When updating field metadata (either the target of an alias, or else when specified along with **GD\_REN\_UPDB**), skip updating field codes which would be invalid (due to **/INCLUDE** affixes).  Without this flag, such invalid field codes causes this function to fail with the error **GD\_E\_BAD\_CODE**.\
  .TP 8 **GD\_REN\_UPDB** Rename the field in any other field specifications which use this field as an input (either as a vector input field to a derived field, or else as a scalar field parameter).  Without this flag, fields which depend on the old name of this field are left unmodified.

## RETURN VALUE

On success, **gd\_rename**() returns zero.   On error, a negative-valued error code is returned.  Possible error codes are:\
  .TP 8 **GD\_E\_ACCMODE** The specified dirfile was opened read-only.\
  .TP 8 **GD\_E\_ALLOC** The library was unable to allocate memory.\
  .TP 8 **GD\_E\_BAD\_CODE** The field specified by *old\_code* was not found.  Or else the resultant metadata update tried to change a field code into something prohibited by a fragment's affixes.\
  .TP 8 **GD\_E\_BAD\_DIRFILE** The supplied dirfile was invalid.\
  .TP 8 **GD\_E\_BAD\_FIELD\_TYPE** An attempt was made to rename the immutable *INDEX* field.\
  .TP 8 **GD\_E\_DUPLICATE** The new name specified is already in use by another entry.\
  .TP 8 **GD\_E\_IO** An I/O error occurred while attempting to rename the binary file.\
  .TP 8 **GD\_E\_PROTECTED** The metadata of the format specification fragment containing the renamed entry, or another entry affected by this change, was protected from change, or the binary data of the fragment was protected from change and a binary file move was requested.\
  .TP 8 **GD\_E\_UNKNOWN\_ENCODING** The encoding scheme of the specified field could not be determined or was not understood by GetData.\
  .TP 8 **GD\_E\_UNSUPPORTED** The encoding scheme of the field does not support binary file renaming.

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\_rename**() function appeared in GetData-0.5.0.  It had no *flags* argument.  In its place was **int** *move\_data*. Passing a non-zero value for this parameter has the same effect as the **GD\_REN\_DATA** flag does now.

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

In GetData-0.8.0, the *move\_data* parameter was replaced with the *flags* parameter.  The only flags available were **GD\_REN\_DATA** and **GD\_REN\_UBDB**.

The flags **GD\_REN\_DANGLE** and **GD\_REN\_FORCE** flags appeared in GetData-0.9.0.

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

## SEE ALSO

[**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), [dirfile(5)](/dirfile/5.md), [dirfile-format(5)](/dirfile-format/5.md)
