?
Mein Vorschlag wär
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int filestr(FILE *haystack, char const *needle) {
size_t n = strlen(needle);
size_t count = 0;
char *dbuf = calloc(n * 2 + 1, sizeof(char));
char *vorn = dbuf, *hinten = dbuf + n;
if(dbuf == NULL) {
return -1;
}
for(count = fread(dbuf, sizeof(char), 2 * n, haystack);
count != 0;
memmove(vorn, hinten, n), count = fread(hinten, sizeof(char), n, haystack)) {
char *found = strstr(dbuf, needle);
if(found) {
fseek(haystack, found - vorn - n - count, SEEK_CUR);
break;
}
}
free(dbuf);
return 0;
}
Da ließe sich aber sicher noch einiges optimieren. n auf eine vernünftige Blockgröße aufrunden, beispielsweise - strlen(needle) ist halt bloß das absolute Minimum.