diff options
author | Benjamin Barenblat <bbaren@google.com> | 2018-11-07 15:10:40 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2018-11-07 15:10:40 -0500 |
commit | 765c39bea005eaa49852ac1f877ed042ab5b68e6 (patch) | |
tree | cd73d7eea5432f111d04a4d182c839bf1a8c01c4 /src/c/memmem.h | |
parent | 096fbda34b67cccd2026c44006bd9bc98d28c98c (diff) |
Systems without memmem(3) are getting rarer every day. We can improve
clarity and efficiency by relying on libc’s memmem whenever possible.
Detect at compile time whether the system supports memmem(3); if it
does, simply reexport its prototype through memmem.h and emit no code.
If it doesn’t, actually build in the memmem code in memmem.c.
Along the way, undo the renaming from commit
6dad7c645d8fdb7b7237c89ff7b34e90adbb86b1. Since we’re only creating a
memmem prototype if libc doesn’t define the symbol, our prototype
should never clash with libc’s.
As before, authors should not assume string.h provides a prototype for
memmem; they should `#include "memmem.h"` if they use the function.
Diffstat (limited to 'src/c/memmem.h')
-rw-r--r-- | src/c/memmem.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/c/memmem.h b/src/c/memmem.h new file mode 100644 index 00000000..0ddbb494 --- /dev/null +++ b/src/c/memmem.h @@ -0,0 +1,23 @@ +#ifndef URWEB_MEMMEM_H +#define URWEB_MEMMEM_H + +#include "config.h" + +#ifdef HAVE_MEMMEM + +#include <string.h> + +#else // !defined(HAVE_MEMMEM) + +#include <stddef.h> + +/* + * memmem() returns the location of the first occurence of data + * pattern b2 of size len2 in memory block b1 of size len1 or + * NULL if none is found. + */ +void *memmem(const void *b1, size_t len1, const void *b2, size_t len2); + +#endif // !defined(HAVE_MEMMEM) + +#endif // URWEB_MEMMEM_H |