style—
/* * Style guide for the OpenBSD KNF (Kernel Normal Form). */ /* * VERY important single-line comments look like this. */ /* Most single-line comments look like this. */ /* * Multi-line comments look like this. Make them real sentences. * Fill them so they look like real paragraphs. */
<sys/*.h>) come first; normally, you'll need
<sys/types.h>OR
<sys/param.h>, but not both!
<sys/types.h>includes
<sys/cdefs.h>, and it's okay to depend on that.
#include <sys/types.h> /* Non-local includes in brackets. */
#include <net/if.h> #include <net/if_dl.h> #include <net/route.h> #include <netinet/in.h>
#include <paths.h>
#include "pathnames.h" /* Local includes in double quotes. */
static’. This should not be done in kernel land since it makes it impossible to use the kernel debugger. Functions used from other parts of the kernel are prototyped in the relevant include file. Functions that are used locally in more than one module go into a separate header file, e.g., extern.h. Prototypes should not have variable names associated with the types; i.e.,
void function(int);
void function(int a);
static char *function(int, const char *); static void usage(void);
__deadfrom
<sys/cdefs.h>for functions that don't return, i.e.,
__dead void abort(void);
__BEGIN_DECLS / __END_DECLSmatching)
enum enumtype { ONE, TWO } et; */
();
-Wor
-Wallflag should be used to verify that the compiler does not generate warnings such as) {
"usage: f [-12aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n" "usage: f [-a | -b] [-c [-de] [-n number]]\n"
fprintf(stderr, "usage: %s [-ab]\n", getprogname()); exit).