]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/memmem.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / memmem.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" 386BSD man pages
26 .\" Modified Sat Jul 24 18:50:48 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Interchanged `needle' and `haystack'; added history, aeb, 980113.
28 .TH MEMMEM 3 1998-01-13 "GNU" "Linux Programmer's Manual"
29 .SH NAME
30 memmem \- locate a substring
31 .SH SYNOPSIS
32 .nf
33 .B #define _GNU_SOURCE
34 .br
35 .B #include <string.h>
36 .sp
37 .BI "void *memmem(const void *" haystack ", size_t " haystacklen ,
38 .in +\w'void *memmem('u
39 .BI "const void *" needle ", size_t " needlelen );
40 .in
41 .fi
42 .SH DESCRIPTION
43 The \fBmemmem\fP() function finds the start of the first occurrence
44 of the substring \fIneedle\fP of length \fIneedlelen\fP in the memory
45 area \fIhaystack\fP of length \fIhaystacklen\fP.
46 .SH "RETURN VALUE"
47 The \fBmemmem\fP() function returns a pointer to the beginning of the
48 substring, or NULL if the substring is not found.
49 .SH "CONFORMING TO"
50 This function is a GNU extension.
51 .SH BUGS
52 This function was broken in Linux libraries up to and including libc 5.0.9;
53 there the `needle' and `haystack' arguments were interchanged,
54 and a pointer to the end of the first occurrence of \fIneedle\fP
55 was returned. Since libc 5.0.9 is still widely used, this is a
56 dangerous function to use.
57 .br
58 Both old and new libc's have the bug that if \fIneedle\fP is empty
59 \fIhaystack\fP-1 (instead of \fIhaystack\fP) is returned.
60 And glibc 2.0 makes it worse, and returns a pointer to the
61 last byte of `haystack'. This is fixed in glibc 2.1.
62 .SH "SEE ALSO"
63 .BR strstr (3)