diff --git a/src/Makefile.am b/src/Makefile.am index a3d47ce..78af0a9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,9 +63,6 @@ endif if USE_SSL_NSS s3fs_SOURCES += nss_auth.cpp endif -if MSYS - s3fs_SOURCES += strptime.cpp -endif s3fs_LDADD = $(DEPS_LIBS) @@ -84,9 +81,6 @@ endif if USE_SSL_NSS test_curl_util_SOURCES += nss_auth.cpp endif -if MSYS - test_curl_util_SOURCES += strptime.cpp -endif test_curl_util_LDADD = $(DEPS_LIBS) @@ -96,14 +90,8 @@ test_page_list_SOURCES = \ s3fs_logger.cpp \ string_util.cpp \ test_page_list.cpp -if MSYS - test_page_list_SOURCES += strptime.cpp -endif test_string_util_SOURCES = string_util.cpp test_string_util.cpp s3fs_logger.cpp -if MSYS - test_string_util_SOURCES += strptime.cpp -endif TESTS = \ test_curl_util \ diff --git a/src/metaheader.cpp b/src/metaheader.cpp index bdf533a..19b236c 100644 --- a/src/metaheader.cpp +++ b/src/metaheader.cpp @@ -28,11 +28,6 @@ #include "metaheader.h" #include "string_util.h" -// Use the polyfill in MSYS2 environment -#ifdef __MSYS__ -#include "strptime.h" -#endif - //------------------------------------------------------------------- // Utility functions for convert //------------------------------------------------------------------- diff --git a/src/string_util.cpp b/src/string_util.cpp index 9bb674b..b0e4d6c 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -32,11 +32,6 @@ #include "s3fs.h" #include "string_util.h" -// Use the polyfill in MSYS2 environment -#ifdef __MSYS__ -#include "strptime.h" -#endif - //------------------------------------------------------------------- // Global variables //------------------------------------------------------------------- @@ -74,6 +69,24 @@ template<> std::string str(struct timespec value) { // Functions //------------------------------------------------------------------- +#ifdef __MSYS__ +/* + * Polyfill for strptime function + * + * This source code is from https://gist.github.com/jeremyfromearth/5694aa3a66714254752179ecf3c95582 . + */ +char* strptime(const char* s, const char* f, struct tm* tm) +{ + std::istringstream input(s); + input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input >> std::get_time(tm, f); + if (input.fail()) { + return nullptr; + } + return (char*)(s + input.tellg()); +} +#endif + bool s3fs_strtoofft(off_t* value, const char* str, int base) { if(value == NULL || str == NULL){ diff --git a/src/string_util.h b/src/string_util.h index e5c857e..54c629a 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -54,6 +54,12 @@ template std::string str(T value); //------------------------------------------------------------------- // Utilities //------------------------------------------------------------------- +#ifdef __MSYS__ +// +// Polyfill for strptime function. +// +char* strptime(const char* s, const char* f, struct tm* tm); +#endif // // Convert string to off_t. Returns false on bad input. // Replacement for C++11 std::stoll. diff --git a/src/strptime.cpp b/src/strptime.cpp deleted file mode 100644 index e923ee4..0000000 --- a/src/strptime.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Polyfill for strptime function - * - * This source code is from https://gist.github.com/jeremyfromearth/5694aa3a66714254752179ecf3c95582 . - */ - -#include -#include -#include -#include - -#include "strptime.h" - -char* strptime(const char* s, const char* f, struct tm* tm) -{ - std::istringstream input(s); - input.imbue(std::locale(setlocale(LC_ALL, nullptr))); - input >> std::get_time(tm, f); - if (input.fail()) { - return nullptr; - } - return (char*)(s + input.tellg()); -} diff --git a/src/strptime.h b/src/strptime.h deleted file mode 100644 index 1ca97db..0000000 --- a/src/strptime.h +++ /dev/null @@ -1,50 +0,0 @@ - -/* - * Polyfill for strptime function - * - * This source code is from musl library, located at https://git.musl-libc.org/cgit/musl/tree/src/time/strptime.c . - */ - -/* - * musl as a whole is licensed under the following standard MIT license: - * - * ---------------------------------------------------------------------- - * Copyright © 2005-2020 Rich Felker, et al. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * ---------------------------------------------------------------------- - */ - -#ifndef S3FS_STRPTIME_H_ -#define S3FS_STRPTIME_H_ - -#include -#include -#include -#include -#include -#include -#include - -#include "common.h" - -char* strptime(const char* s, const char* f, struct tm* tm); - -#endif