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