libcfe  0.12.1
some useful C-functions
config_files.c File Reference
#include "config.h"
#include "config_files.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <envz.h>
#include "check_path_exists.h"
#include "len.h"
Include dependency graph for config_files.c:

Go to the source code of this file.

Macros

#define ROUNDUP(a, b)   (((a) & ~((b)-1)) + (b))
 

Functions

int add_config_file (char **list, size_t *list_len, size_t *list_size, unsigned char id, char *file, size_t file_len, unsigned int check_path)
 
char * get_config_file (char *list, size_t list_size, unsigned char id)
 

Macro Definition Documentation

◆ ROUNDUP

#define ROUNDUP (   a,
 
)    (((a) & ~((b)-1)) + (b))

Definition at line 18 of file config_files.c.

Function Documentation

◆ add_config_file()

int add_config_file ( char **  list,
size_t *  list_len,
size_t *  list_size,
unsigned char  id,
char *  file,
size_t  file_len,
unsigned int  check_path 
)

Create a path relative to the current users home dir and store this path in a list. Before the path is stored it is checked if it exists (if CREATE_PATH is specified it is created) and has at least the requested permissions. This function sets errno on failure (return value -1).

Parameters
[in,out]listPointer to a pointer to the list.
[in,out]list_lenPointer to the length of this list, that means the amount of really used bytes in the list.
[in,out]list_sizePointer to the size of this list, that means the total amount of bytes allocated for the list.
[in]idThe identifing byte, used to indentify this path. 0 < id < 256.
[in]filePointer to the string that needs to be added to the users home dir to construct the requested path, may start with a '/', but not neseccarily.
[in]file_lenNumber of characters/bytes used from file.
[in]check_pathvalid values (maybe OR-ed):
  • CREATE_PATH
  • defined at stat(2):
    • S_IFMT
    • S_IFSOCK
    • S_IFLNK
    • S_IFREG
    • S_IFBLK
    • S_IFDIR
    • S_IFCHR
    • S_IFIFO
    • S_ISUID
    • S_ISGID
    • S_ISVTX
  • defined at check_path_exists():
    • PATH_R
    • PATH_W
    • PATH_X
Returns
return value:
  • 0 path succesfully added to the list, id is now a valid identifier
  • -1 failed, see errno for the possible problem

Definition at line 20 of file config_files.c.

Here is the call graph for this function:

◆ get_config_file()

char* get_config_file ( char *  list,
size_t  list_size,
unsigned char  id 
)

Get a pointer to the file associated with the given identifier.

Parameters
[in]listPointer to the list.
[in]list_sizeSize of this list, that means the total amount of bytes allocated for the list.
[in]idThe identifing byte, used to indentify this path. 0 < id < 256.
Returns
Pointer to the request file, or NULL if id is not found.

Definition at line 113 of file config_files.c.