]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
docs: mention RET_NERRNO() in CODING_STYLE.md
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Nov 2021 08:32:41 +0000 (09:32 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Nov 2021 07:04:09 +0000 (08:04 +0100)
docs/CODING_STYLE.md

index 34e04ed735a17779906af98539e137f3d800d076..eba1e1444e60a144dc21fc1a3cb7144e78dfaa4e 100644 (file)
@@ -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"