Debian Codegraph @

upstream/debian-unstable/man3/strstr.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH strstr 3 2026-02-25 "Linux man-pages 6.18"
8 .SH NAME
9 strstr, strcasestr \- locate a substring
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <string.h>
16 .P
17 .BI "char *strstr(const char *" haystack ", const char *" needle );
18 .P
19 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
20 .B #include <string.h>
21 .P
22 .BI "char *strcasestr(const char *" haystack ", const char *" needle );
23 .fi
24 .SH DESCRIPTION
25 The
26 .BR strstr ()
27 function finds the first occurrence of the substring
28 .I needle
29 in the string
30 .IR haystack .
31 The terminating null bytes (\[aq]\[rs]0\[aq]) are not compared.
32 .P
33 It is equivalent to
34 .P
35 .in +4n
36 .EX
37 memmem(haystack, strlen(haystack), needle, strlen(needle))
38 .EE
39 .in
40 .P
41 The
42 .BR strcasestr ()
43 function is like
44 .BR strstr (),
45 but ignores the case of both arguments.
46 .SH RETURN VALUE
47 These functions return a pointer to the beginning of the
48 located substring, or NULL if the substring is not found.
49 .P
50 If
51 .I needle
52 is the empty string,
53 the return value is always
54 .I haystack
55 itself.
56 .SH ATTRIBUTES
57 For an explanation of the terms used in this section, see
58 .BR attributes (7).
59 .TS
60 allbox;
61 lbx lb lb
62 l l l.
63 Interface Attribute Value
64 T{
65 .na
66 .nh
67 .BR strstr ()
68 T} Thread safety MT-Safe
69 T{
70 .na
71 .nh
72 .BR strcasestr ()
73 T} Thread safety MT-Safe locale
74 .TE
75 .SH STANDARDS
76 .TP
77 .BR strstr ()
78 C11, POSIX.1-2008.
79 .TP
80 .BR strcasestr ()
81 GNU.
82 .SH HISTORY
83 .TP
84 .BR strstr ()
85 POSIX.1-2001, C89.
86 .TP
87 .BR strcasestr ()
88 GNU.
89 .SH SEE ALSO
90 .BR memchr (3),
91 .BR memmem (3),
92 .BR strcasecmp (3),
93 .BR strchr (3),
94 .BR string (3),
95 .BR strpbrk (3),
96 .BR strsep (3),
97 .BR strspn (3),
98 .BR strtok (3),
99 .BR wcsstr (3)