---
name: "bind_textdomain_codeset"
section: "3"
platform: "linux"
package: "gettext"
version: "1.0-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/bind_textdomain_codeset"
---

# bind\_textdomain\_codeset(3)

set encoding of message translations

## NAME

bind\_textdomain\_codeset - set encoding of message translations

## SYNOPSIS

```
#include <libintl.h>

char * bind_textdomain_codeset (const char * domainname,
                                const char * codeset);
```

## DESCRIPTION

The **bind\_textdomain\_codeset** function sets the output codeset for message catalogs for domain *domainname*.

A message domain is a set of translatable *msgid* messages. Usually, every software package has its own message domain.

By default, the **gettext** family of functions returns translated messages in the locale's character encoding, which can be retrieved as **nl\_langinfo (CODESET)**. The need for calling **bind\_textdomain\_codeset** arises for programs which store strings in a locale independent way (e.g. UTF-8) and want to avoid an extra character set conversion on the returned translated messages.

*domainname* must be a non-empty string.

If *codeset* is not NULL, it must be a valid encoding name which can be used for the **iconv\_open** function. The **bind\_textdomain\_codeset** function sets the output codeset for message catalogs belonging to domain *domainname* to *codeset*. The function makes copies of the argument strings as needed.

If *codeset* is NULL, the function returns the previously set codeset for domain *domainname*. The default is NULL, denoting the locale's character encoding.

## RETURN VALUE

If successful, the **bind\_textdomain\_codeset** function returns the current codeset for domain *domainname*, after possibly changing it. The resulting string is valid until the next **bind\_textdomain\_codeset** call for the same *domainname* and must not be modified or freed. If a memory allocation failure occurs, it sets **errno** to **ENOMEM** and returns NULL. If no codeset has been set for domain *domainname*, it returns NULL.

## ERRORS

The following error can occur, among others:

- **ENOMEM**

  Not enough memory available.

## BUGS

The return type ought to be **const char \***, but is **char \*** to avoid warnings in C code predating ANSI C.

## SEE ALSO

[**gettext**(3)](/gettext/3.md), [**dgettext**(3)](/dgettext/3.md), [**dcgettext**(3)](/dcgettext/3.md), [**ngettext**(3)](/ngettext/3.md), [**dngettext**(3)](/dngettext/3.md), [**dcngettext**(3)](/dcngettext/3.md), [**textdomain**(3)](/textdomain/3.md), [**nl\_langinfo**(3)](/nl_langinfo/3.md), [**iconv\_open**(3)](/iconv_open/3.md)
