From 5d413e0897fee7c2bf10d9ecc0860d3b399d66d5 Mon Sep 17 00:00:00 2001 From: Sitsofe Wheeler Date: Tue, 20 Mar 2018 10:46:32 +0000 Subject: [PATCH] oslib: make str* compat functions more uniform - Ensure there are CONFIG_ guards in the headers and .c files because sometime utilities include oslib headers directly and reference oslib .c files in the Makefile - Ensure all the oslib/str*.h files have redefinition guards - Shuffle some #include lines from the .h files to the .c ones - Ensure the .c files have #include ".h" in them so the compiler can check the declaration and definition match Signed-off-by: Sitsofe Wheeler --- oslib/strcasestr.c | 5 +++-- oslib/strcasestr.h | 7 ++----- oslib/strlcat.c | 4 ++++ oslib/strlcat.h | 4 ++++ oslib/strndup.c | 6 +++--- oslib/strndup.h | 9 +++++++-- oslib/strsep.c | 7 ++++++- oslib/strsep.h | 4 ++++ 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/oslib/strcasestr.c b/oslib/strcasestr.c index 26266091..5fa05fa1 100644 --- a/oslib/strcasestr.c +++ b/oslib/strcasestr.c @@ -1,7 +1,8 @@ +#ifndef CONFIG_STRCASESTR + #include #include - -#ifndef CONFIG_STRCASESTR +#include "strcasestr.h" char *strcasestr(const char *s1, const char *s2) { diff --git a/oslib/strcasestr.h b/oslib/strcasestr.h index 43d61df4..f13e929d 100644 --- a/oslib/strcasestr.h +++ b/oslib/strcasestr.h @@ -1,8 +1,4 @@ -#ifdef CONFIG_STRCASESTR - -#include - -#else +#ifndef CONFIG_STRCASESTR #ifndef FIO_STRCASESTR_H #define FIO_STRCASESTR_H @@ -10,4 +6,5 @@ char *strcasestr(const char *haystack, const char *needle); #endif + #endif diff --git a/oslib/strlcat.c b/oslib/strlcat.c index 3b33d0eb..6c4c6786 100644 --- a/oslib/strlcat.c +++ b/oslib/strlcat.c @@ -1,3 +1,5 @@ +#ifndef CONFIG_STRLCAT + #include #include "strlcat.h" @@ -22,3 +24,5 @@ size_t strlcat(char *dst, const char *src, size_t size) return dstlen + srclen; } + +#endif diff --git a/oslib/strlcat.h b/oslib/strlcat.h index 720034fe..f7663927 100644 --- a/oslib/strlcat.h +++ b/oslib/strlcat.h @@ -1,3 +1,5 @@ +#ifndef CONFIG_STRLCAT + #ifndef FIO_STRLCAT_H #define FIO_STRLCAT_H @@ -6,3 +8,5 @@ size_t strlcat(char *dst, const char *src, size_t size); #endif + +#endif diff --git a/oslib/strndup.c b/oslib/strndup.c index 40e92f82..657904ab 100644 --- a/oslib/strndup.c +++ b/oslib/strndup.c @@ -1,9 +1,9 @@ -#include +#ifndef CONFIG_HAVE_STRNDUP +#include +#include #include "strndup.h" -#ifndef CONFIG_HAVE_STRNDUP - char *strndup(const char *s, size_t n) { char *str = malloc(n + 1); diff --git a/oslib/strndup.h b/oslib/strndup.h index 2cb904da..2f41848e 100644 --- a/oslib/strndup.h +++ b/oslib/strndup.h @@ -1,7 +1,12 @@ -#include - #ifndef CONFIG_HAVE_STRNDUP +#ifndef FIO_STRNDUP_LIB_H +#define FIO_STRNDUP_LIB_H + +#include + char *strndup(const char *s, size_t n); #endif + +#endif diff --git a/oslib/strsep.c b/oslib/strsep.c index b71e9f7b..2d42ca0f 100644 --- a/oslib/strsep.c +++ b/oslib/strsep.c @@ -1,4 +1,7 @@ -#include +#ifndef CONFIG_STRSEP + +#include +#include "strsep.h" char *strsep(char **stringp, const char *delim) { @@ -27,3 +30,5 @@ char *strsep(char **stringp, const char *delim) } while (sc != 0); } while (1); } + +#endif diff --git a/oslib/strsep.h b/oslib/strsep.h index 5fea5d19..8cd9ada9 100644 --- a/oslib/strsep.h +++ b/oslib/strsep.h @@ -1,6 +1,10 @@ +#ifndef CONFIG_STRSEP + #ifndef FIO_STRSEP_LIB_H #define FIO_STRSEP_LIB_H char *strsep(char **, const char *); #endif + +#endif -- 2.25.1