memmem(3)

memmem3

Locate a byte subsequence in a byte sequence

Usage

#include <string.h>

QVoid *

memmem(QVoid *big, size_t big_len, const void *little, size_t little_len);

Library

Standard C Library (libc, -lc)

Overview

The memmem() function locates the first occurrence of the byte sequence little in the byte sequence big.

Return values

If little_len is zero big is returned (that is, an empty little is deemed to match at the beginning of big); if little occurs nowhere in big, NULL is returned; otherwise a pointer to the first character of the first occurrence of little is returned.

Releases

49 releases since FreeBSD 6.0-RELEASE; the text changed 36 times.

  1. 6.0–6.1
  2. 6.2–6.3
  3. 6.4
  4. 7.0
  5. 7.1
  6. 7.2
  7. 7.3
  8. 7.4
  9. 8.0
  10. 8.1
  11. 8.2
  12. 8.3
  13. 8.4
  14. 9.0
  15. 9.1
  16. 9.2
  17. 9.3
  18. 10.0
  19. 10.1
  20. 10.2
  21. 10.3
  22. 10.4
  23. 11.0
  24. 11.1
  25. 11.2
  26. 11.3
  27. 11.4
  28. 12.0
  29. 12.1
  30. 12.2
  31. 12.3
  32. 12.4
  33. 13.0–13.2
  34. 13.3–13.5
  35. 14.0–14.2
  36. 14.3–15.1
  37. 16.0

Standards

memmem() conforms to IEEE Std 1003.1-2024 (“POSIX.1”). Like the qualifier-preserving functions in ISO/IEC 9899:2024 (“ISO C23”), FreeBSD implements memmem() as qualifier-preserving as well.

History

The memmem() function first appeared in FreeBSD 6.0. It was replaced with an optimized O(n) implementation from the musl libc project in FreeBSD 12.0. Pascal Gloor ⟨[email protected]⟩ provided this man page along with the previous implementation.

Bugs

This function was broken in Linux libc up to and including version 5.0.9 and in GNU libc prior to version 2.1. Prior to FreeBSD 11.0 memmem returned NULL when little_len equals 0.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.