diff options
| author | Junio C Hamano <gitster@pobox.com> | 2007-09-10 11:32:58 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2007-09-10 11:32:58 -0700 |
| commit | ddb95de33e99d547c3b533aea12f18c9e4dd649e (patch) | |
| tree | b9d745e3dc1cdd91b0bc938ce104808b2f2db42a /compat/memmem.c | |
| parent | Use strbuf API in cache-tree.c (diff) | |
| parent | Merge branch 'rs/archive' (diff) | |
| download | git-ddb95de33e99d547c3b533aea12f18c9e4dd649e.tar.gz git-ddb95de33e99d547c3b533aea12f18c9e4dd649e.zip | |
Merge branch 'master' into ph/strbuf
* master:
archive - leakfix for format_subst()
Make --no-thin the default in git-push to save server resources
fix doc for --compression argument to pack-objects
git-tag -s must fail if gpg cannot sign the tag.
git-svn: understand grafts when doing dcommit
git-diff: don't squelch the new SHA1 in submodule diffs
Define NO_MEMMEM on Darwin as it lacks the function
git-svn: fix "Malformed network data" with svn:// servers
(cvs|svn)import: Ask git-tag to overwrite old tags.
git-rebase: fix -C option
git-rebase: support --whitespace=<option>
Documentation / grammer nit
archive: rename attribute specfile to export-subst
archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR" (take 2)
add memmem()
Remove unused function convert_sha1_file()
archive: specfile support (--pretty=format: in archive files)
Export format_commit_message()
Diffstat (limited to 'compat/memmem.c')
| -rw-r--r-- | compat/memmem.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/compat/memmem.c b/compat/memmem.c new file mode 100644 index 0000000000..cd0d877364 --- /dev/null +++ b/compat/memmem.c @@ -0,0 +1,29 @@ +#include "../git-compat-util.h" + +void *gitmemmem(const void *haystack, size_t haystack_len, + const void *needle, size_t needle_len) +{ + const char *begin = haystack; + const char *last_possible = begin + haystack_len - needle_len; + + /* + * The first occurrence of the empty string is deemed to occur at + * the beginning of the string. + */ + if (needle_len == 0) + return (void *)begin; + + /* + * Sanity check, otherwise the loop might search through the whole + * memory. + */ + if (haystack_len < needle_len) + return NULL; + + for (; begin <= last_possible; begin++) { + if (!memcmp(begin, needle, needle_len)) + return (void *)begin; + } + + return NULL; +} |
