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