Skip to content
Snippets Groups Projects
Commit 2950df31 authored by Luis Gerhorst's avatar Luis Gerhorst
Browse files

Search with memcmp

parent c85a7cba
Branches
Tags
No related merge requests found
......@@ -130,8 +130,13 @@ static void plog(const unsigned int level, const char *fmt, ...) {
va_end(args);
}
static int search_buf(buf, f_len, file_full_path, literal) {
fprintf(stderr, "%d: %s", f_len, buf);
static int search_buf(const char *buf, size_t f_len, const char *file_full_path,
const char *literal) {
size_t literal_len = strlen(literal);
for (int i = 0; i < f_len - literal_len + 1; i++) {
if (!memcmp(buf + i, literal, literal_len))
printf("%d\n", i);
}
return EXIT_SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment