Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strchr.c File Reference
#include <string.h>
Include dependency graph for strchr.c:

Go to the source code of this file.

Functions

char * __strchrnul (const char *, int)
 
char * strchr (const char *s, int c)
 Finds the first occurrence of c in the null-terminated byte string pointed to by s. More...
 

Function Documentation

◆ __strchrnul()

char* __strchrnul ( const char *  ,
int   
)

Definition at line 13 of file strchrnul.c.

14 {
15  const size_t* w;
16  size_t k;
17  c = (unsigned char)c;
18 
19  if(!c)
20  {
21  return (char*)(uintptr_t)s + strlen(s);
22  }
23 
24  for(; (uintptr_t)s % ALIGN; s++)
25  {
26  if(!*s || *(const unsigned char*)s == c)
27  {
28  return (char*)(uintptr_t)s;
29  }
30  }
31 
32  k = ONES * (unsigned long)c;
33 
34  for(w = (const void*)s; !HASZERO(*w) && !HASZERO(*w ^ k); w++)
35  {
36  {
37  ;
38  }
39  }
40  for(s = (const void*)w; *s && *(const unsigned char*)s != c; s++)
41  {
42  {
43  ;
44  }
45  }
46 
47  return (char*)(uintptr_t)s;
48 }
#define HASZERO(x)
Definition: strchrnul.c:11
#define ONES
Definition: strchrnul.c:9
size_t strlen(const char *str)
Returns the length of the given null-terminated byte string.
Definition: strlen.c:77
#define ALIGN
Definition: strchrnul.c:8

Referenced by strchr(), and strcspn().

Here is the caller graph for this function:

◆ strchr()

char* strchr ( const char *  s,
int  c 
)

Finds the first occurrence of c in the null-terminated byte string pointed to by s.

Finds the first occurrence of c (after conversion to char as if by (char)c ) in the null-terminated byte string pointed to by s (each character interpreted as unsigned char). The terminating null character is considered to be a part of the string and can be found when searching for '\0'.

The behavior is undefined if s is not a pointer to a null-terminated byte string.

Parameters
spointer to the null-terminated byte string to be analyzed
ccharacter to search for
Returns
a pointer to the found character in s, or null pointer if no such character is found.

Definition at line 7 of file strchr.c.

8 {
9  char* r = __strchrnul(s, c);
10  return *(unsigned char*)r == (unsigned char)c ? r : 0;
11 }
char * __strchrnul(const char *, int)
Definition: strchrnul.c:13

References __strchrnul().