mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 01:08:54 +00:00
Avoid mutating mybasename and mydirname parameters (#2004)
basename and dirname mutate their inputs but const_cast hid this
behavior. Also shuffle helpers to avoid unnecessary std::string.
Follows on to 404c284440
.
This commit is contained in:
parent
e30a5939d0
commit
f9f614a474
@ -225,7 +225,7 @@ std::string mydirname(const std::string& path)
|
||||
{
|
||||
AutoLock auto_lock(pbasename_lock);
|
||||
|
||||
return std::string(dirname(const_cast<char*>(path.c_str())));
|
||||
return mydirname(path.c_str());
|
||||
}
|
||||
|
||||
// safe variant of dirname
|
||||
@ -235,14 +235,18 @@ std::string mydirname(const char* path)
|
||||
if(!path || '\0' == path[0]){
|
||||
return std::string("");
|
||||
}
|
||||
return mydirname(std::string(path));
|
||||
|
||||
char *buf = strdup(path);
|
||||
std::string result = dirname(buf);
|
||||
free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string mybasename(const std::string& path)
|
||||
{
|
||||
AutoLock auto_lock(pbasename_lock);
|
||||
|
||||
return std::string(basename(const_cast<char*>(path.c_str())));
|
||||
return mybasename(path.c_str());
|
||||
}
|
||||
|
||||
// safe variant of basename
|
||||
@ -252,7 +256,11 @@ std::string mybasename(const char* path)
|
||||
if(!path || '\0' == path[0]){
|
||||
return std::string("");
|
||||
}
|
||||
return mybasename(std::string(path));
|
||||
|
||||
char *buf = strdup(path);
|
||||
std::string result = basename(buf);
|
||||
free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// mkdir --parents
|
||||
|
Loading…
Reference in New Issue
Block a user