I was addicted to using mkdir during the program in ubuntu & C/C ++, so instead of a memorandum.
If it's windows, I can manage to use mkdir without worrying too much, but Option specification is required when using with ubuntu. If you make a mistake, you will create a directory that you do not have access to. It is kicked when creating a new file in that directory with the source immediately after.
Why can I create a directory without my own privileges? I don't know what it means (even though I haven't confirmed the specifications properly). Is it irrelevant when creating a directory because the authority is granted from the system side immediately after creating it? (Writing so far, I remembered ◯ Inter ☓ ◯ Inter ◯ RapiCa for a moment)
Well, what I wanted to make was to add the full path to the directory name specified by the relative path, A function that creates the directory and returns its full path. If the directory creation fails, it will return an empty string anyway (correspondence is miscellaneous).
okay. Anyway, I plan to operate it only when the directory structure is fixed in the system. (↑ A guy with this kind of thinking is a drag on team development)
std::string create_dir(std::string dir_name)
{
char buf[1024] = "";
if (NULL == getcwd(buf, sizeof(buf)))
return "";
std::string new_dir = buf + std::string("/") + dir_name;
if (0 != mkdir(new_dir.c_str(), S_IRWXO | S_IRWXU | S_IRWXG))
{
return "";
}
else
{
return new_dir;
}
}
For example, here
if (0 != mkdir(new_dir.c_str(), S_IRWXO))
If you do something like that, you will regret it later. Even though I made it myself, I do not have access authority (S_IRWXO grants full access authority to a third party) If you then try to create the file inside, you'll be confused.
Wouldn't it be nice if everyone had full access by default? If you are highly conscious, specify the option yourself. What's more, the mkdir page doesn't mention options. What do you mean Ya. At least put a link. ..
Recommended Posts