Le merge / 20

This commit is contained in:
LuckyLaszlo
2022-08-14 06:30:27 +02:00
parent 84babec82b
commit ce0a004d28
15 changed files with 159 additions and 49 deletions

View File

@@ -171,6 +171,21 @@ file_type eval_file_type(const std::string &path)
return (IS_OTHER);
}
size_t eval_file_mode(std::string path, int mode)
{
if (access(path.c_str(), F_OK) == -1)
{
std::perror("err access()");
return 404; // NOT_FOUND, file doesn't exist
}
if (access(path.c_str(), mode) == -1)
{
std::perror("err access()");
return 403; // FORBIDDEN, file doesn't have execution permission
}
return 0;
}
void
replace_all_substr(
@@ -198,8 +213,8 @@ std::string str_tolower(std::string str)
}
// identify a line in a string, by delim (ex. '\n')
// delete this line from the string
// and return the deleted line
// delete this line from the string (and the following nl sequence characters)
// and return the deleted line (without the followinf nl sequence characters)
std::string
extract_line(std::string & str, size_t pos, std::string delim)
{
@@ -220,7 +235,7 @@ std::string
len = end - begin;
del_str = str.substr(begin, len);
str.erase(begin, len);
str.erase(begin, len + delim.size());
return del_str;
}