Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/compat/memmem.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / compat / memmem.c` 32 lines ยท 752 bytes Raw Blame History 1 #include "../git-compat-util.h" 2 3 void *gitmemmem(const void *haystack, size_t haystack_len, 4 const void *needle, size_t needle_len) 5 { 6 const char *begin = haystack; 7 const char *last_possible = begin + haystack_len - needle_len; 8 const char *tail = needle; 9 char point; 10 11 /* 12 * The first occurrence of the empty string is deemed to occur at 13 * the beginning of the string. 14 */ 15 if (needle_len == 0) 16 return (void *)begin; 17 18 /* 19 * Sanity check, otherwise the loop might search through the whole 20 * memory. 21 */ 22 if (haystack_len < needle_len) 23 return NULL; 24 25 point = *tail++; 26 for (; begin <= last_possible; begin++) { 27 if (*begin == point && !memcmp(begin + 1, tail, needle_len - 1)) 28 return (void *)begin; 29 } 30 31 return NULL; 32 }