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

Go to the source code of this file.

Functions

void * __memrchr (const void *, int, size_t)
 
char * strrchr (const char *s, int c)
 Finds the last occurrence of c in the null-terminated byte string pointed to by s. More...
 

Function Documentation

◆ __memrchr()

void* __memrchr ( const void *  ,
int  ,
size_t   
)

Definition at line 7 of file memrchr.c.

8 {
9  const unsigned char* s = m;
10  c = (unsigned char)c;
11 
12  while(n--)
13  {
14  if(s[n] == c)
15  {
16  return (void*)(uintptr_t)(s + n);
17  }
18  }
19 
20  return 0;
21 }

Referenced by strrchr().

Here is the caller graph for this function:

◆ strrchr()

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

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

Finds the last 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 strrchr.c.

8 {
9  return __memrchr(s, c, strlen(s) + 1);
10 }
void * __memrchr(const void *, int, size_t)
Definition: memrchr.c:7
size_t strlen(const char *str)
Returns the length of the given null-terminated byte string.
Definition: strlen.c:77

References __memrchr(), and strlen().