From bfb33f2f46a40023aa9820f4cdd99281e41250c1 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 25 Nov 2016 18:30:41 +0100 Subject: common: Fix 'unchecked return code' warnings Several tools are simply not checking return code of functions marked with 'warn_unused_result'. Provide wrappers for the read/write functions to avoid patching old code and providing proper error handling. Fix the remaining ones (calls to fgets() and system()). Signed-off-by: Boris Brezillon --- include/common.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include/common.h') diff --git a/include/common.h b/include/common.h index 93ef7f3..32b5d23 100644 --- a/include/common.h +++ b/include/common.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "config.h" @@ -226,6 +227,38 @@ long long util_get_bytes(const char *str); void util_print_bytes(long long bytes, int bracket); int util_srand(void); +/* + * The following helpers are here to avoid compiler complaints about unchecked + * return code. + * FIXME: The proper fix would be to check the return code in all those places, + * but it's usually placed in old code which have no proper exit path and + * handling errors requires rewriting a lot of code. + * + * WARNING: Please do not use these helpers in new code. Instead, make sure + * you check the function return code and provide coherent error handling in + * case of error. + */ +static inline ssize_t read_nocheck(int fd, void *buf, size_t count) +{ + return read(fd, buf, count); +} + +static inline ssize_t write_nocheck(int fd, void *buf, size_t count) +{ + return write(fd, buf, count); +} + +static inline ssize_t pread_nocheck(int fd, void *buf, size_t count, + off_t offset) +{ + return pread(fd, buf, count, offset); +} + +static inline ssize_t pwrite_nocheck(int fd, void *buf, size_t count, + off_t offset) +{ + return pwrite(fd, buf, count, offset); +} #ifdef __cplusplus } #endif -- cgit v1.2.3