diff options
author | Jens Axboe <axboe@kernel.dk> | 2017-06-08 09:37:52 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2017-06-08 09:37:52 -0600 |
commit | b29c71c4a1e96390051d012b4e35c8d0718f7ce3 (patch) | |
tree | c3523c761932752bcbe37b6c1f635ed64f6c2e6a | |
parent | a1554f6519e7c91b262a35486d100d757b3b5b8a (diff) | |
download | fio-b29c71c4a1e96390051d012b4e35c8d0718f7ce3.tar.gz fio-b29c71c4a1e96390051d012b4e35c8d0718f7ce3.tar.bz2 |
Add strndup() function, if we don't have it
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | configure | 21 | ||||
-rw-r--r-- | lib/pattern.c | 1 | ||||
-rw-r--r-- | oslib/strndup.c | 18 | ||||
-rw-r--r-- | oslib/strndup.h | 9 |
5 files changed, 52 insertions, 0 deletions
@@ -107,6 +107,9 @@ endif ifndef CONFIG_STRLCAT SOURCE += oslib/strlcat.c endif +ifndef CONFIG_HAVE_STRNDUP + SOURCE += oslib/strndup.c +endif ifndef CONFIG_GETOPT_LONG_ONLY SOURCE += oslib/getopt_long.c endif @@ -1971,6 +1971,24 @@ fi print_config "bool" "$have_bool" ########################################## +# Check whether we have strndup() +cat > $TMPC << EOF +#include <string.h> +#include <stdlib.h> +int main(int argc, char **argv) +{ + char *res = strndup("test string", 8); + + free(res); + return 0; +} +EOF +if compile_prog "" "" "strndup"; then + strndup="yes" +fi +print_config "strndup" "$strndup" + +########################################## # check march=armv8-a+crc+crypto if test "$march_armv8_a_crc_crypto" != "yes" ; then march_armv8_a_crc_crypto="no" @@ -2227,6 +2245,9 @@ fi if test "$have_bool" = "yes" ; then output_sym "CONFIG_HAVE_BOOL" fi +if test "$strndup" = "yes" ; then + output_sym "CONFIG_HAVE_STRNDUP" +fi if test "$disable_opt" = "yes" ; then output_sym "CONFIG_DISABLE_OPTIMIZATIONS" fi diff --git a/lib/pattern.c b/lib/pattern.c index 420d74a9..31ee4eaf 100644 --- a/lib/pattern.c +++ b/lib/pattern.c @@ -13,6 +13,7 @@ #include "pattern.h" #include "../minmax.h" #include "../oslib/strcasestr.h" +#include "../oslib/strndup.h" /** * parse_file() - parses binary file to fill buffer diff --git a/oslib/strndup.c b/oslib/strndup.c new file mode 100644 index 00000000..318ca933 --- /dev/null +++ b/oslib/strndup.c @@ -0,0 +1,18 @@ +#include <stdlib.h> +#include <string.h> + +#ifndef CONFIG_HAVE_STRNDUP + +char *strndup(const char *s, size_t n) +{ + char *str = malloc(n + 1); + + if (str) { + strncpy(str, s, n); + str[n] = '\0'; + } + + return str; +} + +#endif diff --git a/oslib/strndup.h b/oslib/strndup.h new file mode 100644 index 00000000..669364e4 --- /dev/null +++ b/oslib/strndup.h @@ -0,0 +1,9 @@ +#ifdef CONFIG_HAVE_STRNDUP + +#include <string.h> + +#else + +char *strndup(const char *s, size_t n); + +#endif |