---
name: "strnlen"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/strlen"
---

# strnlen(3)

find length of string

Part of [strlen(3)](/strlen/3.md).

## NAME

**strlen**, **strnlen** – find length of string

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

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

*size\_t*\

**strlen**(*const char \*s*);

*size\_t*\

**strnlen**(*const char \*s*, *size\_t maxlen*);

## DESCRIPTION

The **strlen**() function computes the length of the string *s*. The **strnlen**() function attempts to compute the length of *s*, but never scans beyond the first *maxlen* bytes of *s*.

## RETURN VALUES

The **strlen**() function returns the number of characters that precede the terminating NUL character. The **strnlen**() function returns either the same result as **strlen**() or *maxlen*, whichever is smaller.

## SEE ALSO

[string(3)](/string/3.md), [wcslen(3)](/wcslen/3.md), [wcswidth(3)](/wcswidth/3.md)

## STANDARDS

The **strlen**() function conforms to ISO/IEC 9899:1990 (“ISO C90”). The **strnlen**() function conforms to IEEE Std 1003.1-2008 (“POSIX.1”).

## HISTORY

The **strlen**() function first appeared in the Programmer's Workbench (PWB/UNIX) and was ported to Version 7 AT&T UNIX. The **strnlen**() function first appeared in FreeBSD 8.0, OpenBSD 4.8, and NetBSD 6.0.
