From de032e9b33fc5a48e1cca1c6d9dbb6c5b37e8458 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 27 Nov 2010 18:07:16 +0100 Subject: [PATCH] compat: Added memrchr implementation --- src/compat/memrchr.c | 21 +++++++++++++++++++++ src/compat/string.h | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 src/compat/memrchr.c create mode 100644 src/compat/string.h diff --git a/src/compat/memrchr.c b/src/compat/memrchr.c new file mode 100644 index 0000000..731be3d --- /dev/null +++ b/src/compat/memrchr.c @@ -0,0 +1,21 @@ +/* memrchr.c + * + * memrchr implementation for systems without it + * + * Copyright (C) 2010 Henrik Hautakoski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + */ + +#include "string.h" + +void* memrchr(const void *s, int c, size_t n) { + + for(s += n++; n; n--) + if (*((char*)s--) == c) + return (void*) s + 1; + return NULL; +} diff --git a/src/compat/string.h b/src/compat/string.h new file mode 100644 index 0000000..ef96332 --- /dev/null +++ b/src/compat/string.h @@ -0,0 +1,6 @@ + +#include + +#ifdef NO_MEMRCHR +extern void* memrchr(const void *, int, size_t); +#endif