Nagios
4.4.7
Dev docs for Nagios core and neb-module hackers
|
path handling functions More...
#include <errno.h>
#include <sys/stat.h>
#include "snprintf.h"
Go to the source code of this file.
#define | NSPATH_MKDIR_SKIP_LAST (1 << 0) |
Don't mkdir() last element of path when calling nspath_mkdir_p() | |
char * | nspath_normalize (const char *orig_path) |
Normalize a path By "normalize", we mean that we convert dot-slash and dot-dot-slash embedded components into a legible continuous string of characters. More... | |
char * | nspath_absolute (const char *rel_path, const char *base) |
Make the "base"-relative path "rel_path" absolute. More... | |
char * | nspath_real (const char *rel_path, const char *base) |
Canonicalize the "base"-relative path "rel_path". More... | |
char * | nspath_absolute_dirname (const char *path, const char *base) |
Get absolute dirname of "path", relative to "base". More... | |
int | nspath_mkdir_p (const char *path, mode_t mode, int options) |
Recursively create a directory, just like mkdir_p would. More... | |
path handling functions
This library handles path normalization and resolution. It's nifty if you want to turn relative paths into absolute ones, or if you want to make insane ones sane, but without chdir()'ing your way around the filesystem.
char* nspath_absolute | ( | const char * | rel_path, |
const char * | base | ||
) |
Make the "base"-relative path "rel_path" absolute.
Turns the relative path "rel_path" into an absolute path and resolves it as if we were currently in "base". If "base" is NULL, the current working directory is used. If "base" is not null, it should be an absolute path for the result to make sense.
rel_path | The relative path to convert |
base | The base directory (if NULL, we use current working dir) |
char* nspath_absolute_dirname | ( | const char * | path, |
const char * | base | ||
) |
Get absolute dirname of "path", relative to "base".
path | Full path to target object (file or subdir) |
base | The base directory (if NULL, we use current working dir) |
int nspath_mkdir_p | ( | const char * | path, |
mode_t | mode, | ||
int | options | ||
) |
Recursively create a directory, just like mkdir_p would.
path | Path to create, in normalized form |
mode | Filemode (same as mkdir() takes) |
options | Options flag. See NSPATH_MKDIR_* for or-able options |
char* nspath_normalize | ( | const char * | orig_path | ) |
Normalize a path By "normalize", we mean that we convert dot-slash and dot-dot-slash embedded components into a legible continuous string of characters.
Leading and trailing slashes are kept exactly as they are in input, but with sequences of slashes reduced to a single one.
"foo/bar/.././lala.txt" becomes "foo/lala.txt" "../../../../bar/../foo/" becomes "/foo/" "////foo////././bar" becomes "/foo/bar"
orig_path | The path to normalize |
char* nspath_real | ( | const char * | rel_path, |
const char * | base | ||
) |
Canonicalize the "base"-relative path "rel_path".
errno gets properly set in case of errors.
rel_path | The path to transform |
base | The base we should operate relative to |