libite
Functions
makepath.c File Reference
#include <errno.h>
#include <libgen.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "lite.h"
Include dependency graph for makepath.c:

Functions

int mkpath (const char *dir, mode_t mode)
 makepath() but takes a mode_t argument. More...
 
int fmkpath (mode_t mode, const char *fmt,...)
 Formatted version of mkpath(). More...
 
int makepath (const char *dir)
 Create all components of the specified directory. More...
 

Detailed Description

Author
Joachim Wiberg
Date
2013-2021

Function Documentation

◆ fmkpath()

int fmkpath ( mode_t  mode,
const char *  fmt,
  ... 
)

Formatted version of mkpath().

Parameters
modeA mode_t mode to create directories with
fmtFormatted string to be composed into a pathname
Note
Notice the swapped arguments, compared to mkpath()!
Returns
POSIX OK(0) on success, otherwise -1 with errno set.

◆ makepath()

int makepath ( const char *  dir)

Create all components of the specified directory.

Parameters
dirDirectory to create.
Note
It is strongly recommended to use mkpath() over this function since it has the mode argument while this function default to 0777, which in most cases is insecure.
Returns
POSIX OK (0) on success, otherwise -1 and errno set appropriately.
Exceptions
EINVALon bad argument, or
ENOMEMwhen it fails allocating temporary memory.

For other error codes see the mkdir(2) syscall description.

◆ mkpath()

int mkpath ( const char *  dir,
mode_t  mode 
)

makepath() but takes a mode_t argument.

Parameters
dirDirectory to created, relative or absolute
modeA &mode_t mode to create dir with
Returns
POSIX OK(0) on success, otherwise -1 with errno set.