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

# scan\_utf8(3)

decode an unsigned integer from UTF-8 encoding

## NAME

scan\_utf8 - decode an unsigned integer from UTF-8 encoding

## SYNTAX

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

size\_t **scan\_utf8**(const char \**src*,size\_t *len*,uint32\_t \**dest*);

size\_t **scan\_utf8\_sem**(const char \**src*,size\_t *len*,uint32\_t \**dest*);

## DESCRIPTION

scan\_utf8 decodes an unsigned integer in UTF-8 encoding from a memory area holding binary data.  It writes the decode value in *dest* and returns the number of bytes it read from *src*.

scan\_utf8 never reads more than *len* bytes from *src*.  If the sequence is longer than that, or the memory area contains an invalid sequence, scan\_utf8 returns 0 and does not touch *dest*.

The length of the longest valid UTF-8 sequence is 6.

scan\_utf8 will reject syntactically invalid encodings, but not semantically invalid ones. scan\_utf8\_sem will additionally reject surrogates.

## 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 above 0x10ffff are not valid UTF-8.  If you are using this function to parse UTF-8, you need to reject them (see RFC 3629).

## SEE ALSO

[fmt\_utf8(3)](/fmt_utf8/3.md), [scan\_utf8\_sem(3)](/scan_utf8_sem/3.md)
