-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3912d9e
commit 43560d3
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "util.h" | ||
|
||
#include <cstring> | ||
#include <cstdint> | ||
|
||
// TTYD doesn't use this so we reimplement it. | ||
// TODO: Not the greatest solution in the long run | ||
char *strstr(const char *container, const char *pattern) | ||
{ | ||
int pattern_len = strlen(pattern); | ||
for (const char *start = container; *start; ++start) | ||
{ | ||
bool mismatch = false; | ||
for (int i = 0; i < pattern_len; ++i) | ||
{ | ||
if (!container[i] || start[i] != pattern[i]) | ||
{ | ||
mismatch = true; | ||
break; | ||
} | ||
} | ||
if (!mismatch) | ||
{ | ||
// Cast away the const because C demands it | ||
return (char *)start; | ||
} | ||
} | ||
return nullptr; | ||
} |