libcfe  0.12.1
some useful C-functions
check_path_exists.c File Reference
#include "config.h"
#include "check_path_exists.h"
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Include dependency graph for check_path_exists.c:

Go to the source code of this file.

Macros

#define perm_owner(m)   ((m & S_IRWXU) >> 6)
 
#define perm_group(m)   ((m & S_IRWXG) >> 3)
 
#define perm_other(m)   (m & S_IRWXO)
 
#define check_mode(m, c)   (((m) | (c)) == (m) ? 1 : 0)
 
#define checkpermission_root(m, c)   check_mode(perm_owner(m) | perm_group(m) | perm_other(m), c)
 

Functions

int read_all_groups (gid_t **g)
 
int checkpermission (struct stat *st, mode_t mode)
 
int check_path_exists (const char *path, mode_t type, mode_t mode)
 

Macro Definition Documentation

◆ check_mode

#define check_mode (   m,
 
)    (((m) | (c)) == (m) ? 1 : 0)

Definition at line 12 of file check_path_exists.c.

◆ checkpermission_root

#define checkpermission_root (   m,
 
)    check_mode(perm_owner(m) | perm_group(m) | perm_other(m), c)

Definition at line 13 of file check_path_exists.c.

◆ perm_group

#define perm_group (   m)    ((m & S_IRWXG) >> 3)

Definition at line 10 of file check_path_exists.c.

◆ perm_other

#define perm_other (   m)    (m & S_IRWXO)

Definition at line 11 of file check_path_exists.c.

◆ perm_owner

#define perm_owner (   m)    ((m & S_IRWXU) >> 6)

Definition at line 9 of file check_path_exists.c.

Function Documentation

◆ check_path_exists()

int check_path_exists ( const char *  path,
mode_t  type,
mode_t  mode 
)

Check the existence, type and permissions of a path.

Parameters
[in]pathPointer to a string representing the path.
[in]typeThe type the path should be (0 disables this check).
[in]modeType of access the path should have (0 disables this check).
Returns
return value
  • 0 the path exists and has at least the requested permissions
  • -1 the path does not exists or has not the requested permissions

Definition at line 60 of file check_path_exists.c.

Here is the call graph for this function:

◆ checkpermission()

int checkpermission ( struct stat *  st,
mode_t  mode 
)

Definition at line 32 of file check_path_exists.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_all_groups()

int read_all_groups ( gid_t **  g)

Definition at line 18 of file check_path_exists.c.

Here is the caller graph for this function: