summaryrefslogtreecommitdiff
path: root/docs/CODING_STYLE.md
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-15 09:32:41 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-16 08:04:09 +0100
commit947796eac385651f6a66fc0ce925a301b49f6fa4 (patch)
tree751cc92056acb078cbc650e005799c8ac26f4b65 /docs/CODING_STYLE.md
parent7c248223ebafb9bfde9af978cd1ccfc57dcced26 (diff)
downloadsystemd-947796eac385651f6a66fc0ce925a301b49f6fa4.tar.gz
docs: mention RET_NERRNO() in CODING_STYLE.md
Diffstat (limited to 'docs/CODING_STYLE.md')
-rw-r--r--docs/CODING_STYLE.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md
index 34e04ed735..eba1e1444e 100644
--- a/docs/CODING_STYLE.md
+++ b/docs/CODING_STYLE.md
@@ -285,6 +285,25 @@ SPDX-License-Identifier: LGPL-2.1-or-later
one cause, it *really* should have an `int` as the return value for the error
code.
+- libc system calls typically return -1 on error (with the error code in
+ `errno`), and >= 0 on success. Use the RET_NERRNO() helper if you are looking
+ for a simple way to convert this libc style error returning into systemd
+ style error returning. e.g.
+
+ ```c
+ …
+ r = RET_NERRNO(unlink(t));
+ …
+ ```
+
+ or
+
+ ```c
+ …
+ r = RET_NERRNO(open("/some/file", O_RDONLY|O_CLOEXEC));
+ …
+ ```
+
- Do not bother with error checking whether writing to stdout/stderr worked.
- Do not log errors from "library" code, only do so from "main program"