Creating directory in c
Solution 1
According to this manpage, the 2nd parameter is a mode_t
, which is a numeric type and gives the wanted access mode of the directory. Here you should provide 0777
, an octal number meaning all of r
, w
and x
, and this is restricted by the umask
.
I don't know which of these informations apply to Windows.
Solution 2
The second argument of mkdir should be of type mode_t
. The chmod man page lists available modes (which can be OR'd together).
Solution 3
The second parameter of the mkdir
function is not a string. It's a flag combination to define the mode.
See the mkdir manual page for more information. See sys/stat.h for the complete flag list (search for "S_IRWXU")
Boardy
Develop apps and services in PHP, C#, C++, HTML, CSS, Jquery etc, recently started learning React.
Updated on July 22, 2022Comments
-
Boardy almost 2 years
I am working on some c code and am trying to programmatically create a directory. I found a while ago the mkdir(file, "w+) function to make the directory writable once its created but I've just noticed its creating a warning when compiled
warning: passing argument 2 of âmkdirâ makes integer from pointer without a cast
Below is the code I am using
void checkLogDirectoryExistsAndCreate() { struct stat st; char logPath[FILE_PATH_BUF_LEN]; sprintf(logPath, "%s/logs", logRotateConfiguration->logFileDir); if (stat(logPath, &st) != 0) { printf("Making log directory\n"); mkdir(logPath, "w+"); } }
Thanks for any help you can provide.