Use C++11 nullptr instead of 0 or NULL (#2234)

This improves type-safety.
This commit is contained in:
Andrew Gaul 2023-07-27 21:56:58 +09:00 committed by GitHub
parent 0ece204393
commit a4a2841c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 537 additions and 538 deletions

View File

@ -26,11 +26,11 @@ Checks: '
-modernize-avoid-c-arrays,
-modernize-deprecated-headers,
-modernize-loop-convert,
-modernize-make-unique,
-modernize-raw-string-literal,
-modernize-return-braced-init-list,
-modernize-use-auto,
-modernize-use-emplace,
-modernize-use-nullptr,
-modernize-use-trailing-return-type,
-modernize-use-using,
performance-*,

View File

@ -65,7 +65,7 @@ AdditionalHeader::~AdditionalHeader()
bool AdditionalHeader::Load(const char* file)
{
if(!file){
S3FS_PRN_WARN("file is NULL.");
S3FS_PRN_WARN("file is nullptr.");
return false;
}
Unload();
@ -165,7 +165,7 @@ bool AdditionalHeader::AddHeader(headers_t& meta, const char* path) const
return true;
}
if(!path){
S3FS_PRN_WARN("path is NULL.");
S3FS_PRN_WARN("path is nullptr.");
return false;
}

View File

@ -36,7 +36,7 @@ typedef struct add_header{
}
}
std::unique_ptr<regex_t> pregex; // not NULL means using regex, NULL means comparing suffix directly.
std::unique_ptr<regex_t> pregex; // not nullptr means using regex, nullptr means comparing suffix directly.
std::string basestring;
std::string headkey;
std::string headvalue;

View File

@ -63,10 +63,10 @@ bool BodyData::Resize(size_t addbytes)
}
// realloc
char* newtext;
if(NULL == (newtext = reinterpret_cast<char*>(realloc(text, (bufsize + need_size))))){
S3FS_PRN_CRIT("not enough memory (realloc returned NULL)");
if(nullptr == (newtext = reinterpret_cast<char*>(realloc(text, (bufsize + need_size))))){
S3FS_PRN_CRIT("not enough memory (realloc returned nullptr)");
free(text);
text = NULL;
text = nullptr;
return false;
}
text = newtext;
@ -79,7 +79,7 @@ void BodyData::Clear()
{
if(text){
free(text);
text = NULL;
text = nullptr;
}
lastpos = 0;
bufsize = 0;

View File

@ -41,7 +41,7 @@ class BodyData
bool Resize(size_t addbytes);
public:
BodyData() : text(NULL), lastpos(0), bufsize(0) {}
BodyData() : text(nullptr), lastpos(0), bufsize(0) {}
~BodyData()
{
Clear();

View File

@ -264,13 +264,13 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met
S3FS_PRN_DBG("stat cache hit [path=%s][time=%lld.%09ld][hit count=%lu]",
strpath.c_str(), static_cast<long long>(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count);
if(pst!= NULL){
if(pst!= nullptr){
*pst= ent->stbuf;
}
if(meta != NULL){
if(meta != nullptr){
*meta = ent->meta;
}
if(pisforce != NULL){
if(pisforce != nullptr){
(*pisforce) = ent->isforce;
}
ent->hit_count++;

View File

@ -133,29 +133,29 @@ class StatCache
}
// Get stat cache
bool GetStat(const std::string& key, struct stat* pst, headers_t* meta, bool overcheck = true, bool* pisforce = NULL)
bool GetStat(const std::string& key, struct stat* pst, headers_t* meta, bool overcheck = true, bool* pisforce = nullptr)
{
return GetStat(key, pst, meta, overcheck, NULL, pisforce);
return GetStat(key, pst, meta, overcheck, nullptr, pisforce);
}
bool GetStat(const std::string& key, struct stat* pst, bool overcheck = true)
{
return GetStat(key, pst, NULL, overcheck, NULL, NULL);
return GetStat(key, pst, nullptr, overcheck, nullptr, nullptr);
}
bool GetStat(const std::string& key, headers_t* meta, bool overcheck = true)
{
return GetStat(key, NULL, meta, overcheck, NULL, NULL);
return GetStat(key, nullptr, meta, overcheck, nullptr, nullptr);
}
bool HasStat(const std::string& key, bool overcheck = true)
{
return GetStat(key, NULL, NULL, overcheck, NULL, NULL);
return GetStat(key, nullptr, nullptr, overcheck, nullptr, nullptr);
}
bool HasStat(const std::string& key, const char* etag, bool overcheck = true)
{
return GetStat(key, NULL, NULL, overcheck, etag, NULL);
return GetStat(key, nullptr, nullptr, overcheck, etag, nullptr);
}
bool HasStat(const std::string& key, struct stat* pst, const char* etag)
{
return GetStat(key, pst, NULL, true, etag, NULL);
return GetStat(key, pst, nullptr, true, etag, nullptr);
}
// Cache For no object

View File

@ -33,10 +33,10 @@ std::string s3fs_get_content_md5(int fd)
char* base64;
std::string Signature;
if(NULL == (md5 = s3fs_md5_fd(fd, 0, -1))){
if(nullptr == (md5 = s3fs_md5_fd(fd, 0, -1))){
return std::string("");
}
if(NULL == (base64 = s3fs_base64(md5, get_md5_digest_length()))){
if(nullptr == (base64 = s3fs_base64(md5, get_md5_digest_length()))){
delete[] md5;
return std::string(""); // ENOMEM
}
@ -53,7 +53,7 @@ std::string s3fs_sha256_hex_fd(int fd, off_t start, off_t size)
size_t digestlen = get_sha256_digest_length();
unsigned char* sha256;
if(NULL == (sha256 = s3fs_sha256_fd(fd, start, size))){
if(nullptr == (sha256 = s3fs_sha256_fd(fd, start, size))){
return std::string("");
}

View File

@ -84,9 +84,9 @@ pthread_mutex_t S3fsCurl::curl_warnings_lock;
pthread_mutex_t S3fsCurl::curl_handles_lock;
S3fsCurl::callback_locks_t S3fsCurl::callback_locks;
bool S3fsCurl::is_initglobal_done = false;
CurlHandlerPool* S3fsCurl::sCurlPool = NULL;
CurlHandlerPool* S3fsCurl::sCurlPool = nullptr;
int S3fsCurl::sCurlPoolSize = 32;
CURLSH* S3fsCurl::hCurlShare = NULL;
CURLSH* S3fsCurl::hCurlShare = nullptr;
bool S3fsCurl::is_cert_check = true; // default
bool S3fsCurl::is_dns_cache = true; // default
bool S3fsCurl::is_ssl_session_cache= true; // default
@ -102,7 +102,7 @@ sse_type_t S3fsCurl::ssetype = sse_type_t::SSE_DISABLE;
bool S3fsCurl::is_content_md5 = false;
bool S3fsCurl::is_verbose = false;
bool S3fsCurl::is_dump_body = false;
S3fsCred* S3fsCurl::ps3fscred = NULL;
S3fsCred* S3fsCurl::ps3fscred = nullptr;
long S3fsCurl::ssl_verify_hostname = 1; // default(original code...)
// protected by curl_warnings_lock
@ -183,7 +183,7 @@ bool S3fsCurl::DestroyS3fsCurl()
result = false;
}
delete sCurlPool;
sCurlPool = NULL;
sCurlPool = nullptr;
if(!S3fsCurl::DestroyShareCurl()){
result = false;
}
@ -240,7 +240,7 @@ bool S3fsCurl::InitShareCurl()
S3FS_PRN_WARN("already initiated.");
return false;
}
if(NULL == (S3fsCurl::hCurlShare = curl_share_init())){
if(nullptr == (S3fsCurl::hCurlShare = curl_share_init())){
S3FS_PRN_ERR("curl_share_init failed");
return false;
}
@ -289,7 +289,7 @@ bool S3fsCurl::DestroyShareCurl()
if(CURLSHE_OK != curl_share_cleanup(S3fsCurl::hCurlShare)){
return false;
}
S3fsCurl::hCurlShare = NULL;
S3fsCurl::hCurlShare = nullptr;
return true;
}
@ -347,7 +347,7 @@ bool S3fsCurl::DestroyCryptMutex()
int S3fsCurl::CurlProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
CURL* curl = static_cast<CURL*>(clientp);
time_t now = time(0);
time_t now = time(nullptr);
progress_t p(dlnow, ulnow);
AutoLock lock(&S3fsCurl::curl_handles_lock);
@ -519,7 +519,7 @@ bool S3fsCurl::LocateBundle()
// curl_ca_bundle variable to it
if(S3fsCurl::curl_ca_bundle.empty()){
char* CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE");
if(CURL_CA_BUNDLE != NULL) {
if(CURL_CA_BUNDLE != nullptr) {
// check for existence and readability of the file
std::ifstream BF(CURL_CA_BUNDLE);
if(!BF.good()){
@ -800,7 +800,7 @@ bool S3fsCurl::PushbackSseKeys(const std::string& input)
char* p_key;
size_t keylength;
if(NULL != (p_key = reinterpret_cast<char*>(s3fs_decode64(onekey.c_str(), onekey.size(), &keylength)))) {
if(nullptr != (p_key = reinterpret_cast<char*>(s3fs_decode64(onekey.c_str(), onekey.size(), &keylength)))) {
raw_key = std::string(p_key, keylength);
base64_key = onekey;
delete[] p_key;
@ -811,7 +811,7 @@ bool S3fsCurl::PushbackSseKeys(const std::string& input)
} else {
char* pbase64_key;
if(NULL != (pbase64_key = s3fs_base64(reinterpret_cast<const unsigned char*>(onekey.c_str()), onekey.length()))) {
if(nullptr != (pbase64_key = s3fs_base64(reinterpret_cast<const unsigned char*>(onekey.c_str()), onekey.length()))) {
raw_key = onekey;
base64_key = pbase64_key;
delete[] pbase64_key;
@ -926,7 +926,7 @@ bool S3fsCurl::FinalCheckSse()
bool S3fsCurl::LoadEnvSseCKeys()
{
char* envkeys = getenv("AWSSSECKEYS");
if(NULL == envkeys){
if(nullptr == envkeys){
// nothing to do
return true;
}
@ -950,7 +950,7 @@ bool S3fsCurl::LoadEnvSseCKeys()
bool S3fsCurl::LoadEnvSseKmsid()
{
const char* envkmsid = getenv("AWSSSEKMSID");
if(NULL == envkmsid){
if(nullptr == envkmsid){
// nothing to do
return true;
}
@ -1212,7 +1212,7 @@ bool S3fsCurl::MixMultipartPostCallback(S3fsCurl* s3fscurl, void* param)
S3fsCurl* S3fsCurl::UploadMultipartPostRetryCallback(S3fsCurl* s3fscurl)
{
if(!s3fscurl){
return NULL;
return nullptr;
}
// parse and get part_num, upload_id.
std::string upload_id;
@ -1220,20 +1220,20 @@ S3fsCurl* S3fsCurl::UploadMultipartPostRetryCallback(S3fsCurl* s3fscurl)
int part_num;
off_t tmp_part_num = 0;
if(!get_keyword_value(s3fscurl->url, "uploadId", upload_id)){
return NULL;
return nullptr;
}
upload_id = urlDecode(upload_id); // decode
if(!get_keyword_value(s3fscurl->url, "partNumber", part_num_str)){
return NULL;
return nullptr;
}
if(!s3fs_strtoofft(&tmp_part_num, part_num_str.c_str(), /*base=*/ 10)){
return NULL;
return nullptr;
}
part_num = static_cast<int>(tmp_part_num);
if(s3fscurl->retry_count >= S3fsCurl::retries){
S3FS_PRN_ERR("Over retry count(%d) limit(%s:%d).", s3fscurl->retry_count, s3fscurl->path.c_str(), part_num);
return NULL;
return nullptr;
}
// duplicate request
@ -1252,7 +1252,7 @@ S3fsCurl* S3fsCurl::UploadMultipartPostRetryCallback(S3fsCurl* s3fscurl)
if(0 != newcurl->UploadMultipartPostSetup(s3fscurl->path.c_str(), part_num, upload_id)){
S3FS_PRN_ERR("Could not duplicate curl object(%s:%d).", s3fscurl->path.c_str(), part_num);
delete newcurl;
return NULL;
return nullptr;
}
return newcurl;
}
@ -1260,7 +1260,7 @@ S3fsCurl* S3fsCurl::UploadMultipartPostRetryCallback(S3fsCurl* s3fscurl)
S3fsCurl* S3fsCurl::CopyMultipartPostRetryCallback(S3fsCurl* s3fscurl)
{
if(!s3fscurl){
return NULL;
return nullptr;
}
// parse and get part_num, upload_id.
std::string upload_id;
@ -1268,20 +1268,20 @@ S3fsCurl* S3fsCurl::CopyMultipartPostRetryCallback(S3fsCurl* s3fscurl)
int part_num;
off_t tmp_part_num = 0;
if(!get_keyword_value(s3fscurl->url, "uploadId", upload_id)){
return NULL;
return nullptr;
}
upload_id = urlDecode(upload_id); // decode
if(!get_keyword_value(s3fscurl->url, "partNumber", part_num_str)){
return NULL;
return nullptr;
}
if(!s3fs_strtoofft(&tmp_part_num, part_num_str.c_str(), /*base=*/ 10)){
return NULL;
return nullptr;
}
part_num = static_cast<int>(tmp_part_num);
if(s3fscurl->retry_count >= S3fsCurl::retries){
S3FS_PRN_ERR("Over retry count(%d) limit(%s:%d).", s3fscurl->retry_count, s3fscurl->path.c_str(), part_num);
return NULL;
return nullptr;
}
// duplicate request
@ -1297,7 +1297,7 @@ S3fsCurl* S3fsCurl::CopyMultipartPostRetryCallback(S3fsCurl* s3fscurl)
if(0 != newcurl->CopyMultipartPostSetup(s3fscurl->b_from.c_str(), s3fscurl->path.c_str(), part_num, upload_id, s3fscurl->b_meta)){
S3FS_PRN_ERR("Could not duplicate curl object(%s:%d).", s3fscurl->path.c_str(), part_num);
delete newcurl;
return NULL;
return nullptr;
}
return newcurl;
}
@ -1305,7 +1305,7 @@ S3fsCurl* S3fsCurl::CopyMultipartPostRetryCallback(S3fsCurl* s3fscurl)
S3fsCurl* S3fsCurl::MixMultipartPostRetryCallback(S3fsCurl* s3fscurl)
{
if(!s3fscurl){
return NULL;
return nullptr;
}
S3fsCurl* pcurl;
@ -1337,7 +1337,7 @@ int S3fsCurl::MapPutErrorResponse(int result)
const char* pstrbody = bodydata.str();
std::string code;
if(!pstrbody || simple_parse_xml(pstrbody, bodydata.size(), "Code", code)){
S3FS_PRN_ERR("Put request get 200 status response, but it included error body(or NULL). The request failed during copying the object in S3. Code: %s", code.c_str());
S3FS_PRN_ERR("Put request get 200 status response, but it included error body(or nullptr). The request failed during copying the object in S3. Code: %s", code.c_str());
// TODO: parse more specific error from <Code>
result = -EIO;
}
@ -1354,7 +1354,7 @@ std::unique_ptr<S3fsCurl> S3fsCurl::CreateParallelS3fsCurl(const char* tpath, in
if(!tpath || -1 == fd || start < 0 || size <= 0 || !petag){
S3FS_PRN_ERR("Parameters are wrong: tpath(%s), fd(%d), start(%lld), size(%lld), petag(%s)", SAFESTRPTR(tpath), fd, static_cast<long long int>(start), static_cast<long long int>(size), (petag ? "not null" : "null"));
result = -EIO;
return NULL;
return nullptr;
}
result = 0;
@ -1373,7 +1373,7 @@ std::unique_ptr<S3fsCurl> S3fsCurl::CreateParallelS3fsCurl(const char* tpath, in
if(0 != (result = s3fscurl->UploadMultipartPostSetup(tpath, part_num, upload_id))){
S3FS_PRN_ERR("failed uploading part setup(%d)", result);
return NULL;
return nullptr;
}
}else{
headers_t meta;
@ -1394,7 +1394,7 @@ std::unique_ptr<S3fsCurl> S3fsCurl::CreateParallelS3fsCurl(const char* tpath, in
if(0 != (result = s3fscurl->CopyMultipartPostSetup(tpath, tpath, part_num, upload_id, meta))){
S3FS_PRN_ERR("failed uploading part setup(%d)", result);
return NULL;
return nullptr;
}
}
@ -1402,7 +1402,7 @@ std::unique_ptr<S3fsCurl> S3fsCurl::CreateParallelS3fsCurl(const char* tpath, in
if(!s3fscurl->fpLazySetup || !s3fscurl->fpLazySetup(s3fscurl.get())){
S3FS_PRN_ERR("failed lazy function setup for uploading part");
result = -EIO;
return NULL;
return nullptr;
}
return s3fscurl;
}
@ -1602,11 +1602,11 @@ S3fsCurl* S3fsCurl::ParallelGetObjectRetryCallback(S3fsCurl* s3fscurl)
int result;
if(!s3fscurl){
return NULL;
return nullptr;
}
if(s3fscurl->retry_count >= S3fsCurl::retries){
S3FS_PRN_ERR("Over retry count(%d) limit(%s).", s3fscurl->retry_count, s3fscurl->path.c_str());
return NULL;
return nullptr;
}
// duplicate request(setup new curl object)
@ -1615,7 +1615,7 @@ S3fsCurl* S3fsCurl::ParallelGetObjectRetryCallback(S3fsCurl* s3fscurl)
if(0 != (result = newcurl->PreGetObjectRequest(s3fscurl->path.c_str(), s3fscurl->partdata.fd, s3fscurl->partdata.startpos, s3fscurl->partdata.size, s3fscurl->b_ssetype, s3fscurl->b_ssevalue))){
S3FS_PRN_ERR("failed downloading part setup(%d)", result);
delete newcurl;
return NULL;;
return nullptr;;
}
newcurl->retry_count = s3fscurl->retry_count + 1;
@ -1641,7 +1641,7 @@ int S3fsCurl::ParallelGetObjectRequest(const char* tpath, int fd, off_t start, o
off_t chunk;
// Initialize S3fsMultiCurl
//curlmulti.SetSuccessCallback(NULL); // not need to set success callback
//curlmulti.SetSuccessCallback(nullptr); // not need to set success callback
curlmulti.SetRetryCallback(S3fsCurl::ParallelGetObjectRetryCallback);
// Loop for setup parallel upload(multipart) request.
@ -1878,7 +1878,7 @@ int S3fsCurl::RawCurlDebugFunc(const CURL* hcurl, curl_infotype type, char* data
do {
char* eol = reinterpret_cast<char*>(memchr(p, '\n', remaining));
int newline = 0;
if (eol == NULL) {
if (eol == nullptr) {
eol = reinterpret_cast<char*>(memchr(p, '\r', remaining));
} else {
if (eol > p && *(eol - 1) == '\r') {
@ -1891,7 +1891,7 @@ int S3fsCurl::RawCurlDebugFunc(const CURL* hcurl, curl_infotype type, char* data
S3FS_PRN_CURL("%s %.*s", getCurlDebugHead(type), (int)length - newline, p);
remaining -= length;
p = eol;
} while (p != NULL && remaining > 0);
} while (p != nullptr && remaining > 0);
break;
case CURLINFO_SSL_DATA_IN:
@ -1909,11 +1909,11 @@ int S3fsCurl::RawCurlDebugFunc(const CURL* hcurl, curl_infotype type, char* data
// Methods for S3fsCurl
//-------------------------------------------------------------------
S3fsCurl::S3fsCurl(bool ahbe) :
hCurl(NULL), type(REQTYPE_UNSET), requestHeaders(NULL),
LastResponseCode(S3FSCURL_RESPONSECODE_NOTSET), postdata(NULL), postdata_remaining(0), is_use_ahbe(ahbe),
retry_count(0), b_infile(NULL), b_postdata(NULL), b_postdata_remaining(0), b_partdata_startpos(0), b_partdata_size(0),
hCurl(nullptr), type(REQTYPE_UNSET), requestHeaders(nullptr),
LastResponseCode(S3FSCURL_RESPONSECODE_NOTSET), postdata(nullptr), postdata_remaining(0), is_use_ahbe(ahbe),
retry_count(0), b_infile(nullptr), b_postdata(nullptr), b_postdata_remaining(0), b_partdata_startpos(0), b_partdata_size(0),
b_ssekey_pos(-1), b_ssetype(sse_type_t::SSE_DISABLE),
sem(NULL), completed_tids_lock(NULL), completed_tids(NULL), fpLazySetup(NULL), curlCode(CURLE_OK)
sem(nullptr), completed_tids_lock(nullptr), completed_tids(nullptr), fpLazySetup(nullptr), curlCode(CURLE_OK)
{
if(!S3fsCurl::ps3fscred){
S3FS_PRN_CRIT("The object of S3fs Credential class is not initialized.");
@ -2023,7 +2023,7 @@ bool S3fsCurl::ResetHandle(AutoLock::Type locktype)
}
AutoLock lock(&S3fsCurl::curl_handles_lock, locktype);
S3fsCurl::curl_times[hCurl] = time(0);
S3fsCurl::curl_times[hCurl] = time(nullptr);
S3fsCurl::curl_progress[hCurl] = progress_t(-1, -1);
return true;
@ -2042,7 +2042,7 @@ bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake)
}
if(!hCurl){
if(NULL == (hCurl = sCurlPool->GetHandler(only_pool))){
if(nullptr == (hCurl = sCurlPool->GetHandler(only_pool))){
if(!only_pool){
S3FS_PRN_ERR("Failed to create handle.");
return false;
@ -2080,7 +2080,7 @@ bool S3fsCurl::DestroyCurlHandle(bool restore_pool, bool clear_internal_data, Au
S3fsCurl::curl_times.erase(hCurl);
S3fsCurl::curl_progress.erase(hCurl);
sCurlPool->ReturnHandler(hCurl, restore_pool);
hCurl = NULL;
hCurl = nullptr;
}else{
return false;
}
@ -2100,23 +2100,23 @@ bool S3fsCurl::ClearInternalData()
query_string= "";
if(requestHeaders){
curl_slist_free_all(requestHeaders);
requestHeaders = NULL;
requestHeaders = nullptr;
}
responseHeaders.clear();
bodydata.Clear();
headdata.Clear();
LastResponseCode = S3FSCURL_RESPONSECODE_NOTSET;
postdata = NULL;
postdata = nullptr;
postdata_remaining = 0;
retry_count = 0;
b_infile = NULL;
b_postdata = NULL;
b_infile = nullptr;
b_postdata = nullptr;
b_postdata_remaining = 0;
b_partdata_startpos = 0;
b_partdata_size = 0;
partdata.clear();
fpLazySetup = NULL;
fpLazySetup = nullptr;
S3FS_MALLOCTRIM(0);
@ -2471,7 +2471,7 @@ bool S3fsCurl::RemakeHandle()
int S3fsCurl::RequestPerform(bool dontAddAuthHeaders /*=false*/)
{
if(S3fsLog::IsS3fsLogDbg()){
char* ptr_url = NULL;
char* ptr_url = nullptr;
curl_easy_getinfo(hCurl, CURLINFO_EFFECTIVE_URL , &ptr_url);
S3FS_PRN_DBG("connecting to URL %s", SAFESTRPTR(ptr_url));
}
@ -2622,7 +2622,7 @@ int S3fsCurl::RequestPerform(bool dontAddAuthHeaders /*=false*/)
sleep(4);
{
AutoLock lock(&S3fsCurl::curl_handles_lock);
S3fsCurl::curl_times[hCurl] = time(0);
S3fsCurl::curl_times[hCurl] = time(nullptr);
}
break;
@ -2759,13 +2759,13 @@ std::string S3fsCurl::CalcSignatureV2(const std::string& method, const std::stri
size_t key_len = secret_access_key.size();
const unsigned char* sdata = reinterpret_cast<const unsigned char*>(StringToSign.data());
size_t sdata_len = StringToSign.size();
unsigned char* md = NULL;
unsigned char* md = nullptr;
unsigned int md_len = 0;;
s3fs_HMAC(key, key_len, sdata, sdata_len, &md, &md_len);
char* base64;
if(NULL == (base64 = s3fs_base64(md, md_len))){
if(nullptr == (base64 = s3fs_base64(md, md_len))){
delete[] md;
return std::string(""); // ENOMEM
}
@ -2805,7 +2805,7 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
StringCQ += payload_hash;
std::string kSecret = "AWS4" + secret_access_key;
unsigned char *kDate, *kRegion, *kService, *kSigning, *sRequest = NULL;
unsigned char *kDate, *kRegion, *kService, *kSigning, *sRequest = nullptr;
unsigned int kDate_len,kRegion_len, kService_len, kSigning_len, sRequest_len = 0;
s3fs_HMAC256(kSecret.c_str(), kSecret.size(), reinterpret_cast<const unsigned char*>(strdate.data()), strdate.size(), &kDate, &kDate_len);
@ -2828,7 +2828,7 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
const unsigned char* cscope = reinterpret_cast<const unsigned char*>(StringToSign.c_str());
size_t cscope_len = StringToSign.size();
unsigned char* md = NULL;
unsigned char* md = nullptr;
unsigned int md_len = 0;
s3fs_HMAC256(kSigning, kSigning_len, cscope, cscope_len, &md, &md_len);
@ -2849,14 +2849,14 @@ void S3fsCurl::insertV4Headers(const std::string& access_key_id, const std::stri
if(GetUnsignedPayload()){
payload_hash = "UNSIGNED-PAYLOAD";
}else{
payload_hash = s3fs_sha256_hex_fd(b_infile == NULL ? -1 : fileno(b_infile), 0, -1);
payload_hash = s3fs_sha256_hex_fd(b_infile == nullptr ? -1 : fileno(b_infile), 0, -1);
}
break;
case REQTYPE_COMPLETEMULTIPOST:
{
size_t cRequest_len = strlen(reinterpret_cast<const char *>(b_postdata));
unsigned char* sRequest = NULL;
unsigned char* sRequest = nullptr;
unsigned int sRequest_len = 0;
s3fs_sha256(b_postdata, cRequest_len, &sRequest, &sRequest_len);
payload_hash = s3fs_hex_lower(sRequest, sRequest_len);
@ -2875,7 +2875,7 @@ void S3fsCurl::insertV4Headers(const std::string& access_key_id, const std::stri
break;
}
if(b_infile != NULL && payload_hash.empty()){
if(b_infile != nullptr && payload_hash.empty()){
S3FS_PRN_ERR("Failed to make SHA256.");
// TODO: propagate error
}
@ -2917,7 +2917,7 @@ void S3fsCurl::insertV2Headers(const std::string& access_key_id, const std::stri
std::string date = get_date_rfc850();
requestHeaders = curl_slist_sort_insert(requestHeaders, "Date", date.c_str());
if(op != "PUT" && op != "POST"){
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", NULL);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", nullptr);
}
if(!S3fsCurl::IsPublicBucket()){
@ -2973,7 +2973,7 @@ int S3fsCurl::DeleteRequest(const char* tpath)
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
op = "DELETE";
@ -3003,7 +3003,7 @@ int S3fsCurl::GetIAMv2ApiToken(const char* token_url, int token_ttl, const char*
if(!CreateCurlHandle()){
return -EIO;
}
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
@ -3069,7 +3069,7 @@ bool S3fsCurl::GetIAMCredentials(const char* cred_url, const char* iam_v2_token,
if(!CreateCurlHandle()){
return false;
}
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
std::string postContent;
@ -3156,7 +3156,7 @@ bool S3fsCurl::GetIAMRoleFromMetaData(const char* cred_url, const char* iam_v2_t
if(!CreateCurlHandle()){
return false;
}
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
@ -3261,7 +3261,7 @@ bool S3fsCurl::PreHeadRequest(const char* tpath, const char* bpath, const char*
path = get_realpath(tpath);
base_path = SAFESTRPTR(bpath);
saved_path = SAFESTRPTR(savedpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
// requestHeaders(SSE-C)
@ -3296,7 +3296,7 @@ int S3fsCurl::HeadRequest(const char* tpath, headers_t& meta)
if(!DestroyCurlHandle()){
break;
}
if(!PreHeadRequest(tpath, NULL, NULL, pos)){
if(!PreHeadRequest(tpath, nullptr, nullptr, pos)){
break;
}
if(!fpLazySetup || !fpLazySetup(this)){
@ -3350,7 +3350,7 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
@ -3435,7 +3435,7 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
{
struct stat st;
FILE* file = NULL;
FILE* file = nullptr;
S3FS_PRN_INFO3("[tpath=%s]", SAFESTRPTR(tpath));
@ -3451,7 +3451,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
// The fd should not be closed here, so call dup here to duplicate it.
//
int fd2;
if(-1 == (fd2 = dup(fd)) || -1 == fstat(fd2, &st) || 0 != lseek(fd2, 0, SEEK_SET) || NULL == (file = fdopen(fd2, "rb"))){
if(-1 == (fd2 = dup(fd)) || -1 == fstat(fd2, &st) || 0 != lseek(fd2, 0, SEEK_SET) || nullptr == (file = fdopen(fd2, "rb"))){
S3FS_PRN_ERR("Could not duplicate file descriptor(errno=%d)", errno);
if(-1 != fd2){
close(fd2);
@ -3476,7 +3476,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
@ -3590,7 +3590,7 @@ int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, off_t
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
if(0 < size){
@ -3704,7 +3704,7 @@ int S3fsCurl::CheckBucket(const char* check_path, bool compat_dir)
turl += urlargs;
url = prepare_url(turl.c_str());
path = strCheckPath;
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
@ -3756,7 +3756,7 @@ int S3fsCurl::ListBucketRequest(const char* tpath, const char* query)
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
@ -3812,7 +3812,7 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, std::s
turl += "?" + query_string;
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
bodydata.Clear();
responseHeaders.clear();
@ -3852,7 +3852,7 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, std::s
requestHeaders = AdditionalHeader::get()->AddHeader(requestHeaders, tpath);
}
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", NULL);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", nullptr);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
op = "POST";
@ -3927,8 +3927,8 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, const std::string&
b_postdata_remaining = postdata_remaining;
if(!CreateCurlHandle()){
postdata = NULL;
b_postdata = NULL;
postdata = nullptr;
b_postdata = nullptr;
return -EIO;
}
std::string resource;
@ -3943,12 +3943,12 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, const std::string&
turl += "?" + query_string;
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
bodydata.Clear();
responseHeaders.clear();
std::string contype = "application/xml";
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", NULL);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", nullptr);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
if(sse_type_t::SSE_C == S3fsCurl::GetSseType()){
@ -3995,8 +3995,8 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, const std::string&
// request
int result = RequestPerform();
bodydata.Clear();
postdata = NULL;
b_postdata = NULL;
postdata = nullptr;
b_postdata = nullptr;
return result;
}
@ -4016,11 +4016,11 @@ int S3fsCurl::MultipartListRequest(std::string& body)
query_string = "uploads";
turl += "?" + query_string;
url = prepare_url(turl.c_str());
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", NULL);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", nullptr);
op = "GET";
type = REQTYPE_MULTILIST;
@ -4072,7 +4072,7 @@ int S3fsCurl::AbortMultipartUpload(const char* tpath, const std::string& upload_
turl += "?" + query_string;
url = prepare_url(turl.c_str());
path = get_realpath(tpath);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
op = "DELETE";
@ -4113,12 +4113,12 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st
return -EINVAL;
}
requestHeaders = NULL;
requestHeaders = nullptr;
// make md5 and file pointer
if(S3fsCurl::is_content_md5){
unsigned char *md5raw = s3fs_md5_fd(partdata.fd, partdata.startpos, partdata.size);
if(md5raw == NULL){
if(md5raw == nullptr){
S3FS_PRN_ERR("Could not make md5 for file(part %d)", part_num);
return -EIO;
}
@ -4156,7 +4156,7 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st
}
}
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", NULL);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Accept", nullptr);
op = "PUT";
type = REQTYPE_UPLOADMULTIPOST;
@ -4216,7 +4216,7 @@ int S3fsCurl::CopyMultipartPostSetup(const char* from, const char* to, int part_
turl += urlargs;
url = prepare_url(turl.c_str());
path = get_realpath(to);
requestHeaders = NULL;
requestHeaders = nullptr;
responseHeaders.clear();
bodydata.Clear();
headdata.Clear();

View File

@ -349,7 +349,7 @@ class S3fsCurl
int RequestPerform(bool dontAddAuthHeaders=false);
int DeleteRequest(const char* tpath);
int GetIAMv2ApiToken(const char* token_url, int token_ttl, const char* token_ttl_hdr, std::string& response);
bool PreHeadRequest(const char* tpath, const char* bpath = NULL, const char* savedpath = NULL, size_t ssekey_pos = -1);
bool PreHeadRequest(const char* tpath, const char* bpath = nullptr, const char* savedpath = nullptr, size_t ssekey_pos = -1);
bool PreHeadRequest(const std::string& tpath, const std::string& bpath, const std::string& savedpath, size_t ssekey_pos = -1) {
return PreHeadRequest(tpath.c_str(), bpath.c_str(), savedpath.c_str(), ssekey_pos);
}

View File

@ -75,7 +75,7 @@ CURL* CurlHandlerPool::GetHandler(bool only_pool)
{
AutoLock lock(&mLock);
CURL* hCurl = NULL;
CURL* hCurl = nullptr;
if(!mPool.empty()){
hCurl = mPool.back();

View File

@ -33,7 +33,7 @@
//-------------------------------------------------------------------
// Class S3fsMultiCurl
//-------------------------------------------------------------------
S3fsMultiCurl::S3fsMultiCurl(int maxParallelism) : maxParallelism(maxParallelism), SuccessCallback(NULL), NotFoundCallback(NULL), RetryCallback(NULL), pSuccessCallbackParam(NULL), pNotFoundCallbackParam(NULL)
S3fsMultiCurl::S3fsMultiCurl(int maxParallelism) : maxParallelism(maxParallelism), SuccessCallback(nullptr), NotFoundCallback(nullptr), RetryCallback(nullptr), pSuccessCallbackParam(nullptr), pNotFoundCallbackParam(nullptr)
{
int result;
pthread_mutexattr_t attr;
@ -166,7 +166,7 @@ int S3fsMultiCurl::MultiPerform()
isMultiHead |= s3fscurl->GetOp() == "HEAD";
rc = pthread_create(&thread, NULL, S3fsMultiCurl::RequestPerformWrapper, static_cast<void*>(s3fscurl));
rc = pthread_create(&thread, nullptr, S3fsMultiCurl::RequestPerformWrapper, static_cast<void*>(s3fscurl));
if (rc != 0) {
success = false;
S3FS_PRN_ERR("failed pthread_create - rc(%d)", rc);
@ -289,7 +289,7 @@ int S3fsMultiCurl::MultiRead()
if(RetryCallback){
retry_ptr = RetryCallback(s3fscurl.get());
retrycurl.reset(retry_ptr);
if(NULL != retry_ptr){
if(nullptr != retry_ptr){
clist_all.push_back(std::move(retrycurl));
}else{
// set EIO and wait for other parts.
@ -358,7 +358,7 @@ int S3fsMultiCurl::Request()
void* S3fsMultiCurl::RequestPerformWrapper(void* arg)
{
S3fsCurl* s3fscurl= static_cast<S3fsCurl*>(arg);
void* result = NULL;
void* result = nullptr;
if(!s3fscurl){
return reinterpret_cast<void*>(static_cast<intptr_t>(-EIO));
}

View File

@ -65,7 +65,7 @@ struct curl_slist* curl_slist_sort_insert(struct curl_slist* list, const char* k
std::string strval = value ? trim(std::string(value)) : "";
std::string strnew = key + std::string(": ") + strval;
char* data;
if(NULL == (data = strdup(strnew.c_str()))){
if(nullptr == (data = strdup(strnew.c_str()))){
return list;
}
@ -88,7 +88,7 @@ struct curl_slist* curl_slist_sort_insert(struct curl_slist* list, const char* k
}
struct curl_slist* new_item;
if(NULL == (new_item = static_cast<struct curl_slist*>(malloc(sizeof(*new_item))))){
if(nullptr == (new_item = static_cast<struct curl_slist*>(malloc(sizeof(*new_item))))){
free(data);
return list;
}
@ -303,7 +303,7 @@ bool make_md5_from_binary(const char* pstr, size_t length, std::string& md5)
return false;
}
FILE* fp;
if(NULL == (fp = tmpfile())){
if(nullptr == (fp = tmpfile())){
S3FS_PRN_ERR("Could not make tmpfile.");
return false;
}

View File

@ -119,7 +119,7 @@ bool FdManager::DeleteCacheDirectory()
}
std::string cache_path;
if(!FdManager::MakeCachePath(NULL, cache_path, false)){
if(!FdManager::MakeCachePath(nullptr, cache_path, false)){
return false;
}
if(!delete_files_in_dir(cache_path.c_str(), true)){
@ -260,7 +260,7 @@ bool FdManager::InitFakeUsedDiskSize(off_t fake_freesize)
{
FdManager::fake_used_disk_space = 0; // At first, clear this value because this value is used in GetFreeDiskSpace.
off_t actual_freesize = FdManager::GetFreeDiskSpace(NULL);
off_t actual_freesize = FdManager::GetFreeDiskSpace(nullptr);
if(fake_freesize < actual_freesize){
FdManager::fake_used_disk_space = actual_freesize - fake_freesize;
@ -313,7 +313,7 @@ bool FdManager::HaveLseekHole()
// create temporary file
FILE* ptmpfp;
int fd;
if(NULL == (ptmpfp = MakeTempFile()) || -1 == (fd = fileno(ptmpfp))){
if(nullptr == (ptmpfp = MakeTempFile()) || -1 == (fd = fileno(ptmpfp))){
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
if(ptmpfp){
fclose(ptmpfp);
@ -387,11 +387,11 @@ FILE* FdManager::MakeTempFile() {
fd = mkstemp(cfn);
if (-1 == fd) {
S3FS_PRN_ERR("failed to create tmp file. errno(%d)", errno);
return NULL;
return nullptr;
}
if (-1 == unlink(cfn)) {
S3FS_PRN_ERR("failed to delete tmp file. errno(%d)", errno);
return NULL;
return nullptr;
}
return fdopen(fd, "rb+");
}
@ -402,7 +402,7 @@ bool FdManager::HasOpenEntityFd(const char* path)
FdEntity* ent;
int fd = -1;
if(NULL == (ent = FdManager::singleton.GetFdEntity(path, fd, false, AutoLock::ALREADY_LOCKED))){
if(nullptr == (ent = FdManager::singleton.GetFdEntity(path, fd, false, AutoLock::ALREADY_LOCKED))){
return false;
}
return (0 < ent->GetOpenCount());
@ -484,7 +484,7 @@ FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, Aut
S3FS_PRN_INFO3("[path=%s][pseudo_fd=%d]", SAFESTRPTR(path), existfd);
if(!path || '\0' == path[0]){
return NULL;
return nullptr;
}
AutoLock auto_lock(&FdManager::fd_manager_lock, locktype);
@ -514,7 +514,7 @@ FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, Aut
return iter->second;
}
// found fd, but it is used another file(file descriptor is recycled)
// so returns NULL.
// so returns nullptr.
break;
}
}
@ -529,7 +529,7 @@ FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, Aut
}
}
}
return NULL;
return nullptr;
}
FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off_t size, const struct timespec& ts_mctime, int flags, bool force_tmpfile, bool is_create, bool ignore_modify, AutoLock::Type type)
@ -537,7 +537,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
S3FS_PRN_DBG("[path=%s][size=%lld][ts_mctime=%s][flags=0x%x][force_tmpfile=%s][create=%s][ignore_modify=%s]", SAFESTRPTR(path), static_cast<long long>(size), str(ts_mctime).c_str(), flags, (force_tmpfile ? "yes" : "no"), (is_create ? "yes" : "no"), (ignore_modify ? "yes" : "no"));
if(!path || '\0' == path[0]){
return NULL;
return nullptr;
}
AutoLock auto_lock(&FdManager::fd_manager_lock);
@ -579,7 +579,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
// (re)open
if(0 > (fd = ent->Open(pmeta, size, ts_mctime, flags, type))){
S3FS_PRN_ERR("failed to (re)open and create new pseudo fd for path(%s).", path);
return NULL;
return nullptr;
}
}else if(is_create){
@ -587,7 +587,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
std::string cache_path;
if(!force_tmpfile && !FdManager::MakeCachePath(path, cache_path, true)){
S3FS_PRN_ERR("failed to make cache path for object(%s).", path);
return NULL;
return nullptr;
}
// make new obj
ent = new FdEntity(path, cache_path.c_str());
@ -596,7 +596,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
if(0 > (fd = ent->Open(pmeta, size, ts_mctime, flags, type))){
S3FS_PRN_ERR("failed to open and create new pseudo fd for path(%s).", path);
delete ent;
return NULL;
return nullptr;
}
if(!cache_path.empty()){
@ -615,7 +615,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
fent[tmppath] = ent;
}
}else{
return NULL;
return nullptr;
}
return ent;
}
@ -638,7 +638,7 @@ FdEntity* FdManager::GetExistFdEntity(const char* path, int existfd)
}
}
// not found entity
return NULL;
return nullptr;
}
FdEntity* FdManager::OpenExistFdEntity(const char* path, int& fd, int flags)
@ -646,10 +646,10 @@ FdEntity* FdManager::OpenExistFdEntity(const char* path, int& fd, int flags)
S3FS_PRN_DBG("[path=%s][flags=0x%x]", SAFESTRPTR(path), flags);
// search entity by path, and create pseudo fd
FdEntity* ent = Open(fd, path, NULL, -1, S3FS_OMIT_TS, flags, false, false, false, AutoLock::NONE);
FdEntity* ent = Open(fd, path, nullptr, -1, S3FS_OMIT_TS, flags, false, false, false, AutoLock::NONE);
if(!ent){
// Not found entity
return NULL;
return nullptr;
}
return ent;
}
@ -792,7 +792,7 @@ void FdManager::CleanupCacheDirInternal(const std::string &path)
struct dirent* dent;
std::string abs_path = cache_dir + "/" + S3fsCred::GetBucket() + path;
if(NULL == (dp = opendir(abs_path.c_str()))){
if(nullptr == (dp = opendir(abs_path.c_str()))){
S3FS_PRN_ERR("could not open cache dir(%s) - errno(%d)", abs_path.c_str(), errno);
return;
}
@ -831,7 +831,7 @@ void FdManager::CleanupCacheDirInternal(const std::string &path)
bool FdManager::ReserveDiskSpace(off_t size)
{
if(IsSafeDiskSpace(NULL, size)){
if(IsSafeDiskSpace(nullptr, size)){
AutoLock auto_lock(&FdManager::reserved_diskspace_lock);
free_disk_space += size;
return true;
@ -884,14 +884,14 @@ bool FdManager::RawCheckAllCache(FILE* fp, const char* cache_stat_top_dir, const
DIR* statsdir;
std::string target_dir = cache_stat_top_dir;
target_dir += sub_path;
if(NULL == (statsdir = opendir(target_dir.c_str()))){
if(nullptr == (statsdir = opendir(target_dir.c_str()))){
S3FS_PRN_ERR("Could not open directory(%s) by errno(%d)", target_dir.c_str(), errno);
return false;
}
// loop in directory of cache file's stats
struct dirent* pdirent = NULL;
while(NULL != (pdirent = readdir(statsdir))){
struct dirent* pdirent = nullptr;
while(nullptr != (pdirent = readdir(statsdir))){
if(DT_DIR == pdirent->d_type){
// found directory
if(0 == strcmp(pdirent->d_name, ".") || 0 == strcmp(pdirent->d_name, "..")){
@ -1026,7 +1026,7 @@ bool FdManager::CheckAllCache()
if(FdManager::check_cache_output.empty()){
fp = stdout;
}else{
if(NULL == (fp = fopen(FdManager::check_cache_output.c_str(), "a+"))){
if(nullptr == (fp = fopen(FdManager::check_cache_output.c_str(), "a+"))){
S3FS_PRN_ERR("Could not open(create) output file(%s) for checking all cache by errno(%d)", FdManager::check_cache_output.c_str(), errno);
return false;
}

View File

@ -85,7 +85,7 @@ class FdManager
static bool CheckTmpDirExist();
static FILE* MakeTempFile();
// Return FdEntity associated with path, returning NULL on error. This operation increments the reference count; callers must decrement via Close after use.
// Return FdEntity associated with path, returning nullptr on error. This operation increments the reference count; callers must decrement via Close after use.
FdEntity* GetFdEntity(const char* path, int& existfd, bool newfd = true, AutoLock::Type locktype = AutoLock::NONE);
FdEntity* Open(int& fd, const char* path, const headers_t* pmeta, off_t size, const struct timespec& ts_mctime, int flags, bool force_tmpfile, bool is_create, bool ignore_modify, AutoLock::Type type);
FdEntity* GetExistFdEntity(const char* path, int existfd = -1);

View File

@ -27,7 +27,7 @@
//------------------------------------------------
// AutoFdEntity methods
//------------------------------------------------
AutoFdEntity::AutoFdEntity() : pFdEntity(NULL), pseudo_fd(-1)
AutoFdEntity::AutoFdEntity() : pFdEntity(nullptr), pseudo_fd(-1)
{
}
@ -36,7 +36,7 @@ AutoFdEntity::AutoFdEntity() : pFdEntity(NULL), pseudo_fd(-1)
// Even if it is called, the consistency of the number of
// references can be maintained, but this case is not assumed.
//
AutoFdEntity::AutoFdEntity(AutoFdEntity& other) : pFdEntity(NULL), pseudo_fd(-1)
AutoFdEntity::AutoFdEntity(AutoFdEntity& other) : pFdEntity(nullptr), pseudo_fd(-1)
{
S3FS_PRN_WARN("This method should not be called. Please check the caller.");
@ -61,7 +61,7 @@ bool AutoFdEntity::Close()
S3FS_PRN_ERR("Failed to close fdentity.");
return false;
}
pFdEntity = NULL;
pFdEntity = nullptr;
pseudo_fd = -1;
}
return true;
@ -79,7 +79,7 @@ int AutoFdEntity::Detach()
}
int fd = pseudo_fd;
pseudo_fd = -1;
pFdEntity = NULL;
pFdEntity = nullptr;
return fd;
}
@ -88,9 +88,9 @@ FdEntity* AutoFdEntity::Attach(const char* path, int existfd)
{
Close();
if(NULL == (pFdEntity = FdManager::get()->GetFdEntity(path, existfd, false))){
if(nullptr == (pFdEntity = FdManager::get()->GetFdEntity(path, existfd, false))){
S3FS_PRN_DBG("Could not find fd entity object(file=%s, pseudo_fd=%d)", path, existfd);
return NULL;
return nullptr;
}
pseudo_fd = existfd;
return pFdEntity;
@ -100,9 +100,9 @@ FdEntity* AutoFdEntity::Open(const char* path, const headers_t* pmeta, off_t siz
{
Close();
if(NULL == (pFdEntity = FdManager::get()->Open(pseudo_fd, path, pmeta, size, ts_mctime, flags, force_tmpfile, is_create, ignore_modify, type))){
if(nullptr == (pFdEntity = FdManager::get()->Open(pseudo_fd, path, pmeta, size, ts_mctime, flags, force_tmpfile, is_create, ignore_modify, type))){
pseudo_fd = -1;
return NULL;
return nullptr;
}
return pFdEntity;
}
@ -115,8 +115,8 @@ FdEntity* AutoFdEntity::GetExistFdEntity(const char* path, int existfd)
Close();
FdEntity* ent;
if(NULL == (ent = FdManager::get()->GetExistFdEntity(path, existfd))){
return NULL;
if(nullptr == (ent = FdManager::get()->GetExistFdEntity(path, existfd))){
return nullptr;
}
return ent;
}
@ -125,8 +125,8 @@ FdEntity* AutoFdEntity::OpenExistFdEntity(const char* path, int flags)
{
Close();
if(NULL == (pFdEntity = FdManager::get()->OpenExistFdEntity(path, pseudo_fd, flags))){
return NULL;
if(nullptr == (pFdEntity = FdManager::get()->OpenExistFdEntity(path, pseudo_fd, flags))){
return nullptr;
}
return pFdEntity;
}

View File

@ -25,7 +25,6 @@
#include <unistd.h>
#include <limits.h>
#include <sys/stat.h>
#include <memory>
#include "common.h"
#include "fdcache_entity.h"
@ -108,7 +107,7 @@ ino_t FdEntity::GetInode(int fd)
//------------------------------------------------
FdEntity::FdEntity(const char* tpath, const char* cpath) :
is_lock_init(false), path(SAFESTRPTR(tpath)),
physical_fd(-1), pfile(NULL), inode(0), size_orgmeta(0),
physical_fd(-1), pfile(nullptr), inode(0), size_orgmeta(0),
cachepath(SAFESTRPTR(cpath)), pending_status(NO_UPDATE_PENDING)
{
holding_mtime.tv_sec = -1;
@ -172,7 +171,7 @@ void FdEntity::Clear()
}
if(pfile){
fclose(pfile);
pfile = NULL;
pfile = nullptr;
}
physical_fd = -1;
inode = 0;
@ -242,7 +241,7 @@ void FdEntity::Close(int fd)
}
if(pfile){
fclose(pfile);
pfile = NULL;
pfile = nullptr;
}
physical_fd = -1;
inode = 0;
@ -313,13 +312,13 @@ int FdEntity::OpenMirrorFile()
// make temporary directory
std::string bupdir;
if(!FdManager::MakeCachePath(NULL, bupdir, true, true)){
if(!FdManager::MakeCachePath(nullptr, bupdir, true, true)){
S3FS_PRN_ERR("could not make bup cache directory path or create it.");
return -EIO;
}
// create seed generating mirror file name
unsigned int seed = static_cast<unsigned int>(time(NULL));
unsigned int seed = static_cast<unsigned int>(time(nullptr));
int urandom_fd;
if(-1 != (urandom_fd = open("/dev/urandom", O_RDONLY))){
unsigned int rand_data;
@ -376,19 +375,19 @@ PseudoFdInfo* FdEntity::CheckPseudoFdFlags(int fd, bool writable, AutoLock::Type
AutoLock auto_lock(&fdent_lock, locktype);
if(-1 == fd){
return NULL;
return nullptr;
}
fdinfo_map_t::iterator iter = pseudo_fd_map.find(fd);
if(pseudo_fd_map.end() == iter || NULL == iter->second){
return NULL;
if(pseudo_fd_map.end() == iter || nullptr == iter->second){
return nullptr;
}
if(writable){
if(!iter->second->Writable()){
return NULL;
return nullptr;
}
}else{
if(!iter->second->Readable()){
return NULL;
return nullptr;
}
}
return iter->second.get();
@ -582,7 +581,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
physical_fd = mirrorfd;
// make file pointer(for being same tmpfile)
if(NULL == (pfile = fdopen(physical_fd, "wb"))){
if(nullptr == (pfile = fdopen(physical_fd, "wb"))){
S3FS_PRN_ERR("failed to get fileno(%s). errno(%d)", cachepath.c_str(), errno);
close(physical_fd);
physical_fd = -1;
@ -595,11 +594,11 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
inode = 0;
// open temporary file
if(NULL == (pfile = FdManager::MakeTempFile()) || -1 ==(physical_fd = fileno(pfile))){
if(nullptr == (pfile = FdManager::MakeTempFile()) || -1 ==(physical_fd = fileno(pfile))){
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
if(pfile){
fclose(pfile);
pfile = NULL;
pfile = nullptr;
}
return (0 == errno ? -EIO : -errno);
}
@ -626,7 +625,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
if(0 != ftruncate(physical_fd, size) || 0 != fsync(physical_fd)){
S3FS_PRN_ERR("ftruncate(%s) or fsync returned err(%d)", cachepath.c_str(), errno);
fclose(pfile);
pfile = NULL;
pfile = nullptr;
physical_fd = -1;
inode = 0;
return (0 == errno ? -EIO : -errno);
@ -660,7 +659,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
if(0 != SetMCtime(ts_mctime, ts_mctime, AutoLock::ALREADY_LOCKED)){
S3FS_PRN_ERR("failed to set mtime/ctime. errno(%d)", errno);
fclose(pfile);
pfile = NULL;
pfile = nullptr;
physical_fd = -1;
inode = 0;
return (0 == errno ? -EIO : -errno);
@ -679,7 +678,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
pseudo_fd_map.erase(pseudo_fd);
if(pfile){
fclose(pfile);
pfile = NULL;
pfile = nullptr;
}
}
}
@ -1132,7 +1131,7 @@ int FdEntity::NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start, off_t si
S3FS_PRN_INFO3("[path=%s][physical_fd=%d][offset=%lld][size=%lld]", path.c_str(), physical_fd, static_cast<long long int>(start), static_cast<long long int>(size));
if(!pseudo_obj){
S3FS_PRN_ERR("Pseudo object is NULL.");
S3FS_PRN_ERR("Pseudo object is nullptr.");
return -EIO;
}
@ -1157,7 +1156,7 @@ int FdEntity::NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start, off_t si
// open temporary file
FILE* ptmpfp;
int tmpfd;
if(NULL == (ptmpfp = FdManager::MakeTempFile()) || -1 ==(tmpfd = fileno(ptmpfp))){
if(nullptr == (ptmpfp = FdManager::MakeTempFile()) || -1 ==(tmpfd = fileno(ptmpfp))){
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
if(ptmpfp){
fclose(ptmpfp);
@ -1339,7 +1338,7 @@ int FdEntity::NoCacheMultipartPost(PseudoFdInfo* pseudo_obj, int tgfd, off_t sta
}
// append new part and get it's etag string pointer
etagpair* petagpair = NULL;
etagpair* petagpair = nullptr;
if(!pseudo_obj->AppendUploadPart(start, size, false, &petagpair)){
return -EIO;
}
@ -1412,7 +1411,7 @@ int FdEntity::RowFlush(int fd, const char* tpath, AutoLock::Type type, bool forc
// check pseudo fd and its flag
fdinfo_map_t::iterator miter = pseudo_fd_map.find(fd);
if(pseudo_fd_map.end() == miter || NULL == miter->second){
if(pseudo_fd_map.end() == miter || nullptr == miter->second){
return -EBADF;
}
if(!miter->second->Writable() && !(miter->second->GetFlags() & O_CREAT)){
@ -1968,7 +1967,7 @@ ssize_t FdEntity::Read(int fd, char* bytes, off_t start, size_t size, bool force
{
S3FS_PRN_DBG("[path=%s][pseudo_fd=%d][physical_fd=%d][offset=%lld][size=%zu]", path.c_str(), fd, physical_fd, static_cast<long long int>(start), size);
if(-1 == physical_fd || NULL == CheckPseudoFdFlags(fd, false)){
if(-1 == physical_fd || nullptr == CheckPseudoFdFlags(fd, false)){
S3FS_PRN_DBG("pseudo_fd(%d) to physical_fd(%d) for path(%s) is not opened or not readable", fd, physical_fd, path.c_str());
return -EBADF;
}
@ -2031,14 +2030,14 @@ ssize_t FdEntity::Write(int fd, const char* bytes, off_t start, size_t size)
{
S3FS_PRN_DBG("[path=%s][pseudo_fd=%d][physical_fd=%d][offset=%lld][size=%zu]", path.c_str(), fd, physical_fd, static_cast<long long int>(start), size);
PseudoFdInfo* pseudo_obj = NULL;
if(-1 == physical_fd || NULL == (pseudo_obj = CheckPseudoFdFlags(fd, false))){
PseudoFdInfo* pseudo_obj = nullptr;
if(-1 == physical_fd || nullptr == (pseudo_obj = CheckPseudoFdFlags(fd, false))){
S3FS_PRN_ERR("pseudo_fd(%d) to physical_fd(%d) for path(%s) is not opened or not writable", fd, physical_fd, path.c_str());
return -EBADF;
}
// check if not enough disk space left BEFORE locking fd
if(FdManager::IsCacheDir() && !FdManager::IsSafeDiskSpace(NULL, size)){
if(FdManager::IsCacheDir() && !FdManager::IsSafeDiskSpace(nullptr, size)){
FdManager::get()->CleanupCacheDir();
}
AutoLock auto_lock(&fdent_lock);

View File

@ -100,14 +100,14 @@ class FdEntity
static bool GetStreamUpload() { return streamupload; }
static bool SetStreamUpload(bool isstream);
explicit FdEntity(const char* tpath = NULL, const char* cpath = NULL);
explicit FdEntity(const char* tpath = nullptr, const char* cpath = nullptr);
~FdEntity();
void Close(int fd);
bool IsOpen() const { return (-1 != physical_fd); }
bool FindPseudoFd(int fd, AutoLock::Type locktype = AutoLock::NONE) const;
int Open(const headers_t* pmeta, off_t size, const struct timespec& ts_mctime, int flags, AutoLock::Type type);
bool LoadAll(int fd, headers_t* pmeta = NULL, off_t* size = NULL, bool force_load = false);
bool LoadAll(int fd, headers_t* pmeta = nullptr, off_t* size = nullptr, bool force_load = false);
int Dup(int fd, AutoLock::Type locktype = AutoLock::NONE);
int OpenPseudoFd(int flags = O_RDONLY, AutoLock::Type locktype = AutoLock::NONE);
int GetOpenCount(AutoLock::Type locktype = AutoLock::NONE) const;
@ -140,7 +140,7 @@ class FdEntity
off_t BytesModified();
int RowFlush(int fd, const char* tpath, AutoLock::Type type, bool force_sync = false);
int Flush(int fd, AutoLock::Type type, bool force_sync = false) { return RowFlush(fd, NULL, type, force_sync); }
int Flush(int fd, AutoLock::Type type, bool force_sync = false) { return RowFlush(fd, nullptr, type, force_sync); }
ssize_t Read(int fd, char* bytes, off_t start, size_t size, bool force_load = false);
ssize_t Write(int fd, const char* bytes, off_t start, size_t size);

View File

@ -70,7 +70,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg)
// setup and make curl object
std::unique_ptr<S3fsCurl> s3fscurl(S3fsCurl::CreateParallelS3fsCurl(pthparam->path.c_str(), pthparam->upload_fd, pthparam->start, pthparam->size, pthparam->part_num, pthparam->is_copy, pthparam->petag, pthparam->upload_id, result));
if(NULL == s3fscurl.get()){
if(nullptr == s3fscurl.get()){
S3FS_PRN_ERR("failed creating s3fs curl object for uploading [path=%s][start=%lld][size=%lld][part=%d]", pthparam->path.c_str(), static_cast<long long>(pthparam->start), static_cast<long long>(pthparam->size), pthparam->part_num);
// set result for exiting
@ -355,7 +355,7 @@ bool PseudoFdInfo::AppendUploadPart(off_t start, off_t size, bool is_copy, etagp
int partnumber = static_cast<int>(upload_list.size()) + 1;
// add new part
etagpair* petag_entity = etag_entities.add(etagpair(NULL, partnumber)); // [NOTE] Create the etag entity and register it in the list.
etagpair* petag_entity = etag_entities.add(etagpair(nullptr, partnumber)); // [NOTE] Create the etag entity and register it in the list.
filepart newpart(false, physical_fd, start, size, is_copy, petag_entity);
upload_list.push_back(newpart);
@ -391,7 +391,7 @@ bool PseudoFdInfo::InsertUploadPart(off_t start, off_t size, int part_num, bool
AutoLock auto_lock(&upload_list_lock, type);
// insert new part
etagpair* petag_entity = etag_entities.add(etagpair(NULL, part_num));
etagpair* petag_entity = etag_entities.add(etagpair(nullptr, part_num));
filepart newpart(false, physical_fd, start, size, is_copy, petag_entity);
upload_list.push_back(newpart);
@ -424,7 +424,7 @@ bool PseudoFdInfo::ParallelMultipartUpload(const char* path, const mp_part_list_
for(mp_part_list_t::const_iterator iter = mplist.begin(); iter != mplist.end(); ++iter){
// Insert upload part
etagpair* petag = NULL;
etagpair* petag = nullptr;
if(!InsertUploadPart(iter->start, iter->size, iter->part_num, is_copy, &petag, AutoLock::ALREADY_LOCKED)){
S3FS_PRN_ERR("Failed to insert insert upload part(path=%s, start=%lld, size=%lld, part=%d, copy=%s) to mplist", SAFESTRPTR(path), static_cast<long long int>(iter->start), static_cast<long long int>(iter->size), iter->part_num, (is_copy ? "true" : "false"));
return false;
@ -503,7 +503,7 @@ ssize_t PseudoFdInfo::UploadBoundaryLastUntreatedArea(const char* path, headers_
S3FS_PRN_DBG("[path=%s][pseudo_fd=%d][physical_fd=%d]", SAFESTRPTR(path), pseudo_fd, physical_fd);
if(!path || -1 == physical_fd || -1 == pseudo_fd || !pfdent){
S3FS_PRN_ERR("pseudo_fd(%d) to physical_fd(%d) for path(%s) is not opened or not writable, or pfdent is NULL.", pseudo_fd, physical_fd, path);
S3FS_PRN_ERR("pseudo_fd(%d) to physical_fd(%d) for path(%s) is not opened or not writable, or pfdent is nullptr.", pseudo_fd, physical_fd, path);
return -EBADF;
}
AutoLock auto_lock(&upload_list_lock);

View File

@ -48,7 +48,7 @@ struct pseudofdinfo_thparam
int part_num;
etagpair* petag;
pseudofdinfo_thparam() : ppseudofdinfo(NULL), path(""), upload_id(""), upload_fd(-1), start(0), size(0), is_copy(false), part_num(-1), petag(NULL) {}
pseudofdinfo_thparam() : ppseudofdinfo(nullptr), path(""), upload_id(""), upload_fd(-1), start(0), size(0), is_copy(false), part_num(-1), petag(nullptr) {}
};
//------------------------------------------------
@ -107,7 +107,7 @@ class PseudoFdInfo
bool GetUploadId(std::string& id) const;
bool GetEtaglist(etaglist_t& list) const;
bool AppendUploadPart(off_t start, off_t size, bool is_copy = false, etagpair** ppetag = NULL);
bool AppendUploadPart(off_t start, off_t size, bool is_copy = false, etagpair** ppetag = nullptr);
bool ParallelMultipartUploadAll(const char* path, const mp_part_list_t& upload_list, const mp_part_list_t& copy_list, int& result);

View File

@ -73,7 +73,7 @@ static void raw_compress_fdpage_list(const fdpage_list_t& pages, fdpage_list_t&
{
compressed_pages.clear();
fdpage* lastpage = NULL;
fdpage* lastpage = nullptr;
fdpage_list_t::iterator add_iter;
for(fdpage_list_t::const_iterator iter = pages.begin(); iter != pages.end(); ++iter){
if(0 == iter->bytes){
@ -398,7 +398,7 @@ off_t PageList::Size() const
bool PageList::Compress()
{
fdpage* lastpage = NULL;
fdpage* lastpage = nullptr;
for(fdpage_list_t::iterator iter = pages.begin(); iter != pages.end(); ){
if(!lastpage){
// First item

View File

@ -44,7 +44,7 @@ class CacheFileStat
static bool DeleteCacheFileStatDirectory();
static bool RenameCacheFileStat(const char* oldpath, const char* newpath);
explicit CacheFileStat(const char* tpath = NULL);
explicit CacheFileStat(const char* tpath = nullptr);
~CacheFileStat();
bool Open();

View File

@ -75,7 +75,7 @@ bool s3fs_init_global_ssl()
return false;
}
#ifndef USE_GNUTLS_NETTLE
if(NULL == gcry_check_version(NULL)){
if(nullptr == gcry_check_version(nullptr)){
return false;
}
#endif // USE_GNUTLS_NETTLE
@ -154,7 +154,7 @@ bool s3fs_HMAC(const void* key, size_t keylen, const unsigned char* data, size_t
*digest = new unsigned char[*digestlen + 1];
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, *digest)){
delete[] *digest;
*digest = NULL;
*digest = nullptr;
return false;
}
return true;
@ -172,7 +172,7 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz
*digest = new unsigned char[*digestlen + 1];
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, *digest)){
delete[] *digest;
*digest = NULL;
*digest = nullptr;
return false;
}
return true;
@ -198,7 +198,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
@ -216,7 +216,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
}else if(-1 == bytes){
// error
S3FS_PRN_ERR("file read error(%d)", errno);
return NULL;
return nullptr;
}
md5_update(&ctx_md5, bytes, buf);
}
@ -238,14 +238,14 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_md5, GCRY_MD_MD5, 0))){
S3FS_PRN_ERR("MD5 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err));
return NULL;
return nullptr;
}
for(off_t total = 0; total < size; total += bytes){
@ -260,7 +260,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
// error
S3FS_PRN_ERR("file read error(%d)", errno);
gcry_md_close(ctx_md5);
return NULL;
return nullptr;
}
gcry_md_write(ctx_md5, buf, bytes);
}
@ -314,7 +314,7 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
}else if(-1 == bytes){
// error
S3FS_PRN_ERR("file read error(%d)", errno);
return NULL;
return nullptr;
}
sha256_update(&ctx_sha256, bytes, buf);
}
@ -355,14 +355,14 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_sha256, GCRY_MD_SHA256, 0))){
S3FS_PRN_ERR("SHA256 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err));
return NULL;
return nullptr;
}
for(off_t total = 0; total < size; total += bytes){
@ -377,7 +377,7 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
// error
S3FS_PRN_ERR("file read error(%d)", errno);
gcry_md_close(ctx_sha256);
return NULL;
return nullptr;
}
gcry_md_write(ctx_sha256, buf, bytes);
}

View File

@ -65,7 +65,7 @@ static bool abort_incomp_mpu_list(incomp_mpu_list_t& list, time_t abort_time)
if(list.empty()){
return true;
}
time_t now_time = time(NULL);
time_t now_time = time(nullptr);
// do removing.
S3fsCurl s3fscurl;
@ -116,7 +116,7 @@ int s3fs_utility_processing(time_t abort_time)
S3FS_PRN_DBG("response body = {\n%s\n}", body.c_str());
xmlDocPtr doc;
if(NULL == (doc = xmlReadMemory(body.c_str(), static_cast<int>(body.size()), "", NULL, 0))){
if(nullptr == (doc = xmlReadMemory(body.c_str(), static_cast<int>(body.size()), "", nullptr, 0))){
S3FS_PRN_DBG("xmlReadMemory exited with error.");
result = EXIT_FAILURE;

View File

@ -34,17 +34,17 @@ MVNODE *create_mvnode(const char *old_path, const char *new_path, bool is_dir, b
char *p_old_path;
char *p_new_path;
if(NULL == (p_old_path = strdup(old_path))){
if(nullptr == (p_old_path = strdup(old_path))){
printf("create_mvnode: could not allocation memory for p_old_path\n");
S3FS_FUSE_EXIT();
return NULL;
return nullptr;
}
if(NULL == (p_new_path = strdup(new_path))){
if(nullptr == (p_new_path = strdup(new_path))){
free(p_old_path);
printf("create_mvnode: could not allocation memory for p_new_path\n");
S3FS_FUSE_EXIT();
return NULL;
return nullptr;
}
p = new MVNODE();
@ -52,8 +52,8 @@ MVNODE *create_mvnode(const char *old_path, const char *new_path, bool is_dir, b
p->new_path = p_new_path;
p->is_dir = is_dir;
p->is_normdir = normdir;
p->prev = NULL;
p->next = NULL;
p->prev = nullptr;
p->next = nullptr;
return p;
}
@ -63,7 +63,7 @@ MVNODE *create_mvnode(const char *old_path, const char *new_path, bool is_dir, b
MVNODE *add_mvnode(MVNODE** head, MVNODE** tail, const char *old_path, const char *new_path, bool is_dir, bool normdir)
{
if(!head || !tail){
return NULL;
return nullptr;
}
MVNODE* cur;
@ -85,8 +85,8 @@ MVNODE *add_mvnode(MVNODE** head, MVNODE** tail, const char *old_path, const cha
// Add into before cur-pos.
// ex: cur("abc"), mvnew("ab")
// ex: cur("abc"), mvnew("abb")
if(NULL == (mvnew = create_mvnode(old_path, new_path, is_dir, normdir))){
return NULL;
if(nullptr == (mvnew = create_mvnode(old_path, new_path, is_dir, normdir))){
return nullptr;
}
if(cur->prev){
(cur->prev)->next = mvnew;
@ -102,8 +102,8 @@ MVNODE *add_mvnode(MVNODE** head, MVNODE** tail, const char *old_path, const cha
}
}
// Add into tail.
if(NULL == (mvnew = create_mvnode(old_path, new_path, is_dir, normdir))){
return NULL;
if(nullptr == (mvnew = create_mvnode(old_path, new_path, is_dir, normdir))){
return nullptr;
}
mvnew->prev = (*tail);
if(*tail){
@ -121,7 +121,7 @@ void free_mvnodes(MVNODE *head)
MVNODE *my_head;
MVNODE *next;
for(my_head = head, next = NULL; my_head; my_head = next){
for(my_head = head, next = nullptr; my_head; my_head = next){
next = my_head->next;
free(my_head->old_path);
free(my_head->new_path);

View File

@ -56,7 +56,7 @@ bool s3fs_init_global_ssl()
{
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
if(SECSuccess != NSS_NoDB_Init(NULL)){
if(SECSuccess != NSS_NoDB_Init(nullptr)){
S3FS_PRN_ERR("Failed NSS_NoDB_Init call.");
return false;
}
@ -98,16 +98,16 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d
PK11Context* Context;
unsigned char tmpdigest[64];
SECItem KeySecItem = {siBuffer, reinterpret_cast<unsigned char*>(const_cast<void*>(key)), static_cast<unsigned int>(keylen)};
SECItem NullSecItem = {siBuffer, NULL, 0};
SECItem NullSecItem = {siBuffer, nullptr, 0};
if(NULL == (Slot = PK11_GetInternalKeySlot())){
if(nullptr == (Slot = PK11_GetInternalKeySlot())){
return false;
}
if(NULL == (pKey = PK11_ImportSymKey(Slot, (is_sha256 ? CKM_SHA256_HMAC : CKM_SHA_1_HMAC), PK11_OriginUnwrap, CKA_SIGN, &KeySecItem, NULL))){
if(nullptr == (pKey = PK11_ImportSymKey(Slot, (is_sha256 ? CKM_SHA256_HMAC : CKM_SHA_1_HMAC), PK11_OriginUnwrap, CKA_SIGN, &KeySecItem, nullptr))){
PK11_FreeSlot(Slot);
return false;
}
if(NULL == (Context = PK11_CreateContextBySymKey((is_sha256 ? CKM_SHA256_HMAC : CKM_SHA_1_HMAC), CKA_SIGN, pKey, &NullSecItem))){
if(nullptr == (Context = PK11_CreateContextBySymKey((is_sha256 ? CKM_SHA256_HMAC : CKM_SHA_1_HMAC), CKA_SIGN, pKey, &NullSecItem))){
PK11_FreeSymKey(pKey);
PK11_FreeSlot(Slot);
return false;
@ -161,7 +161,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
@ -180,7 +180,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
// error
S3FS_PRN_ERR("file read error(%d)", errno);
PK11_DestroyContext(md5ctx, PR_TRUE);
return NULL;
return nullptr;
}
PK11_DigestOp(md5ctx, buf, bytes);
}
@ -226,7 +226,7 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
@ -245,7 +245,7 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
// error
S3FS_PRN_ERR("file read error(%d)", errno);
PK11_DestroyContext(sha256ctx, PR_TRUE);
return NULL;
return nullptr;
}
PK11_DigestOp(sha256ctx, buf, bytes);
}

View File

@ -79,7 +79,7 @@ struct CRYPTO_dynlock_value
pthread_mutex_t dyn_mutex;
};
static pthread_mutex_t* s3fs_crypt_mutex = NULL;
static pthread_mutex_t* s3fs_crypt_mutex = nullptr;
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line) __attribute__ ((unused));
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line)
@ -120,7 +120,7 @@ static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int l
int result;
if(0 != (result = pthread_mutex_init(&(dyndata->dyn_mutex), &attr))){
S3FS_PRN_CRIT("pthread_mutex_init returned: %d", result);
return NULL;
return nullptr;
}
return dyndata;
}
@ -160,7 +160,7 @@ static void s3fs_destroy_dyn_crypt_mutex(struct CRYPTO_dynlock_value* dyndata, c
bool s3fs_init_crypt_mutex()
{
if(s3fs_crypt_mutex){
S3FS_PRN_DBG("s3fs_crypt_mutex is not NULL, destroy it.");
S3FS_PRN_DBG("s3fs_crypt_mutex is not nullptr, destroy it.");
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress knownConditionTrueFalse
@ -199,11 +199,11 @@ bool s3fs_destroy_crypt_mutex()
return true;
}
CRYPTO_set_dynlock_destroy_callback(NULL);
CRYPTO_set_dynlock_lock_callback(NULL);
CRYPTO_set_dynlock_create_callback(NULL);
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
CRYPTO_set_dynlock_destroy_callback(nullptr);
CRYPTO_set_dynlock_lock_callback(nullptr);
CRYPTO_set_dynlock_create_callback(nullptr);
CRYPTO_set_id_callback(nullptr);
CRYPTO_set_locking_callback(nullptr);
for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){
int result = pthread_mutex_destroy(&s3fs_crypt_mutex[cnt]);
@ -214,7 +214,7 @@ bool s3fs_destroy_crypt_mutex()
}
CRYPTO_cleanup_all_ex_data();
delete[] s3fs_crypt_mutex;
s3fs_crypt_mutex = NULL;
s3fs_crypt_mutex = nullptr;
return true;
}
@ -271,14 +271,14 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
// instead of MD5_Init
mdctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(mdctx, EVP_md5(), NULL);
EVP_DigestInit_ex(mdctx, EVP_md5(), nullptr);
for(off_t total = 0; total < size; total += bytes){
const off_t len = 512;
@ -292,7 +292,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
// error
S3FS_PRN_ERR("file read error(%d)", errno);
EVP_MD_CTX_free(mdctx);
return NULL;
return nullptr;
}
// instead of MD5_Update
EVP_DigestUpdate(mdctx, buf, bytes);
@ -324,7 +324,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
return NULL;
return nullptr;
}
size = st.st_size;
}
@ -342,7 +342,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
}else if(-1 == bytes){
// error
S3FS_PRN_ERR("file read error(%d)", errno);
return NULL;
return nullptr;
}
MD5_Update(&md5ctx, buf, bytes);
}
@ -369,7 +369,7 @@ bool s3fs_sha256(const unsigned char* data, size_t datalen, unsigned char** dige
const EVP_MD* md = EVP_get_digestbyname("sha256");
EVP_MD_CTX* mdctx = EVP_MD_CTX_create();
EVP_DigestInit_ex(mdctx, md, NULL);
EVP_DigestInit_ex(mdctx, md, nullptr);
EVP_DigestUpdate(mdctx, data, datalen);
EVP_DigestFinal_ex(mdctx, *digest, digestlen);
EVP_MD_CTX_destroy(mdctx);
@ -385,19 +385,19 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
unsigned char* result;
if(-1 == fd){
return NULL;
return nullptr;
}
if(-1 == size){
struct stat st;
if(-1 == fstat(fd, &st)){
S3FS_PRN_ERR("fstat error(%d)", errno);
return NULL;
return nullptr;
}
size = st.st_size;
}
sha256ctx = EVP_MD_CTX_create();
EVP_DigestInit_ex(sha256ctx, md, NULL);
EVP_DigestInit_ex(sha256ctx, md, nullptr);
for(off_t total = 0; total < size; total += bytes){
const off_t len = 512;
@ -411,12 +411,12 @@ unsigned char* s3fs_sha256_fd(int fd, off_t start, off_t size)
// error
S3FS_PRN_ERR("file read error(%d)", errno);
EVP_MD_CTX_destroy(sha256ctx);
return NULL;
return nullptr;
}
EVP_DigestUpdate(sha256ctx, buf, bytes);
}
result = new unsigned char[get_sha256_digest_length()];
EVP_DigestFinal_ex(sha256ctx, result, NULL);
EVP_DigestFinal_ex(sha256ctx, result, nullptr);
EVP_MD_CTX_destroy(sha256ctx);
return result;

View File

@ -76,7 +76,7 @@ static mode_t mp_mode = 0; // mode of mount point
static mode_t mp_umask = 0; // umask for mount point
static bool is_mp_umask = false;// default does not set.
static std::string mountpoint;
static S3fsCred* ps3fscred = NULL; // using only in this file
static S3fsCred* ps3fscred = nullptr; // using only in this file
static std::string mimetype_file;
static bool nocopyapi = false;
static bool norenameapi = false;
@ -112,9 +112,9 @@ int put_headers(const char* path, headers_t& meta, bool is_copy, bool use_st_siz
// Static functions : prototype
//-------------------------------------------------------------------
static bool is_special_name_folder_object(const char* path);
static int chk_dir_object_type(const char* path, std::string& newpath, std::string& nowpath, std::string& nowcache, headers_t* pmeta = NULL, dirtype* pDirType = NULL);
static int chk_dir_object_type(const char* path, std::string& newpath, std::string& nowpath, std::string& nowcache, headers_t* pmeta = nullptr, dirtype* pDirType = nullptr);
static int remove_old_type_dir(const std::string& path, dirtype type);
static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t* pmeta = NULL, bool overcheck = true, bool* pisforce = NULL, bool add_no_truncate_cache = false);
static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t* pmeta = nullptr, bool overcheck = true, bool* pisforce = nullptr, bool add_no_truncate_cache = false);
static int check_object_access(const char* path, int mask, struct stat* pstbuf);
static int check_object_owner(const char* path, struct stat* pstbuf);
static int check_parent_object_access(const char* path, int mask);
@ -256,7 +256,7 @@ bool MpStatFlag::Set(bool flag)
}
// whether the stat information file for mount point exists
static MpStatFlag* pHasMpStat = NULL;
static MpStatFlag* pHasMpStat = nullptr;
//
// A synchronous class that calls the fuse_fill_dir_t function that processes the readdir data
@ -271,7 +271,7 @@ class SyncFiller
std::set<std::string> filled;
public:
explicit SyncFiller(void* buff = NULL, fuse_fill_dir_t filler = NULL);
explicit SyncFiller(void* buff = nullptr, fuse_fill_dir_t filler = nullptr);
~SyncFiller();
int Fill(const char *name, const struct stat *stbuf, off_t off);
@ -332,7 +332,7 @@ int SyncFiller::SufficiencyFill(const std::vector<std::string>& pathlist)
int result = 0;
for(std::vector<std::string>::const_iterator it = pathlist.begin(); it != pathlist.end(); ++it) {
if(filled.insert(*it).second){
if(0 != filler_func(filler_buff, it->c_str(), 0, 0)){
if(0 != filler_func(filler_buff, it->c_str(), nullptr, 0)){
result = 1;
}
}
@ -425,7 +425,7 @@ static int chk_dir_object_type(const char* path, std::string& newpath, std::stri
}
// Always check "dir/" at first.
if(0 == (result = get_object_attribute(newpath.c_str(), NULL, pmeta, false, &isforce))){
if(0 == (result = get_object_attribute(newpath.c_str(), nullptr, pmeta, false, &isforce))){
// Found "dir/" cache --> Check for "_$folder$", "no dir object"
nowcache = newpath;
if(is_special_name_folder_object(newpath.c_str())){ // check support_compat_dir in this function
@ -450,7 +450,7 @@ static int chk_dir_object_type(const char* path, std::string& newpath, std::stri
}else if(support_compat_dir){
// Check "dir" when support_compat_dir is enabled
nowpath.erase(newpath.length() - 1);
if(0 == (result = get_object_attribute(nowpath.c_str(), NULL, pmeta, false, &isforce))){
if(0 == (result = get_object_attribute(nowpath.c_str(), nullptr, pmeta, false, &isforce))){
// Found "dir" cache --> this case is only "dir" type.
// Because, if object is "_$folder$" or "no dir object", the cache is "dir/" type.
// (But "no dir object" is checked here.)
@ -555,7 +555,7 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t
}
// Check cache.
pisforce = (NULL != pisforce ? pisforce : &forcedir);
pisforce = (nullptr != pisforce ? pisforce : &forcedir);
(*pisforce) = false;
strpath = path;
if(support_compat_dir && overcheck && std::string::npos != (Pos = strpath.find("_$folder$", 0))){
@ -759,7 +759,7 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t
//
// path: the target object path
// mask: bit field(F_OK, R_OK, W_OK, X_OK) like access().
// stat: NULL or the pointer of struct stat.
// stat: nullptr or the pointer of struct stat.
//
static int check_object_access(const char* path, int mask, struct stat* pstbuf)
{
@ -770,7 +770,7 @@ static int check_object_access(const char* path, int mask, struct stat* pstbuf)
S3FS_PRN_DBG("[path=%s]", path);
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
S3FS_PRN_DBG("[pid=%u,uid=%u,gid=%u]", (unsigned int)(pcxt->pid), (unsigned int)(pcxt->uid), (unsigned int)(pcxt->gid));
@ -846,7 +846,7 @@ static int check_object_owner(const char* path, struct stat* pstbuf)
S3FS_PRN_DBG("[path=%s]", path);
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
if(0 != (result = get_object_attribute(path, pst))){
@ -887,7 +887,7 @@ static int check_parent_object_access(const char* path, int mask)
if(parent == "."){
parent = "/";
}
if(0 != (result = check_object_access(parent.c_str(), X_OK, NULL))){
if(0 != (result = check_object_access(parent.c_str(), X_OK, nullptr))){
return result;
}
if(parent == "/" || parent == "."){
@ -901,7 +901,7 @@ static int check_parent_object_access(const char* path, int mask)
if(parent == "."){
parent = "/";
}
if(0 != (result = check_object_access(parent.c_str(), mask, NULL))){
if(0 != (result = check_object_access(parent.c_str(), mask, nullptr))){
return result;
}
}
@ -918,7 +918,7 @@ bool get_object_sse_type(const char* path, sse_type_t& ssetype, std::string& sse
}
headers_t meta;
if(0 != get_object_attribute(path, NULL, &meta)){
if(0 != get_object_attribute(path, nullptr, &meta)){
S3FS_PRN_ERR("Failed to get object(%s) headers", path);
return false;
}
@ -962,7 +962,7 @@ static int get_local_fent(AutoFdEntity& autoent, FdEntity **entity, const char*
}
bool force_tmpfile = S_ISREG(stobj.st_mode) ? false : true;
if(NULL == (ent = autoent.Open(path, &meta, stobj.st_size, st_mctime, flags, force_tmpfile, true, false, AutoLock::NONE))){
if(nullptr == (ent = autoent.Open(path, &meta, stobj.st_size, st_mctime, flags, force_tmpfile, true, false, AutoLock::NONE))){
S3FS_PRN_ERR("Could not open file. errno(%d)", errno);
return -EIO;
}
@ -1038,7 +1038,7 @@ static int s3fs_getattr(const char* _path, struct stat* stbuf)
if(stbuf){
AutoFdEntity autoent;
FdEntity* ent;
if(NULL != (ent = autoent.OpenExistFdEntity(path))){
if(nullptr != (ent = autoent.OpenExistFdEntity(path))){
struct stat tmpstbuf;
if(ent->GetStats(tmpstbuf)){
stbuf->st_size = tmpstbuf.st_size;
@ -1140,7 +1140,7 @@ static int s3fs_mknod(const char *_path, mode_t mode, dev_t rdev)
S3FS_PRN_INFO("[path=%s][mode=%04o][dev=%llu]", path, mode, (unsigned long long)rdev);
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
@ -1169,7 +1169,7 @@ static int s3fs_create(const char* _path, mode_t mode, struct fuse_file_info* fi
S3FS_PRN_INFO("[path=%s][mode=%04o][flags=0x%x]", path, mode, fi->flags);
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
@ -1177,7 +1177,7 @@ static int s3fs_create(const char* _path, mode_t mode, struct fuse_file_info* fi
if(0 != (result = check_parent_object_access(path, X_OK))){
return result;
}
result = check_object_access(path, W_OK, NULL);
result = check_object_access(path, W_OK, nullptr);
if(-ENOENT == result){
if(0 != (result = check_parent_object_access(path, W_OK))){
return result;
@ -1216,7 +1216,7 @@ static int s3fs_create(const char* _path, mode_t mode, struct fuse_file_info* fi
AutoFdEntity autoent;
FdEntity* ent;
if(NULL == (ent = autoent.Open(path, &meta, 0, S3FS_OMIT_TS, fi->flags, false, true, false, AutoLock::NONE))){
if(nullptr == (ent = autoent.Open(path, &meta, 0, S3FS_OMIT_TS, fi->flags, false, true, false, AutoLock::NONE))){
StatCache::getStatCacheData()->DelStat(path);
return -EIO;
}
@ -1267,7 +1267,7 @@ static int s3fs_mkdir(const char* _path, mode_t mode)
S3FS_PRN_INFO("[path=%s][mode=%04o]", path, mode);
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
@ -1275,7 +1275,7 @@ static int s3fs_mkdir(const char* _path, mode_t mode)
if(0 != (result = check_parent_object_access(path, W_OK | X_OK))){
return result;
}
if(-ENOENT != (result = check_object_access(path, F_OK, NULL))){
if(-ENOENT != (result = check_object_access(path, F_OK, nullptr))){
if(0 == result){
result = -EEXIST;
}
@ -1287,7 +1287,7 @@ static int s3fs_mkdir(const char* _path, mode_t mode)
if(get_parent_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
struct timespec now;
@ -1384,7 +1384,7 @@ static int s3fs_rmdir(const char* _path)
if('/' == *strpath.rbegin()){
strpath.erase(strpath.length() - 1);
}
if(0 == get_object_attribute(strpath.c_str(), &stbuf, NULL, false)){
if(0 == get_object_attribute(strpath.c_str(), &stbuf, nullptr, false)){
if(S_ISDIR(stbuf.st_mode)){
// Found "dir" object.
result = s3fscurl.DeleteRequest(strpath.c_str());
@ -1422,13 +1422,13 @@ static int s3fs_symlink(const char* _from, const char* _to)
S3FS_PRN_INFO("[from=%s][to=%s]", from, to);
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
if(0 != (result = check_parent_object_access(to, W_OK | X_OK))){
return result;
}
if(-ENOENT != (result = check_object_access(to, F_OK, NULL))){
if(-ENOENT != (result = check_object_access(to, F_OK, nullptr))){
if(0 == result){
result = -EEXIST;
}
@ -1453,7 +1453,7 @@ static int s3fs_symlink(const char* _from, const char* _to)
{ // scope for AutoFdEntity
AutoFdEntity autoent;
FdEntity* ent;
if(NULL == (ent = autoent.Open(to, &headers, 0, S3FS_OMIT_TS, O_RDWR, true, true, false, AutoLock::NONE))){
if(nullptr == (ent = autoent.Open(to, &headers, 0, S3FS_OMIT_TS, O_RDWR, true, true, false, AutoLock::NONE))){
S3FS_PRN_ERR("could not open tmpfile(errno=%d)", errno);
return -errno;
}
@ -1535,7 +1535,7 @@ static int rename_object(const char* from, const char* to, bool update_ctime)
// update time
AutoFdEntity autoent;
FdEntity* ent;
if(NULL == (ent = autoent.OpenExistFdEntity(from))){
if(nullptr == (ent = autoent.OpenExistFdEntity(from))){
// no opened fd
// get mtime/ctime/atime from meta
@ -1723,8 +1723,8 @@ static int rename_directory(const char* from, const char* to)
std::string nowcache; // now cache path(not used)
dirtype DirType;
bool normdir;
MVNODE* mn_head = NULL;
MVNODE* mn_tail = NULL;
MVNODE* mn_head = nullptr;
MVNODE* mn_tail = nullptr;
MVNODE* mn_cur;
struct stat stbuf;
int result;
@ -1736,14 +1736,14 @@ static int rename_directory(const char* from, const char* to)
// Initiate and Add base directory into MVNODE struct.
//
strto += "/";
if(0 == chk_dir_object_type(from, newpath, strfrom, nowcache, NULL, &DirType) && DIRTYPE_UNKNOWN != DirType){
if(0 == chk_dir_object_type(from, newpath, strfrom, nowcache, nullptr, &DirType) && DIRTYPE_UNKNOWN != DirType){
if(DIRTYPE_NOOBJ != DirType){
normdir = false;
}else{
normdir = true;
strfrom = from; // from directory is not removed, but from directory attr is needed.
}
if(NULL == (add_mvnode(&mn_head, &mn_tail, strfrom.c_str(), strto.c_str(), true, normdir))){
if(nullptr == (add_mvnode(&mn_head, &mn_tail, strfrom.c_str(), strto.c_str(), true, normdir))){
return -ENOMEM;
}
}else{
@ -1755,7 +1755,7 @@ static int rename_directory(const char* from, const char* to)
//
// No delimiter is specified, the result(head) is all object keys.
// (CommonPrefixes is empty, but all object is listed in Key.)
if(0 != (result = list_bucket(basepath.c_str(), head, NULL))){
if(0 != (result = list_bucket(basepath.c_str(), head, nullptr))){
S3FS_PRN_ERR("list_bucket returns error.");
return result;
}
@ -1771,13 +1771,13 @@ static int rename_directory(const char* from, const char* to)
// Check subdirectory.
StatCache::getStatCacheData()->HasStat(from_name, etag.c_str()); // Check ETag
if(0 != get_object_attribute(from_name.c_str(), &stbuf, NULL)){
if(0 != get_object_attribute(from_name.c_str(), &stbuf, nullptr)){
S3FS_PRN_WARN("failed to get %s object attribute.", from_name.c_str());
continue;
}
if(S_ISDIR(stbuf.st_mode)){
is_dir = true;
if(0 != chk_dir_object_type(from_name.c_str(), newpath, from_name, nowcache, NULL, &DirType) || DIRTYPE_UNKNOWN == DirType){
if(0 != chk_dir_object_type(from_name.c_str(), newpath, from_name, nowcache, nullptr, &DirType) || DIRTYPE_UNKNOWN == DirType){
S3FS_PRN_WARN("failed to get %s%s object directory type.", basepath.c_str(), (*liter).c_str());
continue;
}
@ -1793,7 +1793,7 @@ static int rename_directory(const char* from, const char* to)
}
// push this one onto the stack
if(NULL == add_mvnode(&mn_head, &mn_tail, from_name.c_str(), to_name.c_str(), is_dir, normdir)){
if(nullptr == add_mvnode(&mn_head, &mn_tail, from_name.c_str(), to_name.c_str(), is_dir, normdir)){
return -ENOMEM;
}
}
@ -1809,7 +1809,7 @@ static int rename_directory(const char* from, const char* to)
if(get_meta_xattr_value(mn_cur->old_path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
// [NOTE]
@ -1878,7 +1878,7 @@ static int s3fs_rename(const char* _from, const char* _to)
// not permit removing "from" object parent dir.
return result;
}
if(0 != (result = get_object_attribute(from, &buf, NULL))){
if(0 != (result = get_object_attribute(from, &buf, nullptr))){
return result;
}
if(0 != (result = directory_empty(to))){
@ -1889,7 +1889,7 @@ static int s3fs_rename(const char* _from, const char* _to)
{ // scope for AutoFdEntity
AutoFdEntity autoent;
FdEntity* ent;
if(NULL != (ent = autoent.OpenExistFdEntity(from, O_RDWR))){
if(nullptr != (ent = autoent.OpenExistFdEntity(from, O_RDWR))){
if(0 != (result = ent->Flush(autoent.GetPseudoFd(), AutoLock::NONE, true))){
S3FS_PRN_ERR("could not upload file(%s): result=%d", to, result);
return result;
@ -1959,7 +1959,7 @@ static int s3fs_chmod(const char* _path, mode_t mode)
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, &meta);
result = get_object_attribute(strpath.c_str(), nullptr, &meta);
}
if(0 != result){
return result;
@ -1971,7 +1971,7 @@ static int s3fs_chmod(const char* _path, mode_t mode)
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
if(IS_REPLACEDIR(nDirType)){
// Should rebuild directory object(except new type)
@ -2013,7 +2013,7 @@ static int s3fs_chmod(const char* _path, mode_t mode)
AutoFdEntity autoent;
FdEntity* ent;
bool need_put_header = true;
if(NULL != (ent = autoent.OpenExistFdEntity(path))){
if(nullptr != (ent = autoent.OpenExistFdEntity(path))){
if(ent->MergeOrgMeta(updatemeta)){
// meta is changed, but now uploading.
// then the meta is pending and accumulated to be put after the upload is complete.
@ -2061,11 +2061,11 @@ static int s3fs_chmod_nocopy(const char* _path, mode_t mode)
// Get attributes
if(S_ISDIR(stbuf.st_mode)){
result = chk_dir_object_type(path, newpath, strpath, nowcache, NULL, &nDirType);
result = chk_dir_object_type(path, newpath, strpath, nowcache, nullptr, &nDirType);
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, NULL);
result = get_object_attribute(strpath.c_str(), nullptr, nullptr);
}
if(0 != result){
return result;
@ -2077,7 +2077,7 @@ static int s3fs_chmod_nocopy(const char* _path, mode_t mode)
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
if(IS_REPLACEDIR(nDirType)){
@ -2163,7 +2163,7 @@ static int s3fs_chown(const char* _path, uid_t uid, gid_t gid)
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, &meta);
result = get_object_attribute(strpath.c_str(), nullptr, &meta);
}
if(0 != result){
return result;
@ -2175,7 +2175,7 @@ static int s3fs_chown(const char* _path, uid_t uid, gid_t gid)
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
if(IS_REPLACEDIR(nDirType)){
@ -2218,7 +2218,7 @@ static int s3fs_chown(const char* _path, uid_t uid, gid_t gid)
AutoFdEntity autoent;
FdEntity* ent;
bool need_put_header = true;
if(NULL != (ent = autoent.OpenExistFdEntity(path))){
if(nullptr != (ent = autoent.OpenExistFdEntity(path))){
if(ent->MergeOrgMeta(updatemeta)){
// meta is changed, but now uploading.
// then the meta is pending and accumulated to be put after the upload is complete.
@ -2273,11 +2273,11 @@ static int s3fs_chown_nocopy(const char* _path, uid_t uid, gid_t gid)
// Get attributes
if(S_ISDIR(stbuf.st_mode)){
result = chk_dir_object_type(path, newpath, strpath, nowcache, NULL, &nDirType);
result = chk_dir_object_type(path, newpath, strpath, nowcache, nullptr, &nDirType);
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, NULL);
result = get_object_attribute(strpath.c_str(), nullptr, nullptr);
}
if(0 != result){
return result;
@ -2289,7 +2289,7 @@ static int s3fs_chown_nocopy(const char* _path, uid_t uid, gid_t gid)
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
if(IS_REPLACEDIR(nDirType)){
@ -2418,7 +2418,7 @@ static int update_mctime_parent_directory(const char* _path)
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
// At first, remove directory old object
@ -2498,7 +2498,7 @@ static int s3fs_utimens(const char* _path, const struct timespec ts[2])
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, &meta);
result = get_object_attribute(strpath.c_str(), nullptr, &meta);
}
if(0 != result){
return result;
@ -2510,7 +2510,7 @@ static int s3fs_utimens(const char* _path, const struct timespec ts[2])
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
if(IS_REPLACEDIR(nDirType)){
@ -2547,7 +2547,7 @@ static int s3fs_utimens(const char* _path, const struct timespec ts[2])
FdEntity* ent;
bool need_put_header = true;
bool keep_mtime = false;
if(NULL != (ent = autoent.OpenExistFdEntity(path))){
if(nullptr != (ent = autoent.OpenExistFdEntity(path))){
if(ent->MergeOrgMeta(updatemeta)){
// meta is changed, but now uploading.
// then the meta is pending and accumulated to be put after the upload is complete.
@ -2626,11 +2626,11 @@ static int s3fs_utimens_nocopy(const char* _path, const struct timespec ts[2])
// Get attributes
if(S_ISDIR(stbuf.st_mode)){
result = chk_dir_object_type(path, newpath, strpath, nowcache, NULL, &nDirType);
result = chk_dir_object_type(path, newpath, strpath, nowcache, nullptr, &nDirType);
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, NULL);
result = get_object_attribute(strpath.c_str(), nullptr, nullptr);
}
if(0 != result){
return result;
@ -2642,7 +2642,7 @@ static int s3fs_utimens_nocopy(const char* _path, const struct timespec ts[2])
if(get_meta_xattr_value(path, xattrvalue)){
pxattrvalue = xattrvalue.c_str();
}else{
pxattrvalue = NULL;
pxattrvalue = nullptr;
}
if(IS_REPLACEDIR(nDirType)){
@ -2701,7 +2701,7 @@ static int s3fs_truncate(const char* _path, off_t size)
int result;
headers_t meta;
AutoFdEntity autoent;
FdEntity* ent = NULL;
FdEntity* ent = nullptr;
S3FS_PRN_INFO("[path=%s][size=%lld]", path, static_cast<long long>(size));
@ -2712,12 +2712,12 @@ static int s3fs_truncate(const char* _path, off_t size)
if(0 != (result = check_parent_object_access(path, X_OK))){
return result;
}
if(0 != (result = check_object_access(path, W_OK, NULL))){
if(0 != (result = check_object_access(path, W_OK, nullptr))){
return result;
}
// Get file information
if(0 == (result = get_object_attribute(path, NULL, &meta))){
if(0 == (result = get_object_attribute(path, nullptr, &meta))){
// File exists
// [NOTE]
@ -2746,7 +2746,7 @@ static int s3fs_truncate(const char* _path, off_t size)
ignore_modify = true;
}
if(NULL == (ent = autoent.Open(path, &meta, size, S3FS_OMIT_TS, O_RDWR, false, true, ignore_modify, AutoLock::NONE))){
if(nullptr == (ent = autoent.Open(path, &meta, size, S3FS_OMIT_TS, O_RDWR, false, true, ignore_modify, AutoLock::NONE))){
S3FS_PRN_ERR("could not open file(%s): errno=%d", path, errno);
return -EIO;
}
@ -2769,7 +2769,7 @@ static int s3fs_truncate(const char* _path, off_t size)
}else{
// Not found -> Make tmpfile(with size)
struct fuse_context* pcxt;
if(NULL == (pcxt = fuse_get_context())){
if(nullptr == (pcxt = fuse_get_context())){
return -EIO;
}
@ -2781,7 +2781,7 @@ static int s3fs_truncate(const char* _path, off_t size)
meta["x-amz-meta-uid"] = str(pcxt->uid);
meta["x-amz-meta-gid"] = str(pcxt->gid);
if(NULL == (ent = autoent.Open(path, &meta, size, S3FS_OMIT_TS, O_RDWR, true, true, false, AutoLock::NONE))){
if(nullptr == (ent = autoent.Open(path, &meta, size, S3FS_OMIT_TS, O_RDWR, true, true, false, AutoLock::NONE))){
S3FS_PRN_ERR("could not open file(%s): errno=%d", path, errno);
return -EIO;
}
@ -2852,7 +2852,7 @@ static int s3fs_open(const char* _path, struct fuse_file_info* fi)
// if you keep the file open, shrink its size, and then read the file
// from another process while it has not yet been flushed.
//
if(NULL != (ent = autoent.OpenExistFdEntity(path)) && ent->IsModified()){
if(nullptr != (ent = autoent.OpenExistFdEntity(path)) && ent->IsModified()){
// sets the file size being edited.
ent->GetSize(st.st_size);
}
@ -2861,14 +2861,14 @@ static int s3fs_open(const char* _path, struct fuse_file_info* fi)
st.st_mtime = -1;
}
if(0 != (result = get_object_attribute(path, NULL, &meta, true, NULL, true))){ // no truncate cache
if(0 != (result = get_object_attribute(path, nullptr, &meta, true, nullptr, true))){ // no truncate cache
return result;
}
struct timespec st_mctime;
set_stat_to_timespec(st, ST_TYPE_MTIME, st_mctime);
if(NULL == (ent = autoent.Open(path, &meta, st.st_size, st_mctime, fi->flags, false, true, false, AutoLock::NONE))){
if(nullptr == (ent = autoent.Open(path, &meta, st.st_size, st_mctime, fi->flags, false, true, false, AutoLock::NONE))){
StatCache::getStatCacheData()->DelStat(path);
return -EIO;
}
@ -2900,7 +2900,7 @@ static int s3fs_read(const char* _path, char* buf, size_t size, off_t offset, st
AutoFdEntity autoent;
FdEntity* ent;
if(NULL == (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
if(nullptr == (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
S3FS_PRN_ERR("could not find opened pseudo_fd(=%llu) for path(%s)", (unsigned long long)(fi->fh), path);
return -EIO;
}
@ -2928,7 +2928,7 @@ static int s3fs_write(const char* _path, const char* buf, size_t size, off_t off
AutoFdEntity autoent;
FdEntity* ent;
if(NULL == (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
if(nullptr == (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
S3FS_PRN_ERR("could not find opened pseudo_fd(%llu) for path(%s)", (unsigned long long)(fi->fh), path);
return -EIO;
}
@ -2988,7 +2988,7 @@ static int s3fs_flush(const char* _path, struct fuse_file_info* fi)
if(0 != (result = check_parent_object_access(path, X_OK))){
return result;
}
result = check_object_access(path, mask, NULL);
result = check_object_access(path, mask, nullptr);
if(-ENOENT == result){
if(0 != (result = check_parent_object_access(path, W_OK))){
return result;
@ -2999,7 +2999,7 @@ static int s3fs_flush(const char* _path, struct fuse_file_info* fi)
AutoFdEntity autoent;
FdEntity* ent;
if(NULL != (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
if(nullptr != (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
bool is_new_file = ent->IsDirtyNewFile();
ent->UpdateMtime(true); // clear the flag not to update mtime.
@ -3032,7 +3032,7 @@ static int s3fs_fsync(const char* _path, int datasync, struct fuse_file_info* fi
AutoFdEntity autoent;
FdEntity* ent;
if(NULL != (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
if(nullptr != (ent = autoent.GetExistFdEntity(path, static_cast<int>(fi->fh)))){
bool is_new_file = ent->IsDirtyNewFile();
if(0 == datasync){
@ -3070,7 +3070,7 @@ static int s3fs_release(const char* _path, struct fuse_file_info* fi)
// destroyed here.
//
FdEntity* ent;
if(NULL == (ent = autoent.Attach(path, static_cast<int>(fi->fh)))){
if(nullptr == (ent = autoent.Attach(path, static_cast<int>(fi->fh)))){
S3FS_PRN_ERR("could not find pseudo_fd(%llu) for path(%s)", (unsigned long long)(fi->fh), path);
return -EIO;
}
@ -3139,7 +3139,7 @@ static int s3fs_opendir(const char* _path, struct fuse_file_info* fi)
S3FS_PRN_INFO("[path=%s][flags=0x%x]", path, fi->flags);
if(0 == (result = check_object_access(path, mask, NULL))){
if(0 == (result = check_object_access(path, mask, nullptr))){
result = check_parent_object_access(path, X_OK);
}
S3FS_MALLOCTRIM(0);
@ -3174,10 +3174,10 @@ static bool multi_head_callback(S3fsCurl* s3fscurl, void* param)
pcbparam->Fill(bpath.c_str(), &st, 0);
}else{
S3FS_PRN_INFO2("Could not find %s file in stat cache.", saved_path.c_str());
pcbparam->Fill(bpath.c_str(), 0, 0);
pcbparam->Fill(bpath.c_str(), nullptr, 0);
}
}else{
S3FS_PRN_WARN("param(multi_head_callback_param*) is NULL, then can not call filler.");
S3FS_PRN_WARN("param(multi_head_callback_param*) is nullptr, then can not call filler.");
}
return true;
@ -3197,7 +3197,7 @@ static bool multi_head_notfound_callback(S3fsCurl* s3fscurl, void* param)
S3FS_PRN_INFO("HEAD returned NotFound(404) for %s object, it maybe only the path exists and the object does not exist.", s3fscurl->GetPath().c_str());
if(!param){
S3FS_PRN_WARN("param(multi_head_notfound_callback_param*) is NULL, then can not call filler.");
S3FS_PRN_WARN("param(multi_head_notfound_callback_param*) is nullptr, then can not call filler.");
return false;
}
@ -3213,7 +3213,7 @@ static bool multi_head_notfound_callback(S3fsCurl* s3fscurl, void* param)
static S3fsCurl* multi_head_retry_callback(S3fsCurl* s3fscurl)
{
if(!s3fscurl){
return NULL;
return nullptr;
}
size_t ssec_key_pos= s3fscurl->GetLastPreHeadSeecKeyPos();
int retry_count = s3fscurl->GetMultipartRetryCount();
@ -3224,7 +3224,7 @@ static S3fsCurl* multi_head_retry_callback(S3fsCurl* s3fscurl)
if(0 == S3fsCurl::GetSseKeyCount() || S3fsCurl::GetSseKeyCount() <= ssec_key_pos){
if(s3fscurl->IsOverMultipartRetryCount()){
S3FS_PRN_ERR("Over retry count(%d) limit(%s).", s3fscurl->GetMultipartRetryCount(), s3fscurl->GetSpecialSavedPath().c_str());
return NULL;
return nullptr;
}
ssec_key_pos = -1;
retry_count++;
@ -3238,7 +3238,7 @@ static S3fsCurl* multi_head_retry_callback(S3fsCurl* s3fscurl)
if(!newcurl->PreHeadRequest(path, base_path, saved_path, ssec_key_pos)){
S3FS_PRN_ERR("Could not duplicate curl object(%s).", saved_path.c_str());
delete newcurl;
return NULL;
return nullptr;
}
newcurl->SetMultipartRetryCount(retry_count);
@ -3368,7 +3368,7 @@ static int readdir_multi_head(const char* path, const S3ObjList& head, void* buf
syncfiller.Fill(base_path.c_str(), &st, 0);
}else{
S3FS_PRN_INFO2("Could not find %s directory(no dir object) in stat cache.", dirpath.c_str());
syncfiller.Fill(base_path.c_str(), 0, 0);
syncfiller.Fill(base_path.c_str(), nullptr, 0);
}
}else{
S3FS_PRN_ERR("failed adding stat cache [path=%s], but dontinue...", dirpath.c_str());
@ -3390,7 +3390,7 @@ static int s3fs_readdir(const char* _path, void* buf, fuse_fill_dir_t filler, of
S3FS_PRN_INFO("[path=%s]", path);
if(0 != (result = check_object_access(path, R_OK, NULL))){
if(0 != (result = check_object_access(path, R_OK, nullptr))){
return result;
}
@ -3401,8 +3401,8 @@ static int s3fs_readdir(const char* _path, void* buf, fuse_fill_dir_t filler, of
}
// force to add "." and ".." name.
filler(buf, ".", 0, 0);
filler(buf, "..", 0, 0);
filler(buf, ".", nullptr, 0);
filler(buf, "..", nullptr, 0);
if(head.IsEmpty()){
return 0;
}
@ -3490,7 +3490,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
std::string encbody = get_encoded_cr_code(body->str());
// xmlDocPtr
if(NULL == (doc = xmlReadMemory(encbody.c_str(), static_cast<int>(encbody.size()), "", NULL, 0))){
if(nullptr == (doc = xmlReadMemory(encbody.c_str(), static_cast<int>(encbody.size()), "", nullptr, 0))){
S3FS_PRN_ERR("xmlReadMemory returns with error.");
return -EIO;
}
@ -3501,10 +3501,10 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
}
if(true == (truncated = is_truncated(doc))){
xmlChar* tmpch;
if(NULL != (tmpch = get_next_continuation_token(doc))){
if(nullptr != (tmpch = get_next_continuation_token(doc))){
next_continuation_token = reinterpret_cast<char*>(tmpch);
xmlFree(tmpch);
}else if(NULL != (tmpch = get_next_marker(doc))){
}else if(nullptr != (tmpch = get_next_marker(doc))){
next_marker = reinterpret_cast<char*>(tmpch);
xmlFree(tmpch);
}
@ -3548,7 +3548,7 @@ static int remote_mountpath_exists(const char* path, bool compat_dir)
S3FS_PRN_INFO1("[path=%s]", path);
// getattr will prefix the path with the remote mountpoint
if(0 != (result = get_object_attribute(path, &stbuf, NULL))){
if(0 != (result = get_object_attribute(path, &stbuf, nullptr))){
return result;
}
@ -3579,7 +3579,7 @@ static bool get_meta_xattr_value(const char* path, std::string& rawvalue)
rawvalue.erase();
headers_t meta;
if(0 != get_object_attribute(path, NULL, &meta)){
if(0 != get_object_attribute(path, nullptr, &meta)){
S3FS_PRN_ERR("Failed to get object(%s) headers", path);
return false;
}
@ -3744,7 +3744,7 @@ static size_t parse_xattrs(const std::string& strxattrs, xattrs_t& xattrs)
for(size_t pair_nextpos = restxattrs.find_first_of(','); !restxattrs.empty(); restxattrs = (pair_nextpos != std::string::npos ? restxattrs.substr(pair_nextpos + 1) : std::string("")), pair_nextpos = restxattrs.find_first_of(',')){
std::string pair = pair_nextpos != std::string::npos ? restxattrs.substr(0, pair_nextpos) : restxattrs;
std::string key;
PXATTRVAL pval = NULL;
PXATTRVAL pval = nullptr;
if(!parse_xattr_keyval(pair, key, pval)){
// something format error, so skip this.
continue;
@ -3834,7 +3834,7 @@ static int set_xattrs_to_header(headers_t& meta, const char* name, const char* v
pval->pvalue = new unsigned char[size];
memcpy(pval->pvalue, value, size);
}else{
pval->pvalue = NULL;
pval->pvalue = nullptr;
}
xattrs[std::string(name)] = pval;
@ -3888,7 +3888,7 @@ static int s3fs_setxattr(const char* path, const char* name, const char* value,
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, &meta);
result = get_object_attribute(strpath.c_str(), nullptr, &meta);
}
if(0 != result){
return result;
@ -3914,7 +3914,7 @@ static int s3fs_setxattr(const char* path, const char* name, const char* value,
set_stat_to_timespec(stbuf, ST_TYPE_MTIME, ts_mtime);
set_stat_to_timespec(stbuf, ST_TYPE_CTIME, ts_ctime);
if(0 != (result = create_directory_object(newpath.c_str(), stbuf.st_mode, ts_atime, ts_mtime, ts_ctime, stbuf.st_uid, stbuf.st_gid, NULL))){
if(0 != (result = create_directory_object(newpath.c_str(), stbuf.st_mode, ts_atime, ts_mtime, ts_ctime, stbuf.st_uid, stbuf.st_gid, nullptr))){
return result;
}
@ -3939,7 +3939,7 @@ static int s3fs_setxattr(const char* path, const char* name, const char* value,
AutoFdEntity autoent;
FdEntity* ent;
bool need_put_header = true;
if(NULL != (ent = autoent.OpenExistFdEntity(path))){
if(nullptr != (ent = autoent.OpenExistFdEntity(path))){
// get xattr and make new xattr
std::string strxattr;
if(ent->GetXattr(strxattr)){
@ -4014,7 +4014,7 @@ static int s3fs_getxattr(const char* path, const char* name, char* value, size_t
}
// get headers
if(0 != (result = get_object_attribute(path, NULL, &meta))){
if(0 != (result = get_object_attribute(path, nullptr, &meta))){
return result;
}
@ -4041,8 +4041,8 @@ static int s3fs_getxattr(const char* path, const char* name, char* value, size_t
// decode
size_t length = 0;
unsigned char* pvalue = NULL;
if(NULL != xiter->second){
unsigned char* pvalue = nullptr;
if(nullptr != xiter->second){
length = xiter->second->length;
pvalue = xiter->second->pvalue;
}
@ -4080,7 +4080,7 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
}
// get headers
if(0 != (result = get_object_attribute(path, NULL, &meta))){
if(0 != (result = get_object_attribute(path, nullptr, &meta))){
return result;
}
@ -4165,7 +4165,7 @@ static int s3fs_removexattr(const char* path, const char* name)
}else{
strpath = path;
nowcache = strpath;
result = get_object_attribute(strpath.c_str(), NULL, &meta);
result = get_object_attribute(strpath.c_str(), nullptr, &meta);
}
if(0 != result){
return result;
@ -4213,7 +4213,7 @@ static int s3fs_removexattr(const char* path, const char* name)
set_stat_to_timespec(stbuf, ST_TYPE_MTIME, ts_mtime);
set_stat_to_timespec(stbuf, ST_TYPE_CTIME, ts_ctime);
if(0 != (result = create_directory_object(newpath.c_str(), stbuf.st_mode, ts_atime, ts_mtime, ts_ctime, stbuf.st_uid, stbuf.st_gid, NULL))){
if(0 != (result = create_directory_object(newpath.c_str(), stbuf.st_mode, ts_atime, ts_mtime, ts_ctime, stbuf.st_uid, stbuf.st_gid, nullptr))){
free_xattrs(xattrs);
return result;
}
@ -4244,7 +4244,7 @@ static int s3fs_removexattr(const char* path, const char* name)
AutoFdEntity autoent;
FdEntity* ent;
bool need_put_header = true;
if(NULL != (ent = autoent.OpenExistFdEntity(path))){
if(nullptr != (ent = autoent.OpenExistFdEntity(path))){
if(ent->MergeOrgMeta(updatemeta)){
// meta is changed, but now uploading.
// then the meta is pending and accumulated to be put after the upload is complete.
@ -4282,7 +4282,7 @@ static void s3fs_exit_fuseloop(int exit_status)
S3FS_PRN_ERR("Exiting FUSE event loop due to errors\n");
s3fs_init_deferred_exit_status = exit_status;
struct fuse_context *ctx = fuse_get_context();
if (NULL != ctx) {
if (nullptr != ctx) {
fuse_exit(ctx->fuse);
}
}
@ -4300,7 +4300,7 @@ static void* s3fs_init(struct fuse_conn_info* conn)
if(!ps3fscred->LoadIAMRoleFromMetaData()){
S3FS_PRN_CRIT("could not load IAM role name from meta data.");
s3fs_exit_fuseloop(EXIT_FAILURE);
return NULL;
return nullptr;
}
// Check Bucket
@ -4308,7 +4308,7 @@ static void* s3fs_init(struct fuse_conn_info* conn)
int result;
if(EXIT_SUCCESS != (result = s3fs_check_service())){
s3fs_exit_fuseloop(result);
return NULL;
return nullptr;
}
}
@ -4333,7 +4333,7 @@ static void* s3fs_init(struct fuse_conn_info* conn)
S3FS_PRN_ERR("Failed to initialize signal object, but continue...");
}
return NULL;
return nullptr;
}
static void s3fs_destroy(void*)
@ -4361,7 +4361,7 @@ static int s3fs_access(const char* path, int mask)
((mask & X_OK) == X_OK) ? "X_OK " : "",
(mask == F_OK) ? "F_OK" : "");
int result = check_object_access(path, mask, NULL);
int result = check_object_access(path, mask, nullptr);
S3FS_MALLOCTRIM(0);
return result;
}
@ -4602,7 +4602,7 @@ static int set_bucket(const char* arg)
S3FS_PRN_EXIT("bucket name and path(\"%s\") is wrong, it must be \"bucket[:/path]\".", arg);
return -1;
}
char* pmount_prefix = strtok(NULL, "");
char* pmount_prefix = strtok(nullptr, "");
if(pmount_prefix){
if(0 == strlen(pmount_prefix) || '/' != pmount_prefix[0]){
S3FS_PRN_EXIT("path(%s) must be prefix \"/\".", pmount_prefix);
@ -4633,49 +4633,49 @@ static fsblkcnt_t parse_bucket_size(char* max_size)
fsblkcnt_t ten00=static_cast<fsblkcnt_t>(1000L);
fsblkcnt_t ten24=static_cast<fsblkcnt_t>(1024L);
if ((ptr=strstr(max_size,"GB"))!=NULL) {
if ((ptr=strstr(max_size,"GB"))!=nullptr) {
scale=ten00*ten00*ten00;
if(strlen(ptr)>2)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"GiB"))!=NULL) {
else if ((ptr=strstr(max_size,"GiB"))!=nullptr) {
scale=ten24*ten24*ten24;
if(strlen(ptr)>3)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"TB"))!=NULL) {
else if ((ptr=strstr(max_size,"TB"))!=nullptr) {
scale=ten00*ten00*ten00*ten00;
if(strlen(ptr)>2)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"TiB"))!=NULL) {
else if ((ptr=strstr(max_size,"TiB"))!=nullptr) {
scale=ten24*ten24*ten24*ten24;
if(strlen(ptr)>3)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"PB"))!=NULL) {
else if ((ptr=strstr(max_size,"PB"))!=nullptr) {
scale=ten00*ten00*ten00*ten00*ten00;
if(strlen(ptr)>2)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"PiB"))!=NULL) {
else if ((ptr=strstr(max_size,"PiB"))!=nullptr) {
scale=ten24*ten24*ten24*ten24*ten24;
if(strlen(ptr)>3)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"EB"))!=NULL) {
else if ((ptr=strstr(max_size,"EB"))!=nullptr) {
scale=ten00*ten00*ten00*ten00*ten00*ten00;
if(strlen(ptr)>2)return 0; // no trailing garbage
*ptr='\0';
}
else if ((ptr=strstr(max_size,"EiB"))!=NULL) {
else if ((ptr=strstr(max_size,"EiB"))!=nullptr) {
scale=ten24*ten24*ten24*ten24*ten24*ten24;
if(strlen(ptr)>3)return 0; // no trailing garbage
*ptr='\0';
}
// extra check
for(ptr=max_size;*ptr!='\0';++ptr) if( ! isdigit(*ptr) ) return 0;
n_bytes=static_cast<fsblkcnt_t>(strtoul(max_size,0,10));
n_bytes=static_cast<fsblkcnt_t>(strtoul(max_size,nullptr,10));
n_bytes*=scale;
if(n_bytes<=0)return 0;
@ -4732,11 +4732,11 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
if(!nonempty){
struct dirent *ent;
DIR *dp = opendir(mountpoint.c_str());
if(dp == NULL){
if(dp == nullptr){
S3FS_PRN_EXIT("failed to open MOUNTPOINT: %s: %s", mountpoint.c_str(), strerror(errno));
return -1;
}
while((ent = readdir(dp)) != NULL){
while((ent = readdir(dp)) != nullptr){
if(strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0){
closedir(dp);
S3FS_PRN_EXIT("MOUNTPOINT directory %s is not empty. if you are sure this is safe, can use the 'nonempty' mount option.", mountpoint.c_str());
@ -5387,7 +5387,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
// Check cache file, using SIGUSR1
//
if(0 == strcmp(arg, "set_check_cache_sigusr1")){
if(!S3fsSignals::SetUsr1Handler(NULL)){
if(!S3fsSignals::SetUsr1Handler(nullptr)){
S3FS_PRN_EXIT("could not set sigusr1 for checking cache.");
return -1;
}
@ -5443,12 +5443,12 @@ int main(int argc, char* argv[])
S3fsLog singletonLog;
static const struct option long_opts[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, 0, 0},
{"debug", no_argument, NULL, 'd'},
{"incomplete-mpu-list", no_argument, NULL, 'u'},
{"incomplete-mpu-abort", optional_argument, NULL, 'a'}, // 'a' is only identifier and is not option.
{NULL, 0, NULL, 0}
{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 0},
{"debug", no_argument, nullptr, 'd'},
{"incomplete-mpu-list", no_argument, nullptr, 'u'},
{"incomplete-mpu-abort", optional_argument, nullptr, 'a'}, // 'a' is only identifier and is not option.
{nullptr, 0, nullptr, 0}
};
// init bucket_size
@ -5522,9 +5522,9 @@ int main(int argc, char* argv[])
utility_mode = INCOMP_TYPE_ABORT;
// check expire argument
if(NULL != optarg && 0 == strcasecmp(optarg, "all")){ // all is 0s
if(nullptr != optarg && 0 == strcasecmp(optarg, "all")){ // all is 0s
incomp_abort_time = 0;
}else if(NULL != optarg){
}else if(nullptr != optarg){
if(!convert_unixtime_from_option_arg(optarg, incomp_abort_time)){
S3FS_PRN_EXIT("--incomplete-mpu-abort option argument is wrong.");
delete ps3fscred;
@ -5603,7 +5603,7 @@ int main(int argc, char* argv[])
// after which the bucket name and mountpoint names
// should have been set
struct fuse_args custom_args = FUSE_ARGS_INIT(argc, argv);
if(0 != fuse_opt_parse(&custom_args, NULL, NULL, my_fuse_opt_proc)){
if(0 != fuse_opt_parse(&custom_args, nullptr, nullptr, my_fuse_opt_proc)){
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
destroy_parser_xml_lock();
@ -5755,7 +5755,7 @@ int main(int argc, char* argv[])
}
// check free disk space
if(!FdManager::IsSafeDiskSpace(NULL, S3fsCurl::GetMultipartSize() * S3fsCurl::GetMaxParallelCount())){
if(!FdManager::IsSafeDiskSpace(nullptr, S3fsCurl::GetMultipartSize() * S3fsCurl::GetMaxParallelCount())){
S3FS_PRN_EXIT("There is no enough disk space for used as cache(or temporary) directory by s3fs.");
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
@ -5811,7 +5811,7 @@ int main(int argc, char* argv[])
s3fs_oper.flag_utime_omit_ok = true;
// now passing things off to fuse, fuse will finish evaluating the command line args
fuse_res = fuse_main(custom_args.argc, custom_args.argv, &s3fs_oper, NULL);
fuse_res = fuse_main(custom_args.argc, custom_args.argv, &s3fs_oper, nullptr);
if(fuse_res == 0){
fuse_res = s3fs_init_deferred_exit_status;
}

View File

@ -98,13 +98,13 @@ bool UpdateS3fsCredential(char** ppaccess_key_id, char** ppserect_access_key, ch
}
if(ppaccess_key_id){
*ppaccess_key_id = NULL;
*ppaccess_key_id = nullptr;
}
if(ppserect_access_key){
*ppserect_access_key = NULL;
*ppserect_access_key = nullptr;
}
if(ppaccess_token){
*ppaccess_token = NULL;
*ppaccess_token = nullptr;
}
return false; // always false
}
@ -183,7 +183,7 @@ S3fsCred::S3fsCred() :
IAM_token_field("Token"),
IAM_expiry_field("Expiration"),
set_builtin_cred_opts(false),
hExtCredLib(NULL),
hExtCredLib(nullptr),
pFuncCredVersion(VersionS3fsCredential),
pFuncCredInit(InitS3fsCredential),
pFuncCredFree(FreeS3fsCredential),
@ -374,7 +374,7 @@ bool S3fsCred::GetIAMCredentialsURL(std::string& url, bool check_iam_role, AutoL
if(is_ecs){
const char *env = std::getenv(S3fsCred::ECS_IAM_ENV_VAR);
if(env == NULL){
if(env == nullptr){
S3FS_PRN_ERR("%s is not set.", S3fsCred::ECS_IAM_ENV_VAR);
return false;
}
@ -479,14 +479,14 @@ bool S3fsCred::LoadIAMCredentials(AutoLock::Type type)
return false;
}
const char* iam_v2_token = NULL;
const char* iam_v2_token = nullptr;
std::string str_iam_v2_token;
if(GetIMDSVersion(AutoLock::ALREADY_LOCKED) > 1){
str_iam_v2_token = GetIAMv2APIToken(AutoLock::ALREADY_LOCKED);
iam_v2_token = str_iam_v2_token.c_str();
}
const char* ibm_secret_access_key = NULL;
const char* ibm_secret_access_key = nullptr;
std::string str_ibm_secret_access_key;
if(IsIBMIAMAuth()){
str_ibm_secret_access_key = AWSSecretAccessKey;
@ -521,7 +521,7 @@ bool S3fsCred::LoadIAMRoleFromMetaData()
return false;
}
const char* iam_v2_token = NULL;
const char* iam_v2_token = nullptr;
std::string str_iam_v2_token;
if(GetIMDSVersion(AutoLock::ALREADY_LOCKED) > 1){
str_iam_v2_token = GetIAMv2APIToken(AutoLock::ALREADY_LOCKED);
@ -999,14 +999,14 @@ bool S3fsCred::InitialS3fsCredentials()
const char* AWSSECRETACCESSKEY = getenv("AWS_SECRET_ACCESS_KEY") ? getenv("AWS_SECRET_ACCESS_KEY") : getenv("AWSSECRETACCESSKEY");
const char* AWSSESSIONTOKEN = getenv("AWS_SESSION_TOKEN") ? getenv("AWS_SESSION_TOKEN") : getenv("AWSSESSIONTOKEN");
if(AWSACCESSKEYID != NULL || AWSSECRETACCESSKEY != NULL){
if( (AWSACCESSKEYID == NULL && AWSSECRETACCESSKEY != NULL) ||
(AWSACCESSKEYID != NULL && AWSSECRETACCESSKEY == NULL) ){
if(AWSACCESSKEYID != nullptr || AWSSECRETACCESSKEY != nullptr){
if( (AWSACCESSKEYID == nullptr && AWSSECRETACCESSKEY != nullptr) ||
(AWSACCESSKEYID != nullptr && AWSSECRETACCESSKEY == nullptr) ){
S3FS_PRN_EXIT("both environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set together.");
return false;
}
S3FS_PRN_INFO2("access key from env variables");
if(AWSSESSIONTOKEN != NULL){
if(AWSSESSIONTOKEN != nullptr){
S3FS_PRN_INFO2("session token is available");
if(!SetAccessKeyWithSessionToken(AWSACCESSKEYID, AWSSECRETACCESSKEY, AWSSESSIONTOKEN, AutoLock::NONE)){
S3FS_PRN_EXIT("session token is invalid.");
@ -1028,7 +1028,7 @@ bool S3fsCred::InitialS3fsCredentials()
// 3a - from the AWS_CREDENTIAL_FILE environment variable
char* AWS_CREDENTIAL_FILE = getenv("AWS_CREDENTIAL_FILE");
if(AWS_CREDENTIAL_FILE != NULL){
if(AWS_CREDENTIAL_FILE != nullptr){
passwd_file = AWS_CREDENTIAL_FILE;
if(IsSetPasswdFile()){
if(!IsReadableS3fsPasswdFile()){
@ -1053,7 +1053,7 @@ bool S3fsCred::InitialS3fsCredentials()
// 4 - from the default location in the users home directory
char* HOME = getenv("HOME");
if(HOME != NULL){
if(HOME != nullptr){
passwd_file = HOME;
passwd_file += "/.passwd-s3fs";
if(IsReadableS3fsPasswdFile()){
@ -1146,7 +1146,7 @@ bool S3fsCred::CheckIAMCredentialUpdate(std::string* access_key_id, std::string*
AutoLock auto_lock(&token_lock);
if(IsIBMIAMAuth() || IsSetExtCredLib() || is_ecs || IsSetIAMRole(AutoLock::ALREADY_LOCKED)){
if(AWSAccessTokenExpire < (time(NULL) + S3fsCred::IAM_EXPIRE_MERGIN)){
if(AWSAccessTokenExpire < (time(nullptr) + S3fsCred::IAM_EXPIRE_MERGIN)){
S3FS_PRN_INFO("IAM Access Token refreshing...");
// update
@ -1233,13 +1233,13 @@ bool S3fsCred::InitExtCredLib()
}
// Initialize library
if(!pFuncCredInit){
S3FS_PRN_CRIT("\"InitS3fsCredential\" function pointer is NULL, why?");
S3FS_PRN_CRIT("\"InitS3fsCredential\" function pointer is nullptr, why?");
UnloadExtCredLib();
return false;
}
const char* popts = credlib_opts.empty() ? NULL : credlib_opts.c_str();
char* perrstr = NULL;
const char* popts = credlib_opts.empty() ? nullptr : credlib_opts.c_str();
char* perrstr = nullptr;
if(!(*pFuncCredInit)(popts, &perrstr)){
S3FS_PRN_ERR("Could not initialize %s(external credential library) by \"InitS3fsCredential\" function : %s", credlib.c_str(), perrstr ? perrstr : "unknown");
// cppcheck-suppress unmatchedSuppression
@ -1272,28 +1272,28 @@ bool S3fsCred::LoadExtCredLib()
//
// Search Library: (RPATH ->) LD_LIBRARY_PATH -> (RUNPATH ->) /etc/ld.so.cache -> /lib -> /usr/lib
//
if(NULL == (hExtCredLib = dlopen(credlib.c_str(), RTLD_LAZY))){
if(nullptr == (hExtCredLib = dlopen(credlib.c_str(), RTLD_LAZY))){
const char* preason = dlerror();
S3FS_PRN_ERR("Could not load %s(external credential library) by error : %s", credlib.c_str(), preason ? preason : "unknown");
return false;
}
// Set function pointers
if(NULL == (pFuncCredVersion = reinterpret_cast<fp_VersionS3fsCredential>(dlsym(hExtCredLib, "VersionS3fsCredential")))){
if(nullptr == (pFuncCredVersion = reinterpret_cast<fp_VersionS3fsCredential>(dlsym(hExtCredLib, "VersionS3fsCredential")))){
S3FS_PRN_ERR("%s(external credential library) does not have \"VersionS3fsCredential\" function which is required.", credlib.c_str());
UnloadExtCredLib();
return false;
}
if(NULL == (pFuncCredUpdate = reinterpret_cast<fp_UpdateS3fsCredential>(dlsym(hExtCredLib, "UpdateS3fsCredential")))){
if(nullptr == (pFuncCredUpdate = reinterpret_cast<fp_UpdateS3fsCredential>(dlsym(hExtCredLib, "UpdateS3fsCredential")))){
S3FS_PRN_ERR("%s(external credential library) does not have \"UpdateS3fsCredential\" function which is required.", credlib.c_str());
UnloadExtCredLib();
return false;
}
if(NULL == (pFuncCredInit = reinterpret_cast<fp_InitS3fsCredential>(dlsym(hExtCredLib, "InitS3fsCredential")))){
if(nullptr == (pFuncCredInit = reinterpret_cast<fp_InitS3fsCredential>(dlsym(hExtCredLib, "InitS3fsCredential")))){
S3FS_PRN_INFO("%s(external credential library) does not have \"InitS3fsCredential\" function which is optional.", credlib.c_str());
pFuncCredInit = InitS3fsCredential; // set built-in function
}
if(NULL == (pFuncCredFree = reinterpret_cast<fp_FreeS3fsCredential>(dlsym(hExtCredLib, "FreeS3fsCredential")))){
if(nullptr == (pFuncCredFree = reinterpret_cast<fp_FreeS3fsCredential>(dlsym(hExtCredLib, "FreeS3fsCredential")))){
S3FS_PRN_INFO("%s(external credential library) does not have \"FreeS3fsCredential\" function which is optional.", credlib.c_str());
pFuncCredFree = FreeS3fsCredential; // set built-in function
}
@ -1309,9 +1309,9 @@ bool S3fsCred::UnloadExtCredLib()
// Uninitialize library
if(!pFuncCredFree){
S3FS_PRN_CRIT("\"FreeS3fsCredential\" function pointer is NULL, why?");
S3FS_PRN_CRIT("\"FreeS3fsCredential\" function pointer is nullptr, why?");
}else{
char* perrstr = NULL;
char* perrstr = nullptr;
if(!(*pFuncCredFree)(&perrstr)){
S3FS_PRN_ERR("Could not uninitialize by \"FreeS3fsCredential\" function : %s", perrstr ? perrstr : "unknown");
}
@ -1330,7 +1330,7 @@ bool S3fsCred::UnloadExtCredLib()
// close
dlclose(hExtCredLib);
hExtCredLib = NULL;
hExtCredLib = nullptr;
}
return true;
}
@ -1344,10 +1344,10 @@ bool S3fsCred::UpdateExtCredentials(AutoLock::Type type)
AutoLock auto_lock(&token_lock, type);
char* paccess_key_id = NULL;
char* pserect_access_key = NULL;
char* paccess_token = NULL;
char* perrstr = NULL;
char* paccess_key_id = nullptr;
char* pserect_access_key = nullptr;
char* paccess_token = nullptr;
char* perrstr = nullptr;
long long token_expire = 0;
bool result = (*pFuncCredUpdate)(&paccess_key_id, &pserect_access_key, &paccess_token, &token_expire, &perrstr);

View File

@ -164,7 +164,7 @@ class S3fsCred
bool LoadIAMRoleFromMetaData();
bool CheckIAMCredentialUpdate(std::string* access_key_id = NULL, std::string* secret_access_key = NULL, std::string* access_token = NULL);
bool CheckIAMCredentialUpdate(std::string* access_key_id = nullptr, std::string* secret_access_key = nullptr, std::string* access_token = nullptr);
const char* GetCredFuncVersion(bool detail) const;
int DetectParam(const char* arg);

View File

@ -55,11 +55,11 @@ extern const char* VersionS3fsCredential(bool detail) S3FS_FUNCATTR_WEAK;
// implemented, it will not be called.
//
// const char* popts : String passed with the credlib_opts option. If the
// credlib_opts option is not specified, NULL will be
// credlib_opts option is not specified, nullptr will be
// passed.
// char** pperrstr : pperrstr is used to pass the error message to the
// caller when an error occurs.
// If this pointer is not NULL, you can allocate memory
// If this pointer is not nullptr, you can allocate memory
// and set an error message to it. The allocated memory
// area is freed by the caller.
//
@ -75,7 +75,7 @@ extern bool InitS3fsCredential(const char* popts, char** pperrstr) S3FS_FUNCATTR
//
// char** pperrstr : pperrstr is used to pass the error message to the
// caller when an error occurs.
// If this pointer is not NULL, you can allocate memory
// If this pointer is not nullptr, you can allocate memory
// and set an error message to it. The allocated memory
// area is freed by the caller.
//

View File

@ -34,10 +34,10 @@ 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";
S3fsLog* S3fsLog::pSingleton = NULL;
S3fsLog* S3fsLog::pSingleton = nullptr;
S3fsLog::s3fs_log_level S3fsLog::debug_level = S3fsLog::LEVEL_CRIT;
FILE* S3fsLog::logfp = NULL;
std::string* S3fsLog::plogfile = NULL;
FILE* S3fsLog::logfp = nullptr;
std::string* S3fsLog::plogfile = nullptr;
bool S3fsLog::time_stamp = true;
//-------------------------------------------------------------------
@ -60,7 +60,7 @@ std::string S3fsLog::GetCurrentTime()
now.tv_sec = tsnow.tv_sec;
now.tv_usec = (tsnow.tv_nsec / 1000);
}else{
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);
}
strftime(tmp, sizeof(tmp), "%Y-%m-%dT%H:%M:%S", gmtime_r(&now.tv_sec, &res));
current_time << tmp << "." << std::setfill('0') << std::setw(3) << (now.tv_usec / 1000) << "Z ";
@ -71,7 +71,7 @@ std::string S3fsLog::GetCurrentTime()
bool S3fsLog::SetLogfile(const char* pfile)
{
if(!S3fsLog::pSingleton){
S3FS_PRN_CRIT("S3fsLog::pSingleton is NULL.");
S3FS_PRN_CRIT("S3fsLog::pSingleton is nullptr.");
return false;
}
return S3fsLog::pSingleton->LowSetLogfile(pfile);
@ -80,7 +80,7 @@ bool S3fsLog::SetLogfile(const char* pfile)
bool S3fsLog::ReopenLogfile()
{
if(!S3fsLog::pSingleton){
S3FS_PRN_CRIT("S3fsLog::pSingleton is NULL.");
S3FS_PRN_CRIT("S3fsLog::pSingleton is nullptr.");
return false;
}
if(!S3fsLog::logfp){
@ -88,7 +88,7 @@ bool S3fsLog::ReopenLogfile()
return true;
}
if(!S3fsLog::plogfile){
S3FS_PRN_ERR("There is a problem with the path to the log file being NULL.");
S3FS_PRN_ERR("There is a problem with the path to the log file being nullptr.");
return false;
}
std::string tmp = *(S3fsLog::plogfile);
@ -98,7 +98,7 @@ bool S3fsLog::ReopenLogfile()
S3fsLog::s3fs_log_level S3fsLog::SetLogLevel(s3fs_log_level level)
{
if(!S3fsLog::pSingleton){
S3FS_PRN_CRIT("S3fsLog::pSingleton is NULL.");
S3FS_PRN_CRIT("S3fsLog::pSingleton is nullptr.");
return S3fsLog::debug_level; // Although it is an error, it returns the current value.
}
return S3fsLog::pSingleton->LowSetLogLevel(level);
@ -107,7 +107,7 @@ S3fsLog::s3fs_log_level S3fsLog::SetLogLevel(s3fs_log_level level)
S3fsLog::s3fs_log_level S3fsLog::BumpupLogLevel()
{
if(!S3fsLog::pSingleton){
S3FS_PRN_CRIT("S3fsLog::pSingleton is NULL.");
S3FS_PRN_CRIT("S3fsLog::pSingleton is nullptr.");
return S3fsLog::debug_level; // Although it is an error, it returns the current value.
}
return S3fsLog::pSingleton->LowBumpupLogLevel();
@ -140,15 +140,15 @@ S3fsLog::~S3fsLog()
{
if(S3fsLog::pSingleton == this){
FILE* oldfp = S3fsLog::logfp;
S3fsLog::logfp = NULL;
S3fsLog::logfp = nullptr;
if(oldfp && 0 != fclose(oldfp)){
S3FS_PRN_ERR("Could not close old log file(%s), but continue...", (S3fsLog::plogfile ? S3fsLog::plogfile->c_str() : "null"));
}
if(S3fsLog::plogfile){
delete S3fsLog::plogfile;
S3fsLog::plogfile = NULL;
S3fsLog::plogfile = nullptr;
}
S3fsLog::pSingleton = NULL;
S3fsLog::pSingleton = nullptr;
S3fsLog::debug_level = S3fsLog::LEVEL_CRIT;
closelog();
@ -164,12 +164,12 @@ bool S3fsLog::LowLoadEnv()
return false;
}
char* pEnvVal;
if(NULL != (pEnvVal = getenv(S3fsLog::LOGFILEENV))){
if(nullptr != (pEnvVal = getenv(S3fsLog::LOGFILEENV))){
if(!SetLogfile(pEnvVal)){
return false;
}
}
if(NULL != (pEnvVal = getenv(S3fsLog::MSGTIMESTAMP))){
if(nullptr != (pEnvVal = getenv(S3fsLog::MSGTIMESTAMP))){
if(0 == strcasecmp(pEnvVal, "true") || 0 == strcasecmp(pEnvVal, "yes") || 0 == strcasecmp(pEnvVal, "1")){
S3fsLog::time_stamp = true;
}else if(0 == strcasecmp(pEnvVal, "false") || 0 == strcasecmp(pEnvVal, "no") || 0 == strcasecmp(pEnvVal, "0")){
@ -194,10 +194,10 @@ bool S3fsLog::LowSetLogfile(const char* pfile)
S3FS_PRN_ERR("Could not close log file(%s).", (S3fsLog::plogfile ? S3fsLog::plogfile->c_str() : "null"));
return false;
}
S3fsLog::logfp = NULL;
S3fsLog::logfp = nullptr;
if(S3fsLog::plogfile){
delete S3fsLog::plogfile;
S3fsLog::plogfile = NULL;
S3fsLog::plogfile = nullptr;
}
}else{
// open new log file
@ -206,7 +206,7 @@ bool S3fsLog::LowSetLogfile(const char* pfile)
// It will reopen even if it is the same file.
//
FILE* newfp;
if(NULL == (newfp = fopen(pfile, "a+"))){
if(nullptr == (newfp = fopen(pfile, "a+"))){
S3FS_PRN_ERR("Could not open log file(%s).", pfile);
return false;
}
@ -262,7 +262,7 @@ void s3fs_low_logprn(S3fsLog::s3fs_log_level level, const char* file, const char
if(S3fsLog::IsS3fsLogLevel(level)){
va_list va;
va_start(va, fmt);
size_t len = vsnprintf(NULL, 0, fmt, va) + 1;
size_t len = vsnprintf(nullptr, 0, fmt, va) + 1;
va_end(va);
std::unique_ptr<char[]> message(new char[len]);
@ -286,7 +286,7 @@ void s3fs_low_logprn2(S3fsLog::s3fs_log_level level, int nest, const char* file,
if(S3fsLog::IsS3fsLogLevel(level)){
va_list va;
va_start(va, fmt);
size_t len = vsnprintf(NULL, 0, fmt, va) + 1;
size_t len = vsnprintf(nullptr, 0, fmt, va) + 1;
va_end(va);
std::unique_ptr<char[]> message(new char[len]);

View File

@ -105,7 +105,7 @@ class S3fsLog
static bool IsSetLogFile()
{
return (NULL != logfp);
return (nullptr != logfp);
}
static FILE* GetOutputLogFile()

View File

@ -96,7 +96,7 @@ std::string get_username(uid_t uid)
size_t maxlen = max_password_size;
int result;
struct passwd pwinfo;
struct passwd* ppwinfo = NULL;
struct passwd* ppwinfo = nullptr;
// make buffer
std::unique_ptr<char[]> pbuf(new char[maxlen]);
@ -112,7 +112,7 @@ std::string get_username(uid_t uid)
}
// check pw
if(NULL == ppwinfo){
if(nullptr == ppwinfo){
return std::string("");
}
std::string name = SAFESTRPTR(ppwinfo->pw_name);
@ -124,7 +124,7 @@ int is_uid_include_group(uid_t uid, gid_t gid)
size_t maxlen = max_group_name_length;
int result;
struct group ginfo;
struct group* pginfo = NULL;
struct group* pginfo = nullptr;
// make buffer
std::unique_ptr<char[]> pbuf(new char[maxlen]);
@ -140,7 +140,7 @@ int is_uid_include_group(uid_t uid, gid_t gid)
}
// check group
if(NULL == pginfo){
if(nullptr == pginfo){
// there is not gid in group.
return -EINVAL;
}
@ -167,7 +167,7 @@ int is_uid_include_group(uid_t uid, gid_t gid)
// conflicts.
// To avoid this, exclusive control is performed by mutex.
//
static pthread_mutex_t* pbasename_lock = NULL;
static pthread_mutex_t* pbasename_lock = nullptr;
bool init_basename_lock()
{
@ -187,7 +187,7 @@ bool init_basename_lock()
if(0 != (result = pthread_mutex_init(pbasename_lock, &attr))){
S3FS_PRN_ERR("failed to init pbasename_lock: %d.", result);
delete pbasename_lock;
pbasename_lock = NULL;
pbasename_lock = nullptr;
return false;
}
return true;
@ -205,7 +205,7 @@ bool destroy_basename_lock()
return false;
}
delete pbasename_lock;
pbasename_lock = NULL;
pbasename_lock = nullptr;
return true;
}
@ -349,7 +349,7 @@ bool delete_files_in_dir(const char* dir, bool is_remove_own)
DIR* dp;
struct dirent* dent;
if(NULL == (dp = opendir(dir))){
if(nullptr == (dp = opendir(dir))){
S3FS_PRN_ERR("could not open dir(%s) - errno(%d)", dir, errno);
return false;
}
@ -400,7 +400,7 @@ bool compare_sysname(const char* target)
// The buffer size of sysname member in struct utsname is
// OS dependent, but 512 bytes is sufficient for now.
//
static char* psysname = NULL;
static char* psysname = nullptr;
static char sysname[512];
if(!psysname){
struct utsname sysinfo;
@ -555,7 +555,7 @@ struct timespec* s3fs_realtime(struct timespec& ts)
{
if(-1 == clock_gettime(static_cast<clockid_t>(CLOCK_REALTIME), &ts)){
S3FS_PRN_WARN("failed to clock_gettime by errno(%d)", errno);
ts.tv_sec = time(NULL);
ts.tv_sec = time(nullptr);
ts.tv_nsec = 0;
}
return &ts;

View File

@ -39,7 +39,7 @@ static const char c_strErrorObjectName[] = "FILE or SUBDIR in DIR";
// [NOTE]
// mutex for static variables in GetXmlNsUrl
//
static pthread_mutex_t* pxml_parser_mutex = NULL;
static pthread_mutex_t* pxml_parser_mutex = nullptr;
//-------------------------------------------------------------------
// Functions
@ -59,9 +59,9 @@ static bool GetXmlNsUrl(xmlDocPtr doc, std::string& nsurl)
AutoLock lock(pxml_parser_mutex);
if((tmLast + 60) < time(NULL)){
if((tmLast + 60) < time(nullptr)){
// refresh
tmLast = time(NULL);
tmLast = time(nullptr);
strNs = "";
xmlNodePtr pRootNode = xmlDocGetRootElement(doc);
if(pRootNode){
@ -93,7 +93,7 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp)
std::string exp_string;
if(!doc){
return NULL;
return nullptr;
}
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
@ -106,15 +106,15 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp)
exp_string += exp;
if(NULL == (marker_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_string.c_str()), ctx))){
if(nullptr == (marker_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_string.c_str()), ctx))){
xmlXPathFreeContext(ctx);
return NULL;
return nullptr;
}
if(xmlXPathNodeSetIsEmpty(marker_xp->nodesetval)){
S3FS_PRN_ERR("marker_xp->nodesetval is empty.");
xmlXPathFreeObject(marker_xp);
xmlXPathFreeContext(ctx);
return NULL;
return nullptr;
}
xmlNodeSetPtr nodes = marker_xp->nodesetval;
xmlChar* result = xmlNodeListGetString(doc, nodes->nodeTab[0]->xmlChildrenNode, 1);
@ -142,14 +142,14 @@ xmlChar* get_next_marker(xmlDocPtr doc)
// return: the pointer to object name on allocated memory.
// the pointer to "c_strErrorObjectName".(not allocated)
// NULL(a case of something error occurred)
// nullptr(a case of something error occurred)
static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
{
// Get full path
xmlChar* fullpath = xmlNodeListGetString(doc, node, 1);
if(!fullpath){
S3FS_PRN_ERR("could not get object full path name..");
return NULL;
return nullptr;
}
// basepath(path) is as same as fullpath.
if(0 == strcmp(reinterpret_cast<char*>(fullpath), path)){
@ -166,7 +166,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
xmlFree(fullpath);
if('\0' == mybname[0]){
return NULL;
return nullptr;
}
// check subdir & file in subdir
@ -213,7 +213,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
static xmlChar* get_exp_value_xml(xmlDocPtr doc, xmlXPathContextPtr ctx, const char* exp_key)
{
if(!doc || !ctx || !exp_key){
return NULL;
return nullptr;
}
xmlXPathObjectPtr exp;
@ -221,21 +221,21 @@ static xmlChar* get_exp_value_xml(xmlDocPtr doc, xmlXPathContextPtr ctx, const c
xmlChar* exp_value;
// search exp_key tag
if(NULL == (exp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_key), ctx))){
if(nullptr == (exp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(exp_key), ctx))){
S3FS_PRN_ERR("Could not find key(%s).", exp_key);
return NULL;
return nullptr;
}
if(xmlXPathNodeSetIsEmpty(exp->nodesetval)){
S3FS_PRN_ERR("Key(%s) node is empty.", exp_key);
S3FS_XMLXPATHFREEOBJECT(exp);
return NULL;
return nullptr;
}
// get exp_key value & set in struct
exp_nodes = exp->nodesetval;
if(NULL == (exp_value = xmlNodeListGetString(doc, exp_nodes->nodeTab[0]->xmlChildrenNode, 1))){
if(nullptr == (exp_value = xmlNodeListGetString(doc, exp_nodes->nodeTab[0]->xmlChildrenNode, 1))){
S3FS_PRN_ERR("Key(%s) value is empty.", exp_key);
S3FS_XMLXPATHFREEOBJECT(exp);
return NULL;
return nullptr;
}
S3FS_XMLXPATHFREEOBJECT(exp);
@ -270,7 +270,7 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
// get "Upload" Tags
xmlXPathObjectPtr upload_xp;
if(NULL == (upload_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_upload.c_str()), ctx))){
if(nullptr == (upload_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_upload.c_str()), ctx))){
S3FS_PRN_ERR("xmlXPathEvalExpression returns null.");
return false;
}
@ -292,7 +292,7 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
xmlChar* ex_value;
// search "Key" tag
if(NULL == (ex_value = get_exp_value_xml(doc, ctx, ex_key.c_str()))){
if(nullptr == (ex_value = get_exp_value_xml(doc, ctx, ex_key.c_str()))){
continue;
}
if('/' != *(reinterpret_cast<char*>(ex_value))){
@ -304,14 +304,14 @@ bool get_incomp_mpu_list(xmlDocPtr doc, incomp_mpu_list_t& list)
S3FS_XMLFREE(ex_value);
// search "UploadId" tag
if(NULL == (ex_value = get_exp_value_xml(doc, ctx, ex_id.c_str()))){
if(nullptr == (ex_value = get_exp_value_xml(doc, ctx, ex_id.c_str()))){
continue;
}
part.id = reinterpret_cast<char*>(ex_value);
S3FS_XMLFREE(ex_value);
// search "Initiated" tag
if(NULL == (ex_value = get_exp_value_xml(doc, ctx, ex_date.c_str()))){
if(nullptr == (ex_value = get_exp_value_xml(doc, ctx, ex_date.c_str()))){
continue;
}
part.date = reinterpret_cast<char*>(ex_value);
@ -346,7 +346,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
xmlXPathObjectPtr contents_xp;
xmlNodeSetPtr content_nodes;
if(NULL == (contents_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_contents), ctx))){
if(nullptr == (contents_xp = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_contents), ctx))){
S3FS_PRN_ERR("xmlXPathEvalExpression returns null.");
return -1;
}
@ -365,7 +365,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
// object name
xmlXPathObjectPtr key;
if(NULL == (key = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_key), ctx))){
if(nullptr == (key = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_key), ctx))){
S3FS_PRN_WARN("key is null. but continue.");
continue;
}
@ -387,7 +387,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
if(!isCPrefix && ex_etag){
// Get ETag
xmlXPathObjectPtr ETag;
if(NULL != (ETag = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_etag), ctx))){
if(nullptr != (ETag = xmlXPathEvalExpression(reinterpret_cast<const xmlChar*>(ex_etag), ctx))){
if(xmlXPathNodeSetIsEmpty(ETag->nodesetval)){
S3FS_PRN_INFO("ETag->nodesetval is empty.");
}else{
@ -412,7 +412,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
if(prefix){
head.common_prefixes.push_back(decname);
}
if(!head.insert(decname.c_str(), (!stretag.empty() ? stretag.c_str() : NULL), is_dir)){
if(!head.insert(decname.c_str(), (!stretag.empty() ? stretag.c_str() : nullptr), is_dir)){
S3FS_PRN_ERR("insert_object returns with error.");
xmlXPathFreeObject(key);
xmlXPathFreeObject(contents_xp);
@ -466,7 +466,7 @@ int append_objects_from_xml(const char* path, xmlDocPtr doc, S3ObjList& head)
ex_etag += "ETag";
if(-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_contents.c_str(), ex_key.c_str(), ex_etag.c_str(), 0, head, /*prefix=*/ false) ||
-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_cprefix.c_str(), ex_prefix.c_str(), NULL, 1, head, /*prefix=*/ true) )
-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_cprefix.c_str(), ex_prefix.c_str(), nullptr, 1, head, /*prefix=*/ true) )
{
S3FS_PRN_ERR("append_objects_from_xml_ex returns with error.");
S3FS_XMLXPATHFREECONTEXT(ctx);
@ -490,15 +490,15 @@ bool simple_parse_xml(const char* data, size_t len, const char* key, std::string
value.clear();
xmlDocPtr doc;
if(NULL == (doc = xmlReadMemory(data, static_cast<int>(len), "", NULL, 0))){
if(nullptr == (doc = xmlReadMemory(data, static_cast<int>(len), "", nullptr, 0))){
return false;
}
if(NULL == doc->children){
if(nullptr == doc->children){
S3FS_XMLFREEDOC(doc);
return false;
}
for(xmlNodePtr cur_node = doc->children->children; NULL != cur_node; cur_node = cur_node->next){
for(xmlNodePtr cur_node = doc->children->children; nullptr != cur_node; cur_node = cur_node->next){
// For DEBUG
// std::string cur_node_name(reinterpret_cast<const char *>(cur_node->name));
// printf("cur_node_name: %s\n", cur_node_name.c_str());
@ -542,7 +542,7 @@ bool init_parser_xml_lock()
if(0 != pthread_mutex_init(pxml_parser_mutex, &attr)){
delete pxml_parser_mutex;
pxml_parser_mutex = NULL;
pxml_parser_mutex = nullptr;
return false;
}
return true;
@ -557,7 +557,7 @@ bool destroy_parser_xml_lock()
return false;
}
delete pxml_parser_mutex;
pxml_parser_mutex = NULL;
pxml_parser_mutex = nullptr;
return true;
}

View File

@ -132,10 +132,10 @@ const s3obj_entry* S3ObjList::GetS3Obj(const char* name) const
s3obj_t::const_iterator iter;
if(!name || '\0' == name[0]){
return NULL;
return nullptr;
}
if(objects.end() == (iter = objects.find(name))){
return NULL;
return nullptr;
}
return &((*iter).second);
}
@ -147,7 +147,7 @@ std::string S3ObjList::GetOrgName(const char* name) const
if(!name || '\0' == name[0]){
return std::string("");
}
if(NULL == (ps3obj = GetS3Obj(name))){
if(nullptr == (ps3obj = GetS3Obj(name))){
return std::string("");
}
return ps3obj->orgname;
@ -160,7 +160,7 @@ std::string S3ObjList::GetNormalizedName(const char* name) const
if(!name || '\0' == name[0]){
return std::string("");
}
if(NULL == (ps3obj = GetS3Obj(name))){
if(nullptr == (ps3obj = GetS3Obj(name))){
return std::string("");
}
if(ps3obj->normalname.empty()){
@ -176,7 +176,7 @@ std::string S3ObjList::GetETag(const char* name) const
if(!name || '\0' == name[0]){
return std::string("");
}
if(NULL == (ps3obj = GetS3Obj(name))){
if(nullptr == (ps3obj = GetS3Obj(name))){
return std::string("");
}
return ps3obj->etag;
@ -186,7 +186,7 @@ bool S3ObjList::IsDir(const char* name) const
{
const s3obj_entry* ps3obj;
if(NULL == (ps3obj = GetS3Obj(name))){
if(nullptr == (ps3obj = GetS3Obj(name))){
return false;
}
return ps3obj->is_dir;

View File

@ -63,7 +63,7 @@ class S3ObjList
~S3ObjList() {}
bool IsEmpty() const { return objects.empty(); }
bool insert(const char* name, const char* etag = NULL, bool is_dir = false);
bool insert(const char* name, const char* etag = nullptr, bool is_dir = false);
std::string GetOrgName(const char* name) const;
std::string GetNormalizedName(const char* name) const;
std::string GetETag(const char* name) const;

View File

@ -29,7 +29,7 @@
//-------------------------------------------------------------------
// Class S3fsSignals
//-------------------------------------------------------------------
S3fsSignals* S3fsSignals::pSingleton = NULL;
S3fsSignals* S3fsSignals::pSingleton = nullptr;
bool S3fsSignals::enableUsr1 = false;
//-------------------------------------------------------------------
@ -46,7 +46,7 @@ bool S3fsSignals::Initialize()
bool S3fsSignals::Destroy()
{
delete S3fsSignals::pSingleton;
S3fsSignals::pSingleton = NULL;
S3fsSignals::pSingleton = nullptr;
return true;
}
@ -91,10 +91,10 @@ void* S3fsSignals::CheckCacheWorker(void* arg)
{
Semaphore* pSem = static_cast<Semaphore*>(arg);
if(!pSem){
pthread_exit(NULL);
pthread_exit(nullptr);
}
if(!S3fsSignals::enableUsr1){
pthread_exit(NULL);
pthread_exit(nullptr);
}
// wait and loop
@ -118,7 +118,7 @@ void* S3fsSignals::CheckCacheWorker(void* arg)
pSem->wait();
}
}
return NULL;
return nullptr;
}
void S3fsSignals::HandlerUSR2(int sig)
@ -137,7 +137,7 @@ bool S3fsSignals::InitUsr2Handler()
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = S3fsSignals::HandlerUSR2;
sa.sa_flags = SA_RESTART;
if(0 != sigaction(SIGUSR2, &sa, NULL)){
if(0 != sigaction(SIGUSR2, &sa, nullptr)){
return false;
}
return true;
@ -159,7 +159,7 @@ bool S3fsSignals::InitHupHandler()
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = S3fsSignals::HandlerHUP;
sa.sa_flags = SA_RESTART;
if(0 != sigaction(SIGHUP, &sa, NULL)){
if(0 != sigaction(SIGHUP, &sa, nullptr)){
return false;
}
return true;
@ -168,7 +168,7 @@ bool S3fsSignals::InitHupHandler()
//-------------------------------------------------------------------
// Methods
//-------------------------------------------------------------------
S3fsSignals::S3fsSignals() : pThreadUsr1(NULL), pSemUsr1(NULL)
S3fsSignals::S3fsSignals() : pThreadUsr1(nullptr), pSemUsr1(nullptr)
{
if(S3fsSignals::enableUsr1){
if(!InitUsr1Handler()){
@ -203,12 +203,12 @@ bool S3fsSignals::InitUsr1Handler()
int result;
pSemUsr1 = new Semaphore(0);
pThreadUsr1 = new pthread_t;
if(0 != (result = pthread_create(pThreadUsr1, NULL, S3fsSignals::CheckCacheWorker, static_cast<void*>(pSemUsr1)))){
if(0 != (result = pthread_create(pThreadUsr1, nullptr, S3fsSignals::CheckCacheWorker, static_cast<void*>(pSemUsr1)))){
S3FS_PRN_ERR("Could not create thread for SIGUSR1 by %d", result);
delete pSemUsr1;
delete pThreadUsr1;
pSemUsr1 = NULL;
pThreadUsr1 = NULL;
pSemUsr1 = nullptr;
pThreadUsr1 = nullptr;
return false;
}
@ -217,7 +217,7 @@ bool S3fsSignals::InitUsr1Handler()
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = S3fsSignals::HandlerUSR1;
sa.sa_flags = SA_RESTART;
if(0 != sigaction(SIGUSR1, &sa, NULL)){
if(0 != sigaction(SIGUSR1, &sa, nullptr)){
S3FS_PRN_ERR("Could not set signal handler for SIGUSR1");
DestroyUsr1Handler();
return false;
@ -238,7 +238,7 @@ bool S3fsSignals::DestroyUsr1Handler()
pSemUsr1->post();
// wait for thread exiting
void* retval = NULL;
void* retval = nullptr;
int result;
if(0 != (result = pthread_join(*pThreadUsr1, &retval))){
S3FS_PRN_ERR("Could not stop thread for SIGUSR1 by %d", result);
@ -246,8 +246,8 @@ bool S3fsSignals::DestroyUsr1Handler()
}
delete pSemUsr1;
delete pThreadUsr1;
pSemUsr1 = NULL;
pThreadUsr1 = NULL;
pSemUsr1 = nullptr;
pThreadUsr1 = nullptr;
return true;
}

View File

@ -87,7 +87,7 @@ char* strptime(const char* s, const char* f, struct tm* tm)
bool s3fs_strtoofft(off_t* value, const char* str, int base)
{
if(value == NULL || str == NULL){
if(value == nullptr || str == nullptr){
return false;
}
errno = 0;
@ -169,7 +169,7 @@ static std::string rawUrlEncode(const std::string &s, const char* except_chars)
std::string result;
for (size_t i = 0; i < s.length(); ++i) {
unsigned char c = s[i];
if((except_chars && NULL != strchr(except_chars, c)) ||
if((except_chars && nullptr != strchr(except_chars, c)) ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') )
@ -274,7 +274,7 @@ bool get_keyword_value(const std::string& target, const char* keyword, std::stri
std::string get_date_rfc850()
{
char buf[100];
time_t t = time(NULL);
time_t t = time(nullptr);
struct tm res;
strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime_r(&t, &res));
return buf;
@ -282,7 +282,7 @@ std::string get_date_rfc850()
void get_date_sigv3(std::string& date, std::string& date8601)
{
time_t tm = time(NULL);
time_t tm = time(nullptr);
date = get_date_string(tm);
date8601 = get_date_iso8601(tm);
}
@ -398,7 +398,7 @@ char* s3fs_base64(const unsigned char* input, size_t length)
char* result;
if(!input || 0 == length){
return NULL;
return nullptr;
}
result = new char[((length + 3 - 1) / 3) * 4 + 1];
@ -446,7 +446,7 @@ unsigned char* s3fs_decode64(const char* input, size_t input_len, size_t* plengt
{
unsigned char* result;
if(!input || 0 == input_len || !plength){
return NULL;
return nullptr;
}
result = new unsigned char[input_len / 4 * 3];

View File

@ -56,7 +56,7 @@ const std::string& S3fsCred::GetBucket()
void assert_is_sorted(struct curl_slist* list, const char *file, int line)
{
for(; list != NULL; list = list->next){
for(; list != nullptr; list = list->next){
std::string key1 = list->data;
key1.erase(key1.find(':'));
std::string key2 = list->data;
@ -74,7 +74,7 @@ void assert_is_sorted(struct curl_slist* list, const char *file, int line)
size_t curl_slist_length(const struct curl_slist* list)
{
size_t len = 0;
for(; list != NULL; list = list->next){
for(; list != nullptr; list = list->next){
++len;
}
return len;
@ -82,7 +82,7 @@ size_t curl_slist_length(const struct curl_slist* list)
void test_sort_insert()
{
struct curl_slist* list = NULL;
struct curl_slist* list = nullptr;
ASSERT_IS_SORTED(list);
// add to head
list = curl_slist_sort_insert(list, "2", "val");
@ -107,7 +107,7 @@ void test_sort_insert()
void test_slist_remove()
{
struct curl_slist* list = NULL;
struct curl_slist* list = nullptr;
// remove no elements
ASSERT_EQUALS(static_cast<size_t>(0), curl_slist_length(list));
@ -115,14 +115,14 @@ void test_slist_remove()
ASSERT_EQUALS(static_cast<size_t>(0), curl_slist_length(list));
// remove only element
list = NULL;
list = nullptr;
list = curl_slist_sort_insert(list, "1", "val");
ASSERT_EQUALS(static_cast<size_t>(1), curl_slist_length(list));
list = curl_slist_remove(list, "1");
ASSERT_EQUALS(static_cast<size_t>(0), curl_slist_length(list));
// remove head element
list = NULL;
list = nullptr;
list = curl_slist_sort_insert(list, "1", "val");
list = curl_slist_sort_insert(list, "2", "val");
ASSERT_EQUALS(static_cast<size_t>(2), curl_slist_length(list));
@ -131,7 +131,7 @@ void test_slist_remove()
curl_slist_free_all(list);
// remove tail element
list = NULL;
list = nullptr;
list = curl_slist_sort_insert(list, "1", "val");
list = curl_slist_sort_insert(list, "2", "val");
ASSERT_EQUALS(static_cast<size_t>(2), curl_slist_length(list));
@ -140,7 +140,7 @@ void test_slist_remove()
curl_slist_free_all(list);
// remove middle element
list = NULL;
list = nullptr;
list = curl_slist_sort_insert(list, "1", "val");
list = curl_slist_sort_insert(list, "2", "val");
list = curl_slist_sort_insert(list, "3", "val");

View File

@ -64,13 +64,13 @@ void test_base64()
unsigned char *buf;
size_t len;
ASSERT_STREQUALS(s3fs_base64(NULL, 0), NULL);
buf = s3fs_decode64(NULL, 0, &len);
ASSERT_BUFEQUALS(reinterpret_cast<const char *>(buf), len, NULL, 0);
ASSERT_STREQUALS(s3fs_base64(nullptr, 0), nullptr);
buf = s3fs_decode64(nullptr, 0, &len);
ASSERT_BUFEQUALS(reinterpret_cast<const char *>(buf), len, nullptr, 0);
ASSERT_STREQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>(""), 0), NULL);
ASSERT_STREQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>(""), 0), nullptr);
buf = s3fs_decode64("", 0, &len);
ASSERT_BUFEQUALS(reinterpret_cast<const char *>(buf), len, NULL, 0);
ASSERT_BUFEQUALS(reinterpret_cast<const char *>(buf), len, nullptr, 0);
ASSERT_STREQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("1"), 1), "MQ==");
buf = s3fs_decode64("MQ==", 4, &len);

View File

@ -67,10 +67,10 @@ template <> void assert_nequals(const std::string &x, const std::string &y, cons
void assert_strequals(const char *x, const char *y, const char *file, int line)
{
if(x == NULL && y == NULL){
if(x == nullptr && y == nullptr){
return;
// cppcheck-suppress nullPointerRedundantCheck
} else if(x == NULL || y == NULL || strcmp(x, y) != 0){
} else if(x == nullptr || y == nullptr || strcmp(x, y) != 0){
std::cerr << (x ? x : "null") << " != " << (y ? y : "null") << " at " << file << ":" << line << std::endl;
std::exit(1);
}
@ -78,10 +78,10 @@ void assert_strequals(const char *x, const char *y, const char *file, int line)
void assert_bufequals(const char *x, size_t len1, const char *y, size_t len2, const char *file, int line)
{
if(x == NULL && y == NULL){
if(x == nullptr && y == nullptr){
return;
// cppcheck-suppress nullPointerRedundantCheck
} else if(x == NULL || y == NULL || len1 != len2 || memcmp(x, y, len1) != 0){
} else if(x == nullptr || y == nullptr || len1 != len2 || memcmp(x, y, len1) != 0){
std::cerr << (x ? std::string(x, len1) : "null") << " != " << (y ? std::string(y, len2) : "null") << " at " << file << ":" << line << std::endl;
std::exit(1);
}

View File

@ -30,7 +30,7 @@
//------------------------------------------------
// ThreadPoolMan class variables
//------------------------------------------------
ThreadPoolMan* ThreadPoolMan::singleton = NULL;
ThreadPoolMan* ThreadPoolMan::singleton = nullptr;
//------------------------------------------------
// ThreadPoolMan class methods
@ -49,7 +49,7 @@ void ThreadPoolMan::Destroy()
{
if(ThreadPoolMan::singleton){
delete ThreadPoolMan::singleton;
ThreadPoolMan::singleton = NULL;
ThreadPoolMan::singleton = nullptr;
}
}
@ -96,13 +96,13 @@ void* ThreadPoolMan::Worker(void* arg)
}
}else{
S3FS_PRN_WARN("Got a semaphore, but there is no instruction.");
pparam = NULL;
pparam = nullptr;
}
}
if(pparam){
void* retval = pparam->pfunc(pparam->args);
if(NULL != retval){
if(nullptr != retval){
S3FS_PRN_WARN("The instruction function returned with somthign error code(%ld).", reinterpret_cast<long>(retval));
}
if(pparam->psem){
@ -112,7 +112,7 @@ void* ThreadPoolMan::Worker(void* arg)
}
}
return NULL;
return nullptr;
}
//------------------------------------------------
@ -204,7 +204,7 @@ bool ThreadPoolMan::StopThreads()
// wait for threads exiting
for(thread_list_t::const_iterator iter = thread_list.begin(); iter != thread_list.end(); ++iter){
void* retval = NULL;
void* retval = nullptr;
int result = pthread_join(*iter, &retval);
if(result){
S3FS_PRN_ERR("failed pthread_join - result(%d)", result);
@ -249,7 +249,7 @@ bool ThreadPoolMan::StartThreads(int count)
// run thread
pthread_t thread;
int result;
if(0 != (result = pthread_create(&thread, NULL, ThreadPoolMan::Worker, static_cast<void*>(this)))){
if(0 != (result = pthread_create(&thread, nullptr, ThreadPoolMan::Worker, static_cast<void*>(this)))){
S3FS_PRN_ERR("failed pthread_create with return code(%d)", result);
StopThreads(); // if possible, stop all threads
return false;
@ -262,7 +262,7 @@ bool ThreadPoolMan::StartThreads(int count)
bool ThreadPoolMan::SetInstruction(thpoolman_param* pparam)
{
if(!pparam){
S3FS_PRN_ERR("The parameter value is NULL.");
S3FS_PRN_ERR("The parameter value is nullptr.");
return false;
}

View File

@ -36,7 +36,7 @@ typedef void* (*thpoolman_worker)(void*); // same as start_routine
//
// [NOTE]
// The args member is a value that is an argument of the worker function.
// The psem member is allowed NULL. If it is not NULL, the post() method is
// The psem member is allowed nullptr. If it is not nullptr, the post() method is
// called when finishing the function.
//
struct thpoolman_param
@ -45,7 +45,7 @@ struct thpoolman_param
Semaphore* psem;
thpoolman_worker pfunc;
thpoolman_param() : args(NULL), psem(NULL), pfunc(NULL) {}
thpoolman_param() : args(nullptr), psem(nullptr), pfunc(nullptr) {}
};
typedef std::list<thpoolman_param*> thpoolman_params_t;

View File

@ -59,7 +59,7 @@ typedef struct xattr_value
unsigned char* pvalue;
size_t length;
explicit xattr_value(unsigned char* pval = NULL, size_t len = 0) : pvalue(pval), length(len) {}
explicit xattr_value(unsigned char* pval = nullptr, size_t len = 0) : pvalue(pval), length(len) {}
~xattr_value()
{
delete[] pvalue;
@ -110,7 +110,7 @@ class acl_t{
case LOG_DELIVERY_WRITE:
return "log-delivery-write";
case UNKNOWN:
return NULL;
return nullptr;
}
abort();
}
@ -182,7 +182,7 @@ struct etagpair
std::string etag; // expected etag value
int part_num; // part number
explicit etagpair(const char* petag = NULL, int part = -1) : etag(petag ? petag : ""), part_num(part) {}
explicit etagpair(const char* petag = nullptr, int part = -1) : etag(petag ? petag : ""), part_num(part) {}
~etagpair()
{
@ -232,7 +232,7 @@ struct filepart
bool is_copy; // whether is copy multipart
etagpair* petag; // use only parallel upload
explicit filepart(bool is_uploaded = false, int _fd = -1, off_t part_start = 0, off_t part_size = -1, bool is_copy_part = false, etagpair* petagpair = NULL) : uploaded(false), fd(_fd), startpos(part_start), size(part_size), is_copy(is_copy_part), petag(petagpair) {}
explicit filepart(bool is_uploaded = false, int _fd = -1, off_t part_start = 0, off_t part_size = -1, bool is_copy_part = false, etagpair* petagpair = nullptr) : uploaded(false), fd(_fd), startpos(part_start), size(part_size), is_copy(is_copy_part), petag(petagpair) {}
~filepart()
{
@ -247,7 +247,7 @@ struct filepart
startpos = 0;
size = -1;
is_copy = false;
petag = NULL;
petag = nullptr;
}
void add_etag_list(etaglist_t& list, int partnum = -1)
@ -255,7 +255,7 @@ struct filepart
if(-1 == partnum){
partnum = static_cast<int>(list.size()) + 1;
}
list.push_back(etagpair(NULL, partnum));
list.push_back(etagpair(nullptr, partnum));
petag = &list.back();
}

View File

@ -57,14 +57,14 @@ static unsigned char* create_random_data(off_t size)
int fd;
if(-1 == (fd = open("/dev/urandom", O_RDONLY))){
std::cerr << "[ERROR] Could not open /dev/urandom" << std::endl;
return NULL;
return nullptr;
}
unsigned char* pbuff;
if(NULL == (pbuff = reinterpret_cast<unsigned char*>(malloc(size)))){
if(nullptr == (pbuff = reinterpret_cast<unsigned char*>(malloc(size)))){
std::cerr << "[ERROR] Could not allocate memory." << std::endl;
close(fd);
return NULL;
return nullptr;
}
for(ssize_t readpos = 0, readcnt = 0; readpos < size; readpos += readcnt){
if(-1 == (readcnt = read(fd, &(pbuff[readpos]), static_cast<size_t>(size - readpos)))){
@ -72,7 +72,7 @@ static unsigned char* create_random_data(off_t size)
std::cerr << "[ERROR] Failed reading from /dev/urandom with errno: " << errno << std::endl;
free(pbuff);
close(fd);
return NULL;
return nullptr;
}
readcnt = 0;
}
@ -87,7 +87,7 @@ static off_t cvt_string_to_number(const char* pstr)
}
errno = 0;
char* ptemp = NULL;
char* ptemp = nullptr;
long long result = strtoll(pstr, &ptemp, 10);
if(!ptemp || ptemp == pstr || *ptemp != '\0'){
@ -206,7 +206,7 @@ int main(int argc, char** argv)
// make data and buffer
unsigned char* pData;
if(NULL == (pData = create_random_data(max_size))){
if(nullptr == (pData = create_random_data(max_size))){
exit(EXIT_FAILURE);
}