[RFC] utils: os_unix: use access() for checking file existence

Rahul Bedarkar rahulbedarkar89 at gmail.com
Wed Jul 27 09:47:53 PDT 2016


Trying to open file for checking file existence seems to be too much.
Instead use access system call which is meant for the same.

Signed-off-by: Rahul Bedarkar <rahulbedarkar89 at gmail.com>
---
Note: Compile tested only on Linux/x86
---
 src/utils/os_unix.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c
index 0118d98..aa09709 100644
--- a/src/utils/os_unix.c
+++ b/src/utils/os_unix.c
@@ -435,11 +435,10 @@ char * os_readfile(const char *name, size_t *len)
 
 int os_file_exists(const char *fname)
 {
-	FILE *f = fopen(fname, "rb");
-	if (f == NULL)
+	if (access(fname, F_OK) == 0)
+		return 1;
+	else
 		return 0;
-	fclose(f);
-	return 1;
 }
 
 
-- 
1.8.3.2




More information about the Hostap mailing list