AP_HAL: added replacement for memrchr()

This commit is contained in:
Andrew Tridgell 2018-12-06 11:12:13 +11:00
parent bdacc410ca
commit 8907506c18
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,22 @@
/*
replacement functions for systems that are missing required library functions
*/
#include "replace.h"
#ifndef HAVE_MEMRCHR
/*
replacement for memrchr(). Note that we make the buffer non-const to
avoid issues with converting const to non-const
*/
void *replace_memrchr(void *s, int c, size_t n)
{
uint8_t *b = (uint8_t *)s;
for (int32_t i=n-1; i>=0; i--) {
if (b[i] == (uint8_t)c) {
return (void *)&b[i];
}
}
return nullptr;
}
#endif

View File

@ -0,0 +1,12 @@
/*
replacement functions for systems that are missing required library functions
*/
#pragma once
#include <AP_HAL/AP_HAL.h>
#ifndef HAVE_MEMRCHR
void *replace_memrchr(void *s, int c, size_t n);
#define memrchr(s,c,n) replace_memrchr(s,c,n)
#endif