Skip to content

Commit

Permalink
add strrchr() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bediger4000 committed May 11, 2017
1 parent 1b99ff7 commit 2491806
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions libstatic/libstatic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void linux_brk(unsigned long addr);

unsigned long strlen(const char *s);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strstr(const char *str, char *substr);
void *memcpy(void *dest, const void *src, unsigned long n);
char *strcat(char *dest, const char *src);
Expand Down
18 changes: 18 additions & 0 deletions libstatic/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ char *strchr(const char *s, int c)
return r;
}

char *strrchr(const char *s, int c)
{
char *r = NULL;
char *p;

p = &s[strlen(s)-1];

for (; p != s; --p)
{
if (*p == c)
{
r = (char *)p;
break;
}
}
return r;
}

char *
strcat(char *dest, const char *src)
{
Expand Down

0 comments on commit 2491806

Please sign in to comment.