libgslutil  1.2.3
Functions
File ownership and permissions

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...
 

Detailed Description

Utility functions for manipulating file ownerships and permissions.

Function Documentation

◆ gsl_set_perms()

int gsl_set_perms ( const char *  path,
const char *  owner,
const char *  group,
mode_t  mode 
)

Set file ownership and mode.

Parameters
pathPathname of file to operate on.
ownerName of user that will own file; pass 0 for unchanged
groupName of group that will own file; pass 0 for unchanged
modeNew mode for file; pass -1 for unchanged
Return values
0on success
-1on 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.

◆ gsl_mkdir()

int gsl_mkdir ( const char *  path,
const char *  owner,
const char *  group,
mode_t  mode 
)

Create a directory.

Parameters
pathPathname of directory to create
ownerName of user that will own directory; pass 0 for unchanged
groupName of group for directory; pass 0 for unchanged
modeOctal mode for new directory, pass -1 for unchanged
Return values
0on success
-1on 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).

◆ gsl_recursive_unlink()

int gsl_recursive_unlink ( const char *  path)

Recursively unlink a file or directory.

Parameters
pathPath of file or directory to delete.
Return values
0on success.
-1on 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.