Bash  5.0-beta2
Bash - Bourne Again shell
strstr.c File Reference
#include <sys/types.h>

Go to the source code of this file.

Typedefs

typedef unsigned chartype
 

Functions

char * strstr (const char *phaystack, const char *pneedle)
 

Typedef Documentation

◆ chartype

typedef unsigned chartype

Definition at line 39 of file strstr.c.

Function Documentation

◆ strstr()

char* strstr ( const char *  phaystack,
const char *  pneedle 
)

Definition at line 44 of file strstr.c.

References c.

Referenced by _nl_init_domain_conv(), add_links(), extract_plural_expression(), main(), rl_history_search_internal(), scan_request(), scan_table(), and yyparse().

45 {
46  register const unsigned char *haystack, *needle;
47  register chartype b, c;
48 
49  haystack = (const unsigned char *) phaystack;
50  needle = (const unsigned char *) pneedle;
51 
52  b = *needle;
53  if (b != '\0')
54  {
55  haystack--; /* possible ANSI violation */
56  do
57  {
58  c = *++haystack;
59  if (c == '\0')
60  goto ret0;
61  }
62  while (c != b);
63 
64  c = *++needle;
65  if (c == '\0')
66  goto foundneedle;
67  ++needle;
68  goto jin;
69 
70  for (;;)
71  {
72  register chartype a;
73  register const unsigned char *rhaystack, *rneedle;
74 
75  do
76  {
77  a = *++haystack;
78  if (a == '\0')
79  goto ret0;
80  if (a == b)
81  break;
82  a = *++haystack;
83  if (a == '\0')
84  goto ret0;
85 shloop:; }
86  while (a != b);
87 
88 jin: a = *++haystack;
89  if (a == '\0')
90  goto ret0;
91 
92  if (a != c)
93  goto shloop;
94 
95  rhaystack = haystack-- + 1;
96  rneedle = needle;
97  a = *rneedle;
98 
99  if (*rhaystack == a)
100  do
101  {
102  if (a == '\0')
103  goto foundneedle;
104  ++rhaystack;
105  a = *++needle;
106  if (*rhaystack != a)
107  break;
108  if (a == '\0')
109  goto foundneedle;
110  ++rhaystack;
111  a = *++needle;
112  }
113  while (*rhaystack == a);
114 
115  needle = rneedle; /* took the register-poor approach */
116 
117  if (a == '\0')
118  break;
119  }
120  }
121 foundneedle:
122  return (char*) haystack;
123 ret0:
124  return 0;
125 }
register GCHAR c
Definition: glob_loop.c:26
unsigned chartype
Definition: strstr.c:39
Here is the caller graph for this function: