AP_HAL: added replacement for memrchr()
This commit is contained in:
parent
bdacc410ca
commit
8907506c18
22
libraries/AP_HAL/utility/replace.cpp
Normal file
22
libraries/AP_HAL/utility/replace.cpp
Normal 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
|
12
libraries/AP_HAL/utility/replace.h
Normal file
12
libraries/AP_HAL/utility/replace.h
Normal 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
|
Loading…
Reference in New Issue
Block a user