compat: Added memrchr implementation
This commit is contained in:
parent
132bc6e838
commit
de032e9b33
2 changed files with 27 additions and 0 deletions
21
src/compat/memrchr.c
Normal file
21
src/compat/memrchr.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* memrchr.c
|
||||
*
|
||||
* memrchr implementation for systems without it
|
||||
*
|
||||
* Copyright (C) 2010 Henrik Hautakoski <henrik@fiktivkod.org>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
6
src/compat/string.h
Normal file
6
src/compat/string.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef NO_MEMRCHR
|
||||
extern void* memrchr(const void *, int, size_t);
|
||||
#endif
|
||||
Reference in a new issue