From 90df3741ced48554bcd113dc40599b8ea2972e1a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 18 Feb 2009 00:43:14 -0500 Subject: libsandbox: tweak errno handling in fopen() wrapper No point in saving/restoring the errno value if we don't make any C lib function calls. Signed-off-by: Mike Frysinger --- libsandbox/wrapper-funcs/fopen.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libsandbox/wrapper-funcs') diff --git a/libsandbox/wrapper-funcs/fopen.c b/libsandbox/wrapper-funcs/fopen.c index 18c5a7f..1a157d1 100644 --- a/libsandbox/wrapper-funcs/fopen.c +++ b/libsandbox/wrapper-funcs/fopen.c @@ -15,14 +15,17 @@ #define SB_FOPEN_PRE_CHECK static inline bool sb_fopen_pre_check(WRAPPER_ARGS_PROTO) { - save_errno(); if ((NULL != mode) && (mode[0] == 'r')) { + save_errno(); + /* If we're trying to read, fail normally if file does not stat */ struct stat st; if (-1 == stat(pathname, &st)) return false; + + restore_errno(); } - restore_errno(); + return true; } #endif -- cgit v1.2.3