CODING_STYLE revision 11c9f1e48a683fb2e78ee531016099d567baa19a
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- 8ch indent, no tabs, except for files in man/ which are 2ch indent,
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott and still no tabs
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- We prefer /* comments */ over // comments, please. This is not C++, after
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott all. (Yes we know that C99 supports both kinds of comments, but still,
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Don't break code lines too eagerly. We do *not* force line breaks at
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott 80ch, all of today's screens should be much larger than that. But
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott then again, don't overdo it, ~140ch should be enough really.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Variables and functions *must* be static, unless they have a
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott prototype, and are supposed to be exported.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- structs in MixedCase (with exceptions, such as public API structs),
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott variables + functions in lower_case.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- The destructors always unregister the object from the next bigger
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott object, not the other way around
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- To minimize strict aliasing violations, we prefer unions over casting
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- For robustness reasons, destructors should be able to destruct
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott half-initialized objects, too
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Error codes are returned as negative Exxx. e.g. return -EINVAL. There
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott are some exceptions: for constructors, it is OK to return NULL on
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott OOM. For lookup functions, NULL is fine too for "not found".
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott Be strict with this. When you write a function that can fail due to
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott more than one cause, it *really* should have "int" as return value
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott for the error code.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Do not bother with error checking whether writing to stdout/stderr
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Do not log errors from "library" code, only do so from "main
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott program" code. (With one exception: it is OK to log with DEBUG level
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott from any code, with the exception of maybe inner loops).
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Always check OOM. There is no excuse. In program code, you can use
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott "log_oom()" for then printing a short message, but not in "library" code.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Do not issue NSS requests (that includes user name and host name
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott lookups) from PID 1 as this might trigger deadlocks when those
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott lookups involve synchronously talking to services that we would need
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Do not synchronously talk to any other service from PID 1, due to
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott risk of deadlocks
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott- Avoid fixed-size string buffers, unless you really know the maximum
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott size and that maximum size is small. They are a source of errors,
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott since they possibly result in truncated strings. It is often nicer
numbers. Their syntax is locale dependent (i.e. "5.000" in en_US is
- Use "goto" for cleaning up, and only use it for that. i.e. you may
- Public API calls (i.e. functions exported by our shared libraries)
- Do not POSIX_ME_HARDER unless necessary, i.e. avoid "+" in option string.
The only reason to include libgen.h is because dirname()
(void) unlink("/foo/bar/baz");
unlink("/foo/bar/baz");
2, i.e. stdin, stdout, stderr, should those fds be closed. Given the
t.foo = 7;
t.bar = "bazz";
starting with "sd-"), internal utility libraries from src/shared/,
#include <stdio.h>
#include "sd-daemon.h"
#include "util.h"
#include "frobnicator.h"
frobnicator.h is an placeholder name for any systemd component. The