From d2bb2b4681e1387f7ec0640a3d2b93d5683f9abe Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 28 Mar 2013 10:38:17 +0200 Subject: [PATCH] Add os_file_exists() Signed-off-by: Jouni Malinen --- src/utils/os.h | 7 +++++++ src/utils/os_unix.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/utils/os.h b/src/utils/os.h index d63ac294b..f019e26b1 100644 --- a/src/utils/os.h +++ b/src/utils/os.h @@ -239,6 +239,13 @@ int os_unsetenv(const char *name); */ char * os_readfile(const char *name, size_t *len); +/** + * os_file_exists - Check whether the specified file exists + * @fname: Path and name of the file + * Returns: 1 if the file exists or 0 if not + */ +int os_file_exists(const char *fname); + /** * os_zalloc - Allocate and zero memory * @size: Number of bytes to allocate diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index fa67fdfb6..008ec6b08 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -407,6 +407,16 @@ char * os_readfile(const char *name, size_t *len) } +int os_file_exists(const char *fname) +{ + FILE *f = fopen(fname, "rb"); + if (f == NULL) + return 0; + fclose(f); + return 1; +} + + #ifndef WPA_TRACE void * os_zalloc(size_t size) {