]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/memmem.3
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man3 / memmem.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" 386BSD man pages
8 .\" Modified Sat Jul 24 18:50:48 1993 by Rik Faith (faith@cs.unc.edu)
9 .\" Interchanged 'needle' and 'haystack'; added history, aeb, 980113.
10 .TH MEMMEM 3 2021-03-22 "GNU" "Linux Programmer's Manual"
11 .SH NAME
12 memmem \- locate a substring
13 .SH LIBRARY
14 Standard C library
15 .RI ( libc ", " \-lc )
16 .SH SYNOPSIS
17 .nf
18 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
19 .B #include <string.h>
20 .PP
21 .BI "void *memmem(const void *" haystack ", size_t " haystacklen ,
22 .BI " const void *" needle ", size_t " needlelen );
23 .fi
24 .SH DESCRIPTION
25 The
26 .BR memmem ()
27 function finds the start of the first occurrence
28 of the substring
29 .I needle
30 of length
31 .I needlelen
32 in the memory
33 area
34 .I haystack
35 of length
36 .IR haystacklen .
37 .SH RETURN VALUE
38 The
39 .BR memmem ()
40 function returns a pointer to the beginning of the
41 substring, or NULL if the substring is not found.
42 .SH ATTRIBUTES
43 For an explanation of the terms used in this section, see
44 .BR attributes (7).
45 .ad l
46 .nh
47 .TS
48 allbox;
49 lbx lb lb
50 l l l.
51 Interface Attribute Value
52 T{
53 .BR memmem ()
54 T} Thread safety MT-Safe
55 .TE
56 .hy
57 .ad
58 .sp 1
59 .SH CONFORMING TO
60 This function is not specified in POSIX.1,
61 but is present on a number of other systems.
62 .SH BUGS
63 .\" This function was broken in Linux libraries up to and including libc 5.0.9;
64 .\" there the
65 .\" .IR needle
66 .\" and
67 .\" .I haystack
68 .\" arguments were interchanged,
69 .\" and a pointer to the end of the first occurrence of
70 .\" .I needle
71 .\" was returned.
72 .\"
73 .\" Both old and new libc's have the bug that if
74 .\" .I needle
75 .\" is empty,
76 .\" .I haystack\-1
77 .\" (instead of
78 .\" .IR haystack )
79 .\" is returned.
80 In glibc 2.0, if
81 .I needle
82 is empty,
83 .BR memmem ()
84 returns a pointer to the last byte of
85 .IR haystack .
86 This is fixed in glibc 2.1.
87 .SH SEE ALSO
88 .BR bstring (3),
89 .BR strstr (3)