libgslutil
1.2.3
|
Functions | |
int | gsl_set_perms (const char *path, const char *owner, const char *group, mode_t mode) |
Set file ownership and mode. More... | |
int | gsl_mkdir (const char *path, const char *owner, const char *group, mode_t mode) |
Create a directory. More... | |
int | gsl_recursive_unlink (const char *path) |
Recursively unlink a file or directory. More... | |
Utility functions for manipulating file ownerships and permissions.
int gsl_set_perms | ( | const char * | path, |
const char * | owner, | ||
const char * | group, | ||
mode_t | mode | ||
) |
Set file ownership and mode.
path | Pathname of file to operate on. |
owner | Name of user that will own file; pass 0 for unchanged |
group | Name of group that will own file; pass 0 for unchanged |
mode | New mode for file; pass -1 for unchanged |
0 | on success |
-1 | on error (and see errno) |
Changes the ownership, group and/or permissions of a file (or directory etc.; does not operate on symlinks but always dereferences them). Any errors are logged at LOG_WARNING
.
If lookup of owner or group fails, that parameter is ignored, errno is set to EINVAL
, and the function continues. When it completes it will return -1 to signal error.
The function then changes the ownership with chown(2)
. If this fails, errno is left set and the function continues. When the function completes it will return -1.
Next the function changes the file mode with chmod(2)
. If this fails, errno is left set (overriding any earlier error) and the function returns -1. If any other errors occurred earlier, the function also returns -1.
Only if all operations succeeded completely will the function return 0.
int gsl_mkdir | ( | const char * | path, |
const char * | owner, | ||
const char * | group, | ||
mode_t | mode | ||
) |
Create a directory.
path | Pathname of directory to create |
owner | Name of user that will own directory; pass 0 for unchanged |
group | Name of group for directory; pass 0 for unchanged |
mode | Octal mode for new directory, pass -1 for unchanged |
0 | on success |
-1 | on error (and see errno) |
Creates a directory at path. If the directory cannot be created then returns -1, leaving errno set as per mkdir(2)
(unless the error is EEXIST
, in which case the function continues). Note the directory is created with a mode of 0700 less umask.
If the directory is created (or existed), then gsl_set_perms() is called on it and the function returns 0 (leaving errno set as per gsl_set_perms() but ignoring that function's return value).
int gsl_recursive_unlink | ( | const char * | path | ) |
Recursively unlink a file or directory.
path | Path of file or directory to delete. |
0 | on success. |
-1 | on error (and see errno). |
Attempts to unlink a file or remove a directory. If the directory has contents, they are recursively unlinked/removed as well.
If an error occurs, the process continues, unlinking as much as possible. errno will be set as per the very first error to occur, which should give an indication of why the unlink failed.
This is basically the equivalent of the shell command rm -rf path
.