Misc tidyups replacing magic numbers with defines,

better help text, and some added comments
This commit is contained in:
nvx committed 2023-08-24 15:08:11 +10:00
1 parent db7a8e1e57
commit 42330fc5ed
2 files changed
+29 -22

No files matched your search

+5
View File
@@ -1266,6 +1266,8 @@ inline uint64_t leadingzeros64(uint64_t a) {
}
// byte_strstr searches for the first occurrence of pattern in src
// returns the byte offset the pattern is found at, or -1 if not found
int byte_strstr(const uint8_t *src, size_t srclen, const uint8_t *pattern, size_t plen) {
size_t max = srclen - plen + 1;
@@ -1289,6 +1291,9 @@ int byte_strstr(const uint8_t *src, size_t srclen, const uint8_t *pattern, size_
return -1;
}
// byte_strrstr is like byte_strstr except searches in reverse
// ie it returns the last occurrence of the pattern in src instead of the first
// returns the byte offset the pattern is found at, or -1 if not found
int byte_strrstr(const uint8_t *src, size_t srclen, const uint8_t *pattern, size_t plen) {
for (int i = srclen - plen; i >= 0; i--) {
// compare only first byte