diff --git a/.clang-tidy b/.clang-tidy index 56961c92ce..52834b288f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -67,5 +67,6 @@ Checks: ' -readability-isolate-declaration, -readability-magic-numbers, -readability-named-parameter, + -readability-redundant-declaration, -readability-simplify-boolean-expr, -readability-suspicious-call-argument' diff --git a/src/addhead.cpp b/src/addhead.cpp index 76d2b2a229..bfcd5da2d7 100644 --- a/src/addhead.cpp +++ b/src/addhead.cpp @@ -34,7 +34,7 @@ //------------------------------------------------------------------- // Symbols //------------------------------------------------------------------- -#define ADD_HEAD_REGEX "reg:" +static constexpr char ADD_HEAD_REGEX[] = "reg:"; //------------------------------------------------------------------- // Class AdditionalHeader diff --git a/src/common.h b/src/common.h index 23d40a998e..1d04df058b 100644 --- a/src/common.h +++ b/src/common.h @@ -30,8 +30,8 @@ // Global variables //------------------------------------------------------------------- // TODO: namespace these -static const int64_t FIVE_GB = 5LL * 1024LL * 1024LL * 1024LL; -static const off_t MIN_MULTIPART_SIZE = 5 * 1024 * 1024; +static constexpr int64_t FIVE_GB = 5LL * 1024LL * 1024LL * 1024LL; +static constexpr off_t MIN_MULTIPART_SIZE = 5 * 1024 * 1024; extern bool foreground; extern bool nomultipart; diff --git a/src/curl.cpp b/src/curl.cpp index 846a5b23f6..75f4824718 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -45,14 +45,14 @@ //------------------------------------------------------------------- // Symbols //------------------------------------------------------------------- -static const char EMPTY_PAYLOAD_HASH[] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; -static const char EMPTY_MD5_BASE64_HASH[] = "1B2M2Y8AsgTpgAmY7PhCfg=="; +static constexpr char EMPTY_PAYLOAD_HASH[] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; +static constexpr char EMPTY_MD5_BASE64_HASH[] = "1B2M2Y8AsgTpgAmY7PhCfg=="; //------------------------------------------------------------------- // Class S3fsCurl //------------------------------------------------------------------- -static const int MULTIPART_SIZE = 10 * 1024 * 1024; -static const int GET_OBJECT_RESPONSE_LIMIT = 1024; +static constexpr int MULTIPART_SIZE = 10 * 1024 * 1024; +static constexpr int GET_OBJECT_RESPONSE_LIMIT = 1024; // [NOTE] about default mime.types file // If no mime.types file is specified in the mime option, s3fs @@ -65,8 +65,8 @@ static const int GET_OBJECT_RESPONSE_LIMIT = 1024; // If the mime.types file is not found, s3fs will exit with an // error. // -static const char DEFAULT_MIME_FILE[] = "/etc/mime.types"; -static const char SPECIAL_DARWIN_MIME_FILE[] = "/etc/apache2/mime.types"; +static constexpr char DEFAULT_MIME_FILE[] = "/etc/mime.types"; +static constexpr char SPECIAL_DARWIN_MIME_FILE[] = "/etc/apache2/mime.types"; // [NOTICE] // This symbol is for libcurl under 7.23.0 @@ -83,9 +83,6 @@ static const char SPECIAL_DARWIN_MIME_FILE[] = "/etc/apache2/mime.types"; //------------------------------------------------------------------- // Class S3fsCurl //------------------------------------------------------------------- -const long S3fsCurl::S3FSCURL_RESPONSECODE_NOTSET; -const long S3fsCurl::S3FSCURL_RESPONSECODE_FATAL_ERROR; -const int S3fsCurl::S3FSCURL_PERFORM_RESULT_NOTSET; pthread_mutex_t S3fsCurl::curl_warnings_lock; pthread_mutex_t S3fsCurl::curl_handles_lock; S3fsCurl::callback_locks_t S3fsCurl::callback_locks; diff --git a/src/curl.h b/src/curl.h index 61475b0c8f..dc8f28901c 100644 --- a/src/curl.h +++ b/src/curl.h @@ -193,9 +193,9 @@ class S3fsCurl CURLcode curlCode; // handle curl return public: - static const long S3FSCURL_RESPONSECODE_NOTSET = -1; - static const long S3FSCURL_RESPONSECODE_FATAL_ERROR = -2; - static const int S3FSCURL_PERFORM_RESULT_NOTSET = 1; + static constexpr long S3FSCURL_RESPONSECODE_NOTSET = -1; + static constexpr long S3FSCURL_RESPONSECODE_FATAL_ERROR = -2; + static constexpr int S3FSCURL_PERFORM_RESULT_NOTSET = 1; public: // constructor/destructor diff --git a/src/curl_util.cpp b/src/curl_util.cpp index 3b484d50c5..bfd02441fc 100644 --- a/src/curl_util.cpp +++ b/src/curl_util.cpp @@ -264,8 +264,8 @@ std::string url_to_host(const std::string &url) { S3FS_PRN_INFO3("url is %s", url.c_str()); - static const char HTTP[] = "http://"; - static const char HTTPS[] = "https://"; + static constexpr char HTTP[] = "http://"; + static constexpr char HTTPS[] = "https://"; std::string hostname; if (is_prefix(url.c_str(), HTTP)) { diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 5dd376d7cb..3754ed068d 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -38,7 +38,7 @@ // // The following symbols are used by FdManager::RawCheckAllCache(). // -#define CACHEDBG_FMT_DIR_PROB "Directory: %s" +// These must be #defines due to string literal concatenation. #define CACHEDBG_FMT_HEAD "---------------------------------------------------------------------------\n" \ "Check cache file and its stats file consistency at %s\n" \ "---------------------------------------------------------------------------" @@ -70,7 +70,7 @@ // This process may not be complete, but it is easy way can // be realized. // -#define NOCACHE_PATH_PREFIX_FORM " __S3FS_UNEXISTED_PATH_%lx__ / " // important space words for simply +static constexpr char NOCACHE_PATH_PREFIX_FORM[] = " __S3FS_UNEXISTED_PATH_%lx__ / "; // important space words for simply //------------------------------------------------ // FdManager class variable diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index 1de87262b8..3ec154a1bb 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -41,7 +41,7 @@ //------------------------------------------------ // Symbols //------------------------------------------------ -static const int MAX_MULTIPART_CNT = 10 * 1000; // S3 multipart max count +static constexpr int MAX_MULTIPART_CNT = 10 * 1000; // S3 multipart max count //------------------------------------------------ // FdEntity class variables diff --git a/src/fdcache_page.cpp b/src/fdcache_page.cpp index f9a43f7fe7..f5b50ef0b3 100644 --- a/src/fdcache_page.cpp +++ b/src/fdcache_page.cpp @@ -34,7 +34,7 @@ //------------------------------------------------ // Symbols //------------------------------------------------ -static const int CHECK_CACHEFILE_PART_SIZE = 1024 * 16; // Buffer size in PageList::CheckZeroAreaInFile() +static constexpr int CHECK_CACHEFILE_PART_SIZE = 1024 * 16; // Buffer size in PageList::CheckZeroAreaInFile() //------------------------------------------------ // fdpage_list_t utility diff --git a/src/fdcache_pseudofd.cpp b/src/fdcache_pseudofd.cpp index 8a15d3ee00..711cadaf25 100644 --- a/src/fdcache_pseudofd.cpp +++ b/src/fdcache_pseudofd.cpp @@ -33,7 +33,7 @@ // The minimum pseudo fd value starts 2. // This is to avoid mistakes for 0(stdout) and 1(stderr), which are usually used. // -static const int MIN_PSEUDOFD_NUMBER = 2; +static constexpr int MIN_PSEUDOFD_NUMBER = 2; //------------------------------------------------ // PseudoFdManager class methods diff --git a/src/gnutls_auth.cpp b/src/gnutls_auth.cpp index 1c5228c469..c0ef0dc572 100644 --- a/src/gnutls_auth.cpp +++ b/src/gnutls_auth.cpp @@ -50,7 +50,7 @@ const char* s3fs_crypt_lib_name(void) { - static const char version[] = "GnuTLS(nettle)"; + static constexpr char version[] = "GnuTLS(nettle)"; return version; } @@ -59,7 +59,7 @@ const char* s3fs_crypt_lib_name(void) const char* s3fs_crypt_lib_name() { - static const char version[] = "GnuTLS(gcrypt)"; + static constexpr char version[] = "GnuTLS(gcrypt)"; return version; } diff --git a/src/metaheader.cpp b/src/metaheader.cpp index 571dd6ede4..69e97e821f 100644 --- a/src/metaheader.cpp +++ b/src/metaheader.cpp @@ -27,7 +27,7 @@ #include "metaheader.h" #include "string_util.h" -static const struct timespec DEFAULT_TIMESPEC = {-1, 0}; +static constexpr struct timespec DEFAULT_TIMESPEC = {-1, 0}; //------------------------------------------------------------------- // Utility functions for convert diff --git a/src/nss_auth.cpp b/src/nss_auth.cpp index 106cd41ef7..e58ea0faed 100644 --- a/src/nss_auth.cpp +++ b/src/nss_auth.cpp @@ -44,7 +44,7 @@ //------------------------------------------------------------------- const char* s3fs_crypt_lib_name() { - static const char version[] = "NSS"; + static constexpr char version[] = "NSS"; return version; } diff --git a/src/openssl_auth.cpp b/src/openssl_auth.cpp index 39e6aba56e..5340a9719e 100644 --- a/src/openssl_auth.cpp +++ b/src/openssl_auth.cpp @@ -44,7 +44,7 @@ //------------------------------------------------------------------- const char* s3fs_crypt_lib_name() { - static const char version[] = "OpenSSL"; + static constexpr char version[] = "OpenSSL"; return version; } diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 9d34205832..0668c8e68d 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -5540,7 +5540,7 @@ int main(int argc, char* argv[]) time_t incomp_abort_time = (24 * 60 * 60); S3fsLog singletonLog; - static const struct option long_opts[] = { + static constexpr struct option long_opts[] = { {"help", no_argument, nullptr, 'h'}, {"version", no_argument, nullptr, 0}, {"debug", no_argument, nullptr, 'd'}, diff --git a/src/s3fs_cred.cpp b/src/s3fs_cred.cpp index b9c185182f..a51e0c26d6 100644 --- a/src/s3fs_cred.cpp +++ b/src/s3fs_cred.cpp @@ -38,7 +38,7 @@ //------------------------------------------------------------------- // Symbols //------------------------------------------------------------------- -#define DEFAULT_AWS_PROFILE_NAME "default" +static constexpr char DEFAULT_AWS_PROFILE_NAME[] = "default"; //------------------------------------------------------------------- // External Credential dummy function @@ -53,8 +53,8 @@ // const char* VersionS3fsCredential(bool detail) { - static const char version[] = "built-in"; - static const char detail_version[] = + static constexpr char version[] = "built-in"; + static constexpr char detail_version[] = "s3fs-fuse built-in Credential I/F Function\n" "Copyright(C) 2007 s3fs-fuse\n"; @@ -113,21 +113,19 @@ bool UpdateS3fsCredential(char** ppaccess_key_id, char** ppserect_access_key, ch //------------------------------------------------------------------- // Class Variables //------------------------------------------------------------------- -const char* S3fsCred::ALLBUCKET_FIELDS_TYPE = ""; -const char* S3fsCred::KEYVAL_FIELDS_TYPE = "\t"; -const char* S3fsCred::AWS_ACCESSKEYID = "AWSAccessKeyId"; -const char* S3fsCred::AWS_SECRETKEY = "AWSSecretKey"; - -const int S3fsCred::IAM_EXPIRE_MERGIN = 20 * 60; // update timing -const char* S3fsCred::ECS_IAM_ENV_VAR = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"; -const char* S3fsCred::IAMCRED_ACCESSKEYID = "AccessKeyId"; -const char* S3fsCred::IAMCRED_SECRETACCESSKEY = "SecretAccessKey"; -const char* S3fsCred::IAMCRED_ROLEARN = "RoleArn"; - -const char* S3fsCred::IAMv2_token_url = "http://169.254.169.254/latest/api/token"; -int S3fsCred::IAMv2_token_ttl = 21600; -const char* S3fsCred::IAMv2_token_ttl_hdr = "X-aws-ec2-metadata-token-ttl-seconds"; -const char* S3fsCred::IAMv2_token_hdr = "X-aws-ec2-metadata-token"; +constexpr char S3fsCred::ALLBUCKET_FIELDS_TYPE[]; +constexpr char S3fsCred::KEYVAL_FIELDS_TYPE[]; +constexpr char S3fsCred::AWS_ACCESSKEYID[]; +constexpr char S3fsCred::AWS_SECRETKEY[]; + +constexpr char S3fsCred::ECS_IAM_ENV_VAR[]; +constexpr char S3fsCred::IAMCRED_ACCESSKEYID[]; +constexpr char S3fsCred::IAMCRED_SECRETACCESSKEY[]; +constexpr char S3fsCred::IAMCRED_ROLEARN[]; + +constexpr char S3fsCred::IAMv2_token_url[]; +constexpr char S3fsCred::IAMv2_token_ttl_hdr[]; +constexpr char S3fsCred::IAMv2_token_hdr[]; std::string S3fsCred::bucket_name; @@ -1186,7 +1184,7 @@ bool S3fsCred::CheckIAMCredentialUpdate(std::string* access_key_id, std::string* const char* S3fsCred::GetCredFuncVersion(bool detail) const { - static const char errVersion[] = "unknown"; + static constexpr char errVersion[] = "unknown"; if(!pFuncCredVersion){ return errVersion; diff --git a/src/s3fs_cred.h b/src/s3fs_cred.h index 7fe6dfd57a..845a1f3781 100644 --- a/src/s3fs_cred.h +++ b/src/s3fs_cred.h @@ -40,16 +40,16 @@ typedef std::map iamcredmap_t; class S3fsCred { private: - static const char* ALLBUCKET_FIELDS_TYPE; // special key for mapping(This name is absolutely not used as a bucket name) - static const char* KEYVAL_FIELDS_TYPE; // special key for mapping(This name is absolutely not used as a bucket name) - static const char* AWS_ACCESSKEYID; - static const char* AWS_SECRETKEY; + static constexpr char ALLBUCKET_FIELDS_TYPE[] = ""; // special key for mapping(This name is absolutely not used as a bucket name) + static constexpr char KEYVAL_FIELDS_TYPE[] = "\t"; // special key for mapping(This name is absolutely not used as a bucket name) + static constexpr char AWS_ACCESSKEYID[] = "AWSAccessKeyId"; + static constexpr char AWS_SECRETKEY[] = "AWSSecretKey"; - static const int IAM_EXPIRE_MERGIN; - static const char* ECS_IAM_ENV_VAR; - static const char* IAMCRED_ACCESSKEYID; - static const char* IAMCRED_SECRETACCESSKEY; - static const char* IAMCRED_ROLEARN; + static constexpr int IAM_EXPIRE_MERGIN = 20 * 60; // update timing + static constexpr char ECS_IAM_ENV_VAR[] = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"; + static constexpr char IAMCRED_ACCESSKEYID[] = "AccessKeyId"; + static constexpr char IAMCRED_SECRETACCESSKEY[] = "SecretAccessKey"; + static constexpr char IAMCRED_ROLEARN[] = "RoleArn"; static std::string bucket_name; @@ -89,10 +89,10 @@ class S3fsCred fp_UpdateS3fsCredential pFuncCredUpdate; public: - static const char* IAMv2_token_url; - static int IAMv2_token_ttl; - static const char* IAMv2_token_ttl_hdr; - static const char* IAMv2_token_hdr; + static constexpr char IAMv2_token_url[] = "http://169.254.169.254/latest/api/token"; + static constexpr int IAMv2_token_ttl = 21600; + static constexpr char IAMv2_token_ttl_hdr[] = "X-aws-ec2-metadata-token-ttl-seconds"; + static constexpr char IAMv2_token_hdr[] = "X-aws-ec2-metadata-token"; private: static bool ParseIAMRoleFromMetaDataResponse(const char* response, std::string& rolename); diff --git a/src/s3fs_help.cpp b/src/s3fs_help.cpp index 678d8fb073..bf2bad56a3 100644 --- a/src/s3fs_help.cpp +++ b/src/s3fs_help.cpp @@ -29,7 +29,7 @@ //------------------------------------------------------------------- // Contents //------------------------------------------------------------------- -static const char help_string[] = +static constexpr char help_string[] = "\n" "Mount an Amazon S3 bucket as a file system.\n" "\n" @@ -638,7 +638,7 @@ void show_version() const char* short_version() { - static const char short_ver[] = "s3fs version " VERSION "(" COMMIT_HASH_VAL ")"; + static constexpr char short_ver[] = "s3fs version " VERSION "(" COMMIT_HASH_VAL ")"; return short_ver; } diff --git a/src/s3fs_logger.cpp b/src/s3fs_logger.cpp index 485a8d464f..12b93cbdc9 100644 --- a/src/s3fs_logger.cpp +++ b/src/s3fs_logger.cpp @@ -30,10 +30,9 @@ //------------------------------------------------------------------- // S3fsLog class : variables //------------------------------------------------------------------- -const int S3fsLog::NEST_MAX; -const char* const S3fsLog::nest_spaces[S3fsLog::NEST_MAX] = {"", " ", " ", " "}; -const char S3fsLog::LOGFILEENV[] = "S3FS_LOGFILE"; -const char S3fsLog::MSGTIMESTAMP[] = "S3FS_MSGTIMESTAMP"; +constexpr char S3fsLog::LOGFILEENV[]; +constexpr const char* S3fsLog::nest_spaces[]; +constexpr char S3fsLog::MSGTIMESTAMP[]; S3fsLog* S3fsLog::pSingleton = nullptr; S3fsLog::s3fs_log_level S3fsLog::debug_level = S3fsLog::LEVEL_CRIT; FILE* S3fsLog::logfp = nullptr; diff --git a/src/s3fs_logger.h b/src/s3fs_logger.h index edd3a49f9e..750169fa39 100644 --- a/src/s3fs_logger.h +++ b/src/s3fs_logger.h @@ -51,10 +51,10 @@ class S3fsLog }; protected: - static const int NEST_MAX = 4; - static const char* const nest_spaces[NEST_MAX]; - static const char LOGFILEENV[]; - static const char MSGTIMESTAMP[]; + static constexpr int NEST_MAX = 4; + static constexpr const char* nest_spaces[NEST_MAX] = {"", " ", " ", " "}; + static constexpr char LOGFILEENV[] = "S3FS_LOGFILE"; + static constexpr char MSGTIMESTAMP[] = "S3FS_MSGTIMESTAMP"; static S3fsLog* pSingleton; static s3fs_log_level debug_level; @@ -76,7 +76,7 @@ class S3fsLog static bool IsS3fsLogInfo() { return IsS3fsLogLevel(LEVEL_INFO); } static bool IsS3fsLogDbg() { return IsS3fsLogLevel(LEVEL_DBG); } - static int GetSyslogLevel(s3fs_log_level level) + static constexpr int GetSyslogLevel(s3fs_log_level level) { return ( LEVEL_DBG == (level & LEVEL_DBG) ? LOG_DEBUG : LEVEL_INFO == (level & LEVEL_DBG) ? LOG_INFO : @@ -86,7 +86,7 @@ class S3fsLog static std::string GetCurrentTime(); - static const char* GetLevelString(s3fs_log_level level) + static constexpr const char* GetLevelString(s3fs_log_level level) { return ( LEVEL_DBG == (level & LEVEL_DBG) ? "[DBG] " : LEVEL_INFO == (level & LEVEL_DBG) ? "[INF] " : @@ -94,13 +94,9 @@ class S3fsLog LEVEL_ERR == (level & LEVEL_DBG) ? "[ERR] " : "[CRT] " ); } - static const char* GetS3fsLogNest(int nest) + static constexpr const char* GetS3fsLogNest(int nest) { - if(nest < NEST_MAX){ - return nest_spaces[nest]; - }else{ - return nest_spaces[NEST_MAX - 1]; - } + return nest_spaces[nest < NEST_MAX ? nest : NEST_MAX - 1]; } static bool IsSetLogFile() diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index c6a5ecad0b..1b7d4519b2 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -444,11 +444,6 @@ void print_launch_message(int argc, char** argv) S3FS_PRN_LAUNCH_INFO("%s", message.c_str()); } -//------------------------------------------------------------------- -// Utility for nanosecond time(timespec) -//------------------------------------------------------------------- -const struct timespec S3FS_OMIT_TS = {0, UTIME_OMIT}; - // // result: -1 ts1 < ts2 // 0 ts1 == ts2 diff --git a/src/s3fs_util.h b/src/s3fs_util.h index b83d15b08c..14a525dcd3 100644 --- a/src/s3fs_util.h +++ b/src/s3fs_util.h @@ -66,7 +66,11 @@ enum class stat_time_type{ MTIME, CTIME }; -extern const struct timespec S3FS_OMIT_TS; + +//------------------------------------------------------------------- +// Utility for nanosecond time(timespec) +//------------------------------------------------------------------- +static constexpr struct timespec S3FS_OMIT_TS = {0, UTIME_OMIT}; int compare_timespec(const struct timespec& ts1, const struct timespec& ts2); int compare_timespec(const struct stat& st, stat_time_type type, const struct timespec& ts); diff --git a/src/s3fs_xml.cpp b/src/s3fs_xml.cpp index 2c0a60b008..3d25da9f18 100644 --- a/src/s3fs_xml.cpp +++ b/src/s3fs_xml.cpp @@ -34,7 +34,7 @@ //------------------------------------------------------------------- // Variables //------------------------------------------------------------------- -static const char c_strErrorObjectName[] = "FILE or SUBDIR in DIR"; +static constexpr char c_strErrorObjectName[] = "FILE or SUBDIR in DIR"; // [NOTE] // mutex for static variables in GetXmlNsUrl diff --git a/src/string_util.cpp b/src/string_util.cpp index 8277074bff..a1ab4cd4c9 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -32,7 +32,6 @@ //------------------------------------------------------------------- // Global variables //------------------------------------------------------------------- -const char SPACES[] = " \t\r\n"; //------------------------------------------------------------------- // Functions @@ -147,9 +146,9 @@ std::string peeloff(std::string s) // Therefore, it is a function to use as URL encoding // for use in query strings. // -static const char* encode_general_except_chars = ".-_~"; // For general URL encode -static const char* encode_path_except_chars = ".-_~/"; // For fuse(included path) URL encode -static const char* encode_query_except_chars = ".-_~=&%"; // For query params(and encoded string) +static constexpr char encode_general_except_chars[] = ".-_~"; // For general URL encode +static constexpr char encode_path_except_chars[] = ".-_~/"; // For fuse(included path) URL encode +static constexpr char encode_query_except_chars[] = ".-_~=&%"; // For query params(and encoded string) static std::string rawUrlEncode(const std::string &s, const char* except_chars) { @@ -381,7 +380,7 @@ std::string s3fs_hex_upper(const unsigned char* input, size_t length) std::string s3fs_base64(const unsigned char* input, size_t length) { - static const char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + static constexpr char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; std::string result; result.reserve(((length + 3 - 1) / 3) * 4 + 1); @@ -460,7 +459,7 @@ std::string s3fs_decode64(const char* input, size_t input_len) // Base location for transform. The range 0xE000 - 0xF8ff // is a private range, se use the start of this range. -static const unsigned int escape_base = 0xe000; +static constexpr unsigned int escape_base = 0xe000; // encode bytes into wobbly utf8. // 'result' can be null. returns true if transform was needed. diff --git a/src/string_util.h b/src/string_util.h index 34cdbb14d7..2577d49461 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -30,7 +30,7 @@ //------------------------------------------------------------------- // Global variables //------------------------------------------------------------------- -extern const char SPACES[]; +static constexpr char SPACES[] = " \t\r\n"; //------------------------------------------------------------------- // Inline functions diff --git a/test/mknod_test.cc b/test/mknod_test.cc index fc7137f53f..3b31edb8a9 100644 --- a/test/mknod_test.cc +++ b/test/mknod_test.cc @@ -34,27 +34,27 @@ //--------------------------------------------------------- // Const //--------------------------------------------------------- -const char usage_string[] = "Usage : \"mknod_test \""; +static constexpr char usage_string[] = "Usage : \"mknod_test \""; -const char str_mode_reg[] = "REGULAR"; -const char str_mode_chr[] = "CHARACTER"; -const char str_mode_blk[] = "BLOCK"; -const char str_mode_fifo[] = "FIFO"; -const char str_mode_sock[] = "SOCK"; +static constexpr char str_mode_reg[] = "REGULAR"; +static constexpr char str_mode_chr[] = "CHARACTER"; +static constexpr char str_mode_blk[] = "BLOCK"; +static constexpr char str_mode_fifo[] = "FIFO"; +static constexpr char str_mode_sock[] = "SOCK"; -const char str_ext_reg[] = "reg"; -const char str_ext_chr[] = "chr"; -const char str_ext_blk[] = "blk"; -const char str_ext_fifo[] = "fifo"; -const char str_ext_sock[] = "sock"; +static constexpr char str_ext_reg[] = "reg"; +static constexpr char str_ext_chr[] = "chr"; +static constexpr char str_ext_blk[] = "blk"; +static constexpr char str_ext_fifo[] = "fifo"; +static constexpr char str_ext_sock[] = "sock"; // [NOTE] // It would be nice if PATH_MAX could be used as is, but since there are // issues using on Linux and we also must support for macos, this simple // test program defines a fixed value for simplicity. // -static const size_t S3FS_TEST_PATH_MAX = 255; -static const size_t MAX_BASE_PATH_LENGTH = S3FS_TEST_PATH_MAX - 5; +static constexpr size_t S3FS_TEST_PATH_MAX = 255; +static constexpr size_t MAX_BASE_PATH_LENGTH = S3FS_TEST_PATH_MAX - 5; //--------------------------------------------------------- // Test function diff --git a/test/write_multiblock.cc b/test/write_multiblock.cc index dacbe6e651..a6e4300e7f 100644 --- a/test/write_multiblock.cc +++ b/test/write_multiblock.cc @@ -49,7 +49,7 @@ typedef std::list strlist_t; //--------------------------------------------------------- // Const //--------------------------------------------------------- -const char usage_string[] = "Usage : \"write_multiblock -f -p \" (allows -f and -p multiple times.)"; +static constexpr char usage_string[] = "Usage : \"write_multiblock -f -p \" (allows -f and -p multiple times.)"; //--------------------------------------------------------- // Utility functions