---
name: "fmt_utf8"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/fmt_utf8"
---

# fmt\_utf8(3)

encode 31-bit unsigned integer using UTF-8 rules

## NAME

fmt\_utf8 - encode 31-bit unsigned integer using UTF-8 rules

## SYNTAX

**#include \<libowfat/fmt.h\>**

size\_t **fmt\_utf8**(char \**dest*,uint32\_t *source*);

## DESCRIPTION

fmt\_utf8 encodes a 31-bit unsigned integer using the UTF-8 rules.  This can take from 1 byte (0-0x7f) up to 5 bytes (0x4000000-0x7fffffff). Values larger than 0x7fffffff cannot be represented in this encoding.

If *dest* equals FMT\_LEN (i.e. is NULL), fmt\_utf8 returns the number of bytes it would have written.

For convenience, fmt.h defines the integer FMT\_UTF8 to be big enough to contain every possible fmt\_utf8 output.

## NOTE

fmt\_utf8 and scan\_utf8 implement the encoding from UTF-8, but are meant to be able to store integers, not just Unicode code points.  Values larger than 0x10ffff are not valid UTF-8 (see RFC 3629) but can be represented in the encoding, so fmt\_utf8 will allow them.

## SEE ALSO

[scan\_utf8(3)](/scan_utf8/3.md)
