X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=CODING_STYLE;h=f13f9becbc0839d246ebffa44c34bcfee6963f72;hp=91f09e80a87472f11c65a4f68fb51861a27a38bc;hb=9eb822a5a6b67eb82909f0d68213afbfcee6e93e;hpb=ae695cb23d75f9b43f0a302285bfae6a7565d6cc diff --git a/CODING_STYLE b/CODING_STYLE index 91f09e80a..f13f9becb 100644 --- a/CODING_STYLE +++ b/CODING_STYLE @@ -210,11 +210,12 @@ c) recvmsg() must get MSG_CMSG_CLOEXEC set d) F_DUPFD_CLOEXEC should be used instead of F_DUPFD, and so on -- We never use the XDG version of basename(). glibc defines it in - libgen.h. The only reason to include that file is because dirname() +- We never use the POSIX version of basename() (which glibc defines it in + libgen.h), only the GNU version (which glibc defines in string.h). + The only reason to include libgen.h is because dirname() is needed. Everytime you need that please immediately undefine basename(), and add a comment about it, so that no code ever ends up - using the XDG version! + using the POSIX version! - Use the bool type for booleans, not integers. One exception: in public headers (i.e those in src/systemd/sd-*.h) use integers after all, as "bool" @@ -292,3 +293,21 @@ - When returning a return code from main(), please preferably use EXIT_FAILURE and EXIT_SUCCESS as defined by libc. + +- The order in which header files are included doesn't matter too + much. systemd-internal headers must not rely on an include order, so + it is safe to include them in any order possible. + However, to not clutter global includes, and to make sure internal + definitions will not affect global headers, please always include the + headers of external components first (these are all headers enclosed + in <>), followed by our own exported headers (usually everything + that's prefixed by "sd-"), and then followed by internal headers. + Furthermore, in all three groups, order all includes alphabetically + so duplicate includes can easily be detected. + +- To implement an endless loop, use "for (;;)" rather than "while + (1)". The latter is a bit ugly anyway, since you probably really + meant "while (true)"... To avoid the discussion what the right + always-true expression for an infinite while() loop is our + recommendation is to simply write it without any such expression by + using "for (;;)".