Allow user to specify OS-specific file mode flags
This commit is contained in:
parent
8843785696
commit
ba58914cb1
|
@ -20,7 +20,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
int mkdir_r(const char *const path)
|
int mkdir_r(const char *const path, const int flags)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *dup = NULL;
|
char *dup = NULL;
|
||||||
|
@ -62,7 +62,7 @@ int mkdir_r(const char *const path)
|
||||||
if (!*dir)
|
if (!*dir)
|
||||||
/* Path starting with delimiter character. */
|
/* Path starting with delimiter character. */
|
||||||
;
|
;
|
||||||
else if (mkdir_r_port(dir))
|
else if (mkdir_r_port(dir, flags))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
dir = dup;
|
dir = dup;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
/**
|
/**
|
||||||
* Recursive directory creation.
|
* Recursive directory creation.
|
||||||
* @param path Directory path
|
* @param path Directory path
|
||||||
|
* @param flags File mode. Might be ignored if the underlying implementation
|
||||||
|
* does not support it.
|
||||||
* @return 0 if successful, -1 otherwise.
|
* @return 0 if successful, -1 otherwise.
|
||||||
* @note Sets @c errno to @c ENOMEM if internal dynamic allocation fails.
|
* @note Sets @c errno to @c ENOMEM if internal dynamic allocation fails.
|
||||||
* @note Sets @c errno to @c EINVAL if an invalid or empty directory path is
|
* @note Sets @c errno to @c EINVAL if an invalid or empty directory path is
|
||||||
|
@ -26,6 +28,6 @@
|
||||||
* @note Sets @c errno to @c ENOTDIR if one of the elements from @c path is not
|
* @note Sets @c errno to @c ENOTDIR if one of the elements from @c path is not
|
||||||
* a directory.
|
* a directory.
|
||||||
*/
|
*/
|
||||||
int mkdir_r(const char *const path);
|
int mkdir_r(const char *const path, int flags);
|
||||||
|
|
||||||
#endif /* MKDIR_R_H */
|
#endif /* MKDIR_R_H */
|
||||||
|
|
4
posix.c
4
posix.c
|
@ -19,7 +19,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
int mkdir_r_port(const char *const dir)
|
int mkdir_r_port(const char *const dir, const int flags)
|
||||||
{
|
{
|
||||||
if (!access(dir, 0))
|
if (!access(dir, 0))
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ int mkdir_r_port(const char *const dir)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mkdir(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
|
else if (mkdir(dir, flags))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -19,10 +19,12 @@
|
||||||
/**
|
/**
|
||||||
* Creates a directory using OS-specific API.
|
* Creates a directory using OS-specific API.
|
||||||
* @param dir Directory path.
|
* @param dir Directory path.
|
||||||
|
* @param flags File mode. Might be ignored if the underlying implementation
|
||||||
|
* does not support it.
|
||||||
* @return 0 if successful, -1 otherwise.
|
* @return 0 if successful, -1 otherwise.
|
||||||
* @note Sets @c errno to @c ENOTDIR if one of the elements from @c path is not
|
* @note Sets @c errno to @c ENOTDIR if one of the elements from @c path is not
|
||||||
* a directory.
|
* a directory.
|
||||||
*/
|
*/
|
||||||
int mkdir_r_port(const char *const dir);
|
int mkdir_r_port(const char *const dir, int flags);
|
||||||
|
|
||||||
#endif /* MKDIR_R_PRIVATE_H */
|
#endif /* MKDIR_R_PRIVATE_H */
|
||||||
|
|
Loading…
Reference in New Issue