diff mbox

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

Message ID 1469638073-5141-1-git-send-email-rahulbedarkar89@gmail.com
State Accepted
Headers show

Commit Message

Rahul Bedarkar July 27, 2016, 4:47 p.m. UTC
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@gmail.com>
---
Note: Compile tested only on Linux/x86
---
 src/utils/os_unix.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Jouni Malinen Aug. 7, 2016, 9:55 p.m. UTC | #1
On Wed, Jul 27, 2016 at 10:17:53PM +0530, Rahul Bedarkar wrote:
> Trying to open file for checking file existence seems to be too much.
> Instead use access system call which is meant for the same.

Thanks, applied.
diff mbox

Patch

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;
 }