Support GCC 8.x and support static compile

This commit is contained in:
Nick Peng
2019-06-16 17:17:48 +08:00
parent a09e63d333
commit 3ef325d75d
15 changed files with 124 additions and 64 deletions

23
src/include/stringutil.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef _GENERIC_STRING_UITL_H
#define _GENERIC_STRING_UITL_H
#include <stddef.h>
#include <string.h>
static inline char *safe_strncpy(char *dest, const char *src, size_t n)
{
#if __GNUC__ > 7
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif
char *ret = strncpy(dest, src, n - 1);
if (n > 0) {
dest[n - 1] = '\0';
}
#if __GNUC__ > 7
#pragma GCC diagnostic pop
#endif
return ret;
}
#endif