extensions.h
Raw
1#ifndef EXTENSIONS_H
2#define EXTENSIONS_H
3
4#include <cutils/hedley.h>
5#include <errno.h>
6#include <stdlib.h>
7#include <cutils/backport.h>
8#include <string.h>
9#include <ctype.h>
10
11int strcmp_nocase(const char* s1, const char* s2);
12int strncmp_nocase(const char* s1, const char* s2, size_t n);
13
14HEDLEY_INLINE
15static void* reallocsafe(void *ptr, size_t nmemb, size_t size)
16{
17 size_t new_size = nmemb * size;
18
19 if(nmemb != 0 && new_size / nmemb != size)
20 {
21 errno = ENOMEM;
22 return NULL;
23 } else {
24 return realloc(ptr, new_size);
25 }
26}
27
28HEDLEY_INLINE
29static void* reallocsafe_inc(void *ptr, size_t nmemb, size_t size, size_t add)
30{
31 if(SIZE_MAX - add < size)
32 {
33 errno = ENOMEM;
34 return NULL;
35 } else {
36 return reallocsafe(ptr, nmemb, size+add);
37 }
38}
39
40
41
42#endif /* EXTENSIONS_H */
43