4 - Variables and functions *must* be static, unless they have a
5 protoype, and are supposed to be exported.
7 - structs in MixedCase, variables + functions in lower_case
9 - The destructors always unregister the object from the next bigger
10 object, not the other way around
12 - To minimize strict aliasing violations we prefer unions over casting
14 - For robustness reasons destructors should be able to destruct
15 half-initialized objects, too
17 - Error codes are returned as negative Exxx. i.e. return -EINVAL. There
18 are some exceptions: for constructors its is OK to return NULL on
19 OOM. For lookup functions NULL is fine too for "not found".
21 Be strict with this. When you write a function that can fail due to
22 more than one cause, it *really* should have "int" as return value
25 - Don't bother with error checking if writing to stdout/stderr worked.
27 - Do not log errors from "library" code, only do so from "main
30 - Always check OOM. There's no excuse. In program code you can use
31 "log_oom()" for then printing a short message.
33 - Do not issue NSS requests (that includes user name and host name
34 lookups) from the main daemon as this might trigger deadlocks when
35 those lookups involve synchronously talking to services that we
36 would need to start up
38 - Don't synchronously talk to any other service, due to risk of
41 - Avoid fixed sized string buffers, unless you really know the maximum
42 size and that maximum size is small. They are a source of errors,
43 since they result in strings to be truncated. Often it is nicer to
44 use dynamic memory, or alloca(). If you do allocate fixed size
45 strings on the stack, then it's probably only OK if you either use a
46 maximum size such as LINE_MAX, or count in detail the maximum size a
47 string can have. Or in other words, if you use "char buf[256]" then
48 you are likely doing something wrong!
50 - Stay uniform. For example, always use "usec_t" for time
51 values. Don't usec mix msec, and usec and whatnot.
53 - Make use of _cleanup_free_ and friends. It makes your code much
56 - Be exceptionally careful when formatting and parsing floating point
57 numbers. Their syntax is locale dependent (i.e. "5.000" in en_US is
58 generally understood as 5, while on de_DE as 5000.).
71 But it's OK if you don't.
73 - Don't write "foo ()", write "foo()".
75 - Please use streq() and strneq() instead of strcmp(), strncmp() where applicable.
77 - Please do not allocate variables on the stack in the middle of code,
78 even if C99 allows it. Wrong:
94 - Unless you allocate an array, "double" is always the better choice
95 than "float". Processors speak "double" natively anyway, so this is
96 no speed benefit, and on calls like printf() "float"s get upgraded
97 to "double"s anyway, so there is no point.
99 - Don't invoke functions when you allocate variables on the stack. Wrong:
115 - Use "goto" for cleaning up, and only use it for that. i.e. you may
116 only jump to the end of a function, and little else.
118 - Think about the types you use. If a value cannot sensibly be
119 negative don't use "int", but use "unsigned".
121 - Don't use types like "short". They *never* make sense. Use ints,
122 longs, long longs, all in unsigned+signed fashion, and the fixed
123 size types uint32_t and so on, but nothing else.