From 027cc6031461e67d4c6a9a3463540a8433f2fcd4 Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Sat, 6 Jun 2020 14:06:28 -0400 Subject: tools,tests: fixup errno handling to be more consistent The basic idea is that the C functions should return negative values on error and the terminal programs should return positive, non-zero values on error. Reported-by: Tom Hromatka Acked-by: Tom Hromatka Signed-off-by: Paul Moore --- tests/util.c | 6 +++--- tools/scmp_bpf_disasm.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/util.c b/tests/util.c index a84e475..d212c04 100644 --- a/tests/util.c +++ b/tests/util.c @@ -200,14 +200,14 @@ int util_file_write(const char *path) fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) - return errno; + return -errno; if (write(fd, buf, buf_len) < buf_len) { - int rc = errno; + int rc = -errno; close(fd); return rc; } if (close(fd) < 0) - return errno; + return -errno; return 0; } diff --git a/tools/scmp_bpf_disasm.c b/tools/scmp_bpf_disasm.c index 5c914b4..b95cdeb 100644 --- a/tools/scmp_bpf_disasm.c +++ b/tools/scmp_bpf_disasm.c @@ -288,7 +288,7 @@ static void bpf_decode_args(const bpf_instr_raw *bpf, unsigned int line) * @param file the BPF program * * Read the BPF program and display the instructions. Returns zero on success, - * negative values on failure. + * non-zero values on failure. * */ static int bpf_decode(FILE *file) @@ -424,7 +424,7 @@ static void bpf_dot_decode_args(const bpf_instr_raw *bpf, unsigned int line) * @param file the BPF program * * Read the BPF program and display the instructions. Returns zero on success, - * negative values on failure. + * non-zero values on failure. * */ static int bpf_dot_decode(FILE *file) -- cgit v1.2.1