aboutsummaryrefslogtreecommitdiff
path: root/include/common.h
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2016-11-25 18:30:41 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2016-12-06 19:38:16 +0100
commitbfb33f2f46a40023aa9820f4cdd99281e41250c1 (patch)
tree148d0f16e4936218b4d3f89a2ee45d8c12bcfb6b /include/common.h
parentb2a9601cebb67db9e02ac7bbd927a21aa95f5ba3 (diff)
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 <boris.brezillon@free-electrons.com>
Diffstat (limited to 'include/common.h')
-rw-r--r--include/common.h33
1 files changed, 33 insertions, 0 deletions
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 <errno.h>
#include <features.h>
#include <inttypes.h>
+#include <unistd.h>
#include <sys/sysmacros.h>
#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