mirror of
https://github.com/troglobit/libite.git
synced 2026-10-20 11:09:33 +00:00
New helper function, fexistf(), made for the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
1f6ff90d9e
commit
784a667584
2 files changed
+39
No files matched your search
@@ -29,8 +29,13 @@
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lite.h"
|
||||
|
||||
/**
|
||||
* Check if a file exists in the file system.
|
||||
* @param file File to look for, with full path.
|
||||
@@ -50,6 +55,39 @@ int fexist(const char *file)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like fexist() but with formatted string support
|
||||
* @param fmt Formatted string to be composed into the file to look for.
|
||||
*
|
||||
* This is a wrapper for the fexist() function in lite.h, lessening the
|
||||
* burden of having to compose the filename from parts in a seprate
|
||||
* buffer.
|
||||
*
|
||||
* @returns @c TRUE(1) if the @a file exists, otherwise @c FALSE(0).
|
||||
*/
|
||||
int fexistf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *file;
|
||||
int len;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(NULL, 0, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
file = alloca(len + 1);
|
||||
if (!file) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(file, len + 1, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return fexist(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
|
||||
Reference in new issue
Block a user