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) {