Archived
1
0
Fork 0

compat: Added memrchr implementation

This commit is contained in:
Henrik Hautakoski 2010-11-27 18:07:16 +01:00
parent 132bc6e838
commit de032e9b33
2 changed files with 27 additions and 0 deletions

21
src/compat/memrchr.c Normal file
View 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
View file

@ -0,0 +1,6 @@
#include <string.h>
#ifdef NO_MEMRCHR
extern void* memrchr(const void *, int, size_t);
#endif