util_path: add function to check if a path exists

GitHub-ID: #20

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
Acked-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
Rafael Fonseca
2017-11-23 19:32:04 +01:00
committed by Michael Holzheu
parent 283e0bd5ea
commit df133846b5
2 changed files with 13 additions and 0 deletions

View File

@@ -20,5 +20,6 @@ bool util_path_is_readable(const char *fmt, ...);
bool util_path_is_writable(const char *fmt, ...);
bool util_path_is_dir(const char *fmt, ...);
bool util_path_is_reg_file(const char *fmt, ...);
bool util_path_exists(const char *fmt, ...);
#endif /** LIB_UTIL_PATH_H @} */

View File

@@ -194,3 +194,15 @@ free_str:
free(path);
return rc;
}
bool util_path_exists(const char *fmt, ...)
{
va_list ap;
char *path;
bool rc;
UTIL_VASPRINTF(&path, fmt, ap);
rc = access(path, F_OK) == 0;
free(path);
return rc;
}