mirror of
https://github.com/troglobit/libite.git
synced 2026-11-17 19:30:17 +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 <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a file exists in the file system.
|
* Check if a file exists in the file system.
|
||||||
* @param file File to look for, with full path.
|
* @param file File to look for, with full path.
|
||||||
@@ -50,6 +55,39 @@ int fexist(const char *file)
|
|||||||
return 1;
|
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:
|
* Local Variables:
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ int erasef (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))
|
|||||||
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
||||||
|
|
||||||
int fexist (const char *file);
|
int fexist (const char *file);
|
||||||
|
int fexistf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));;
|
||||||
int fisdir (const char *path);
|
int fisdir (const char *path);
|
||||||
|
|
||||||
FILE *vfopenf (const char *mode, const char *fmt, va_list ap);
|
FILE *vfopenf (const char *mode, const char *fmt, va_list ap);
|
||||||
|
|||||||
Reference in new issue
Block a user