summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorZhangjin Wu <falcon@tinylab.org>2023-06-28 16:08:32 +0300
committerWilly Tarreau <w@1wt.eu>2023-08-06 13:27:53 +0300
commit428905da6ec4a02d08dfcc09013035594f666a31 (patch)
tree482ca414d932f5a87f8b2c483a2ca7135718f96e /tools/include
parent2f98aca8aaef0fca36adff5c478af1788997debd (diff)
downloadlinux-428905da6ec4a02d08dfcc09013035594f666a31.tar.xz
tools/nolibc: sys.h: add a syscall return helper
Most of the library routines share the same syscall return logic: In general, a 0 return value indicates success. A -1 return value indicates an error, and an error number is stored in errno. [1] Let's add a __sysret() helper for the above logic to simplify the coding and shrink the code lines too. Thomas suggested to use inline function instead of macro for __sysret(). Willy suggested to make __sysret() be always inline. [1]: https://man7.org/linux/man-pages/man2/syscall.2.html Suggested-by: Willy Tarreau <w@1wt.eu> Link: https://lore.kernel.org/linux-riscv/ZH1+hkhiA2+ItSvX@1wt.eu/ Suggested-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/linux-riscv/ea4e7442-7223-4211-ba29-70821e907888@t-8ch.de/ Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Zhangjin Wu <falcon@tinylab.org> Signed-off-by: Willy Tarreau <w@1wt.eu>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/sys.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 5464f93e863e..097eef88cf7e 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -28,6 +28,16 @@
#include "errno.h"
#include "types.h"
+/* Syscall return helper, set errno as -ret when ret < 0 */
+static __inline__ __attribute__((unused, always_inline))
+long __sysret(long ret)
+{
+ if (ret < 0) {
+ SET_ERRNO(-ret);
+ ret = -1;
+ }
+ return ret;
+}
/* Functions in this file only describe syscalls. They're declared static so
* that the compiler usually decides to inline them while still being allowed