xref: /minix3/share/misc/style (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/* $NetBSD: style,v 1.51 2013/03/08 16:50:02 christos Exp $ */
25737b690SBen Gras
35737b690SBen Gras/*
45737b690SBen Gras * The revision control tag appears first, with a blank line after it.
55737b690SBen Gras * Copyright text appears after the revision control tag.
65737b690SBen Gras */
75737b690SBen Gras
85737b690SBen Gras/*
95737b690SBen Gras * The NetBSD source code style guide.
105737b690SBen Gras * (Previously known as KNF - Kernel Normal Form).
115737b690SBen Gras *
125737b690SBen Gras *	from: @(#)style	1.12 (Berkeley) 3/18/94
135737b690SBen Gras */
145737b690SBen Gras/*
155737b690SBen Gras * An indent(1) profile approximating the style outlined in
165737b690SBen Gras * this document lives in /usr/share/misc/indent.pro.  It is a
175737b690SBen Gras * useful tool to assist in converting code to KNF, but indent(1)
185737b690SBen Gras * output generated using this profile must not be considered to
195737b690SBen Gras * be an authoritative reference.
205737b690SBen Gras */
215737b690SBen Gras
225737b690SBen Gras/*
235737b690SBen Gras * Source code revision control identifiers appear after any copyright
245737b690SBen Gras * text.  Use the appropriate macros from <sys/cdefs.h>.  Usually only one
255737b690SBen Gras * source file per program contains a __COPYRIGHT() section.
265737b690SBen Gras * Historic Berkeley code may also have an __SCCSID() section.
275737b690SBen Gras * Only one instance of each of these macros can occur in each file.
285737b690SBen Gras * Don't use newlines in the identifiers.
295737b690SBen Gras */
305737b690SBen Gras#include <sys/cdefs.h>
315737b690SBen Gras__COPYRIGHT("@(#) Copyright (c) 2008\
325737b690SBen Gras The NetBSD Foundation, inc. All rights reserved.");
33*84d9c625SLionel Sambuc__RCSID("$NetBSD: style,v 1.51 2013/03/08 16:50:02 christos Exp $");
345737b690SBen Gras
355737b690SBen Gras/*
365737b690SBen Gras * VERY important single-line comments look like this.
375737b690SBen Gras */
385737b690SBen Gras
395737b690SBen Gras/* Most single-line comments look like this. */
405737b690SBen Gras
415737b690SBen Gras/*
425737b690SBen Gras * Multi-line comments look like this.  Make them real sentences.  Fill
435737b690SBen Gras * them so they look like real paragraphs.
445737b690SBen Gras */
455737b690SBen Gras
465737b690SBen Gras/*
475737b690SBen Gras * Attempt to wrap lines longer than 80 characters appropriately.
485737b690SBen Gras * Refer to the examples below for more information.
495737b690SBen Gras */
505737b690SBen Gras
515737b690SBen Gras/*
525737b690SBen Gras * EXAMPLE HEADER FILE:
535737b690SBen Gras *
545737b690SBen Gras * A header file should protect itself against multiple inclusion.
555737b690SBen Gras * E.g, <sys/socket.h> would contain something like:
565737b690SBen Gras */
575737b690SBen Gras#ifndef _SYS_SOCKET_H_
585737b690SBen Gras#define _SYS_SOCKET_H_
595737b690SBen Gras/*
605737b690SBen Gras * Contents of #include file go between the #ifndef and the #endif at the end.
615737b690SBen Gras */
625737b690SBen Gras#endif /* !_SYS_SOCKET_H_ */
635737b690SBen Gras/*
645737b690SBen Gras * END OF EXAMPLE HEADER FILE.
655737b690SBen Gras */
665737b690SBen Gras
675737b690SBen Gras/*
685737b690SBen Gras * If a header file requires structures, defines, typedefs, etc. from
695737b690SBen Gras * another header file it should include that header file and not depend
705737b690SBen Gras * on the including file for that header including both.  If there are
715737b690SBen Gras * exceptions to this for specific headers it should be clearly documented
725737b690SBen Gras * in the headers and, if appropriate, the documentation.  Nothing in this
735737b690SBen Gras * rule should suggest relaxation of the multiple inclusion rule and the
745737b690SBen Gras * application programmer should be free to include both regardless.
755737b690SBen Gras */
765737b690SBen Gras
775737b690SBen Gras/*
785737b690SBen Gras * Kernel include files come first.
795737b690SBen Gras */
80*84d9c625SLionel Sambuc#include <sys/param.h>		/* <sys/param.h> first, */
81*84d9c625SLionel Sambuc#include <sys/types.h>		/*   <sys/types.h> next, */
82*84d9c625SLionel Sambuc#include <sys/ioctl.h>		/*   and then the rest, */
83*84d9c625SLionel Sambuc#include <sys/socket.h>		/*   sorted lexicographically.  */
84*84d9c625SLionel Sambuc#include <sys/stat.h>
85*84d9c625SLionel Sambuc#include <sys/wait.h>		/* Non-local includes in brackets.  */
865737b690SBen Gras
875737b690SBen Gras/*
885737b690SBen Gras * If it's a network program, put the network include files next.
895737b690SBen Gras * Group the includes files by subdirectory.
905737b690SBen Gras */
915737b690SBen Gras#include <net/if.h>
925737b690SBen Gras#include <net/if_dl.h>
935737b690SBen Gras#include <net/route.h>
945737b690SBen Gras#include <netinet/in.h>
955737b690SBen Gras#include <protocols/rwhod.h>
965737b690SBen Gras
975737b690SBen Gras/*
985737b690SBen Gras * Then there's a blank line, followed by the /usr include files.
99*84d9c625SLionel Sambuc * The /usr include files should be sorted lexicographically!
1005737b690SBen Gras */
1015737b690SBen Gras#include <assert.h>
1025737b690SBen Gras#include <errno.h>
1035737b690SBen Gras#include <inttypes.h>
1045737b690SBen Gras#include <stdio.h>
1055737b690SBen Gras#include <stdlib.h>
1065737b690SBen Gras
1075737b690SBen Gras/*
1085737b690SBen Gras * Global pathnames are defined in /usr/include/paths.h.  Pathnames local
1095737b690SBen Gras * to the program go in pathnames.h in the local directory.
1105737b690SBen Gras */
1115737b690SBen Gras#include <paths.h>
1125737b690SBen Gras
1135737b690SBen Gras/* Then, there's a blank line, and the user include files. */
1145737b690SBen Gras#include "pathnames.h"		/* Local includes in double quotes. */
1155737b690SBen Gras
1165737b690SBen Gras/*
1175737b690SBen Gras * ANSI function declarations for private functions (i.e. functions not used
1185737b690SBen Gras * elsewhere) and the main() function go at the top of the source module.
1195737b690SBen Gras * Don't associate a name with the types.  I.e. use:
1205737b690SBen Gras *	void function(int);
1215737b690SBen Gras * Use your discretion on indenting between the return type and the name, and
1225737b690SBen Gras * how to wrap a prototype too long for a single line.  In the latter case,
1235737b690SBen Gras * lining up under the initial left parenthesis may be more readable.
1245737b690SBen Gras * In any case, consistency is important!
1255737b690SBen Gras */
1265737b690SBen Grasstatic char *function(int, int, float, int);
1275737b690SBen Grasstatic int dirinfo(const char *, struct stat *, struct dirent *,
1285737b690SBen Gras		   struct statfs *, int *, char **[]);
1295737b690SBen Grasstatic void usage(void) __dead;	/* declare functions that don't return dead */
1305737b690SBen Gras
1315737b690SBen Gras/*
1325737b690SBen Gras * Macros are capitalized, parenthesized, and should avoid side-effects.
1335737b690SBen Gras * Spacing before and after the macro name may be any whitespace, though
1345737b690SBen Gras * use of TABs should be consistent through a file.
1355737b690SBen Gras * If they are an inline expansion of a function, the function is defined
1365737b690SBen Gras * all in lowercase, the macro has the same name all in uppercase.
1375737b690SBen Gras * If the macro is an expression, wrap the expression in parenthesis.
1385737b690SBen Gras * If the macro is more than a single statement, use ``do { ... } while (0)'',
1395737b690SBen Gras * so that a trailing semicolon works.  Right-justify the backslashes; it
1405737b690SBen Gras * makes it easier to read. The CONSTCOND comment is to satisfy lint(1).
1415737b690SBen Gras */
1425737b690SBen Gras#define	MACRO(v, w, x, y)						\
1435737b690SBen Grasdo {									\
1445737b690SBen Gras	v = (x) + (y);							\
1455737b690SBen Gras	w = (y) + 2;							\
1465737b690SBen Gras} while (/* CONSTCOND */ 0)
1475737b690SBen Gras
1485737b690SBen Gras#define	DOUBLE(x) ((x) * 2)
1495737b690SBen Gras
1505737b690SBen Gras/* Enum types are capitalized.  No comma on the last element. */
1515737b690SBen Grasenum enumtype {
1525737b690SBen Gras	ONE,
1535737b690SBen Gras	TWO
1545737b690SBen Gras} et;
1555737b690SBen Gras
1565737b690SBen Gras/*
1575737b690SBen Gras * When declaring variables in structures, declare them organized by use in
1585737b690SBen Gras * a manner to attempt to minimize memory wastage because of compiler alignment
1595737b690SBen Gras * issues, then by size, and then by alphabetical order. E.g, don't use
1605737b690SBen Gras * ``int a; char *b; int c; char *d''; use ``int a; int b; char *c; char *d''.
1615737b690SBen Gras * Each variable gets its own type and line, although an exception can be made
1625737b690SBen Gras * when declaring bitfields (to clarify that it's part of the one bitfield).
1635737b690SBen Gras * Note that the use of bitfields in general is discouraged.
1645737b690SBen Gras *
1655737b690SBen Gras * Major structures should be declared at the top of the file in which they
1665737b690SBen Gras * are used, or in separate header files, if they are used in multiple
1675737b690SBen Gras * source files.  Use of the structures should be by separate declarations
1685737b690SBen Gras * and should be "extern" if they are declared in a header file.
1695737b690SBen Gras *
1705737b690SBen Gras * It may be useful to use a meaningful prefix for each member name.
1715737b690SBen Gras * E.g, for ``struct softc'' the prefix could be ``sc_''.
1725737b690SBen Gras */
1735737b690SBen Grasstruct foo {
1745737b690SBen Gras	struct foo *next;	/* List of active foo */
1755737b690SBen Gras	struct mumble amumble;	/* Comment for mumble */
1765737b690SBen Gras	int bar;
1775737b690SBen Gras	unsigned int baz:1,	/* Bitfield; line up entries if desired */
1785737b690SBen Gras		     fuz:5,
1795737b690SBen Gras		     zap:2;
1805737b690SBen Gras	uint8_t flag;
1815737b690SBen Gras};
1825737b690SBen Grasstruct foo *foohead;		/* Head of global foo list */
1835737b690SBen Gras
1845737b690SBen Gras/* Make the structure name match the typedef. */
1855737b690SBen Grastypedef struct BAR {
1865737b690SBen Gras	int level;
1875737b690SBen Gras} BAR;
1885737b690SBen Gras
1895737b690SBen Gras/* C99 uintN_t is preferred over u_intN_t. */
1905737b690SBen Grasuint32_t zero;
1915737b690SBen Gras
1925737b690SBen Gras/*
1935737b690SBen Gras * All major routines should have a comment briefly describing what
1945737b690SBen Gras * they do.  The comment before the "main" routine should describe
1955737b690SBen Gras * what the program does.
1965737b690SBen Gras */
1975737b690SBen Grasint
1985737b690SBen Grasmain(int argc, char *argv[])
1995737b690SBen Gras{
2005737b690SBen Gras	long num;
2015737b690SBen Gras	int ch;
2025737b690SBen Gras	char *ep;
2035737b690SBen Gras
2045737b690SBen Gras	/*
2055737b690SBen Gras	 * At the start of main(), call setprogname() to set the program
2065737b690SBen Gras	 * name.  This does nothing on NetBSD, but increases portability
2075737b690SBen Gras	 * to other systems.
2085737b690SBen Gras	 */
2095737b690SBen Gras	setprogname(argv[0]);
2105737b690SBen Gras
2115737b690SBen Gras	/*
2125737b690SBen Gras	 * For consistency, getopt should be used to parse options.
2135737b690SBen Gras	 * Options should be sorted in the getopt call and the switch
2145737b690SBen Gras	 * statement, unless parts of the switch cascade.  For the
2155737b690SBen Gras	 * sorting order, see the usage() example below.  Don't forget
2165737b690SBen Gras	 * to add option descriptions to the usage and the manpage.
2175737b690SBen Gras	 * Elements in a switch statement that cascade should have a
2185737b690SBen Gras	 * FALLTHROUGH comment.  Numerical arguments should be checked
2195737b690SBen Gras	 * for accuracy.  Code that cannot be reached should have a
2205737b690SBen Gras	 * NOTREACHED comment.
2215737b690SBen Gras	 */
2225737b690SBen Gras	while ((ch = getopt(argc, argv, "abn:")) != -1) {
2235737b690SBen Gras		switch (ch) {		/* Indent the switch. */
2245737b690SBen Gras		case 'a':		/* Don't indent the case. */
2255737b690SBen Gras			aflag = 1;
2265737b690SBen Gras			/* FALLTHROUGH */
2275737b690SBen Gras		case 'b':
2285737b690SBen Gras			bflag = 1;
2295737b690SBen Gras			break;
2305737b690SBen Gras		case 'n':
2315737b690SBen Gras			errno = 0;
2325737b690SBen Gras			num = strtol(optarg, &ep, 10);
2335737b690SBen Gras			if (num <= 0 || *ep != '\0' || (errno == ERANGE &&
2345737b690SBen Gras			    (num == LONG_MAX || num == LONG_MIN)) )
2355737b690SBen Gras				errx(1, "illegal number -- %s", optarg);
2365737b690SBen Gras			break;
2375737b690SBen Gras		case '?':
2385737b690SBen Gras		default:
2395737b690SBen Gras			usage();
2405737b690SBen Gras			/* NOTREACHED */
2415737b690SBen Gras		}
2425737b690SBen Gras	}
2435737b690SBen Gras	argc -= optind;
2445737b690SBen Gras	argv += optind;
2455737b690SBen Gras
2465737b690SBen Gras	/*
2475737b690SBen Gras	 * Space after keywords (while, for, return, switch).  No braces are
2485737b690SBen Gras	 * required for control statements with only a single statement,
2495737b690SBen Gras	 * unless it's a long statement.
2505737b690SBen Gras	 *
2515737b690SBen Gras	 * Forever loops are done with for's, not while's.
2525737b690SBen Gras	 */
2535737b690SBen Gras	for (p = buf; *p != '\0'; ++p)
2545737b690SBen Gras		continue;		/* Explicit no-op */
2555737b690SBen Gras	for (;;)
2565737b690SBen Gras		stmt;
2575737b690SBen Gras
2585737b690SBen Gras	/*
2595737b690SBen Gras	 * Braces are required for control statements with a single statement
2605737b690SBen Gras	 * that may expand to nothing.
2615737b690SBen Gras	 */
2625737b690SBen Gras#ifdef DEBUG_FOO
2635737b690SBen Gras#define DPRINTF(a) printf a
2645737b690SBen Gras#else
2655737b690SBen Gras#define DPRINTF(a)
2665737b690SBen Gras#endif
2675737b690SBen Gras	if (broken) {
2685737b690SBen Gras		DPRINTF(("broken is %d\n", broken));
2695737b690SBen Gras	}
2705737b690SBen Gras
2715737b690SBen Gras	/*
2725737b690SBen Gras	 * Parts of a for loop may be left empty.  Don't put declarations
2735737b690SBen Gras	 * inside blocks unless the routine is unusually complicated.
2745737b690SBen Gras	 */
2755737b690SBen Gras	for (; cnt < 15; cnt++) {
2765737b690SBen Gras		stmt1;
2775737b690SBen Gras		stmt2;
2785737b690SBen Gras	}
2795737b690SBen Gras
2805737b690SBen Gras	/* Second level indents are four spaces. */
2815737b690SBen Gras	while (cnt < 20)
2825737b690SBen Gras		z = a + really + long + statement + that + needs + two + lines +
2835737b690SBen Gras		    gets + indented + four + spaces + on + the + second +
2845737b690SBen Gras		    and + subsequent + lines;
2855737b690SBen Gras
2865737b690SBen Gras	/*
2875737b690SBen Gras	 * Closing and opening braces go on the same line as the else.
2885737b690SBen Gras	 * Don't add braces that aren't necessary except in cases where
2895737b690SBen Gras	 * there are ambiguity or readability issues.
2905737b690SBen Gras	 */
2915737b690SBen Gras	if (test) {
2925737b690SBen Gras		/*
2935737b690SBen Gras		 * I have a long comment here.
2945737b690SBen Gras		 */
2955737b690SBen Gras#ifdef zorro
2965737b690SBen Gras		z = 1;
2975737b690SBen Gras#else
2985737b690SBen Gras		b = 3;
2995737b690SBen Gras#endif
3005737b690SBen Gras	} else if (bar) {
3015737b690SBen Gras		stmt;
3025737b690SBen Gras		stmt;
3035737b690SBen Gras	} else
3045737b690SBen Gras		stmt;
3055737b690SBen Gras
3065737b690SBen Gras	/* No spaces after function names. */
3075737b690SBen Gras	if ((result = function(a1, a2, a3, a4)) == NULL)
3085737b690SBen Gras		exit(1);
3095737b690SBen Gras
3105737b690SBen Gras	/*
3115737b690SBen Gras	 * Unary operators don't require spaces, binary operators do.
3125737b690SBen Gras	 * Don't excessively use parenthesis, but they should be used if
3135737b690SBen Gras	 * statement is really confusing without them, such as:
3145737b690SBen Gras	 * a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1;
3155737b690SBen Gras	 */
3165737b690SBen Gras	a = ((b->c[0] + ~d == (e || f)) || (g && h)) ? i : (j >> 1);
3175737b690SBen Gras	k = !(l & FLAGS);
3185737b690SBen Gras
3195737b690SBen Gras	/*
3205737b690SBen Gras	 * Exits should be EXIT_SUCCESS on success, and EXIT_FAILURE on
3215737b690SBen Gras	 * failure.  Don't denote all the possible exit points, using the
3225737b690SBen Gras	 * integers 1 through 127.  Avoid obvious comments such as "Exit
3235737b690SBen Gras	 * 0 on success.". Since main is a function that returns an int,
3245737b690SBen Gras	 * prefer returning from it, than calling exit.
3255737b690SBen Gras	 */
3265737b690SBen Gras	return EXIT_SUCCESS;
3275737b690SBen Gras}
3285737b690SBen Gras
3295737b690SBen Gras/*
3305737b690SBen Gras * The function type must be declared on a line by itself
3315737b690SBen Gras * preceding the function.
3325737b690SBen Gras */
3335737b690SBen Grasstatic char *
3345737b690SBen Grasfunction(int a1, int a2, float fl, int a4)
3355737b690SBen Gras{
3365737b690SBen Gras	/*
3375737b690SBen Gras	 * When declaring variables in functions declare them sorted by size,
3385737b690SBen Gras	 * then in alphabetical order; multiple ones per line are okay.
3395737b690SBen Gras	 * Function prototypes should go in the include file "extern.h".
3405737b690SBen Gras	 * If a line overflows reuse the type keyword.
3415737b690SBen Gras	 *
3425737b690SBen Gras	 * DO NOT initialize variables in the declarations.
3435737b690SBen Gras	 */
3445737b690SBen Gras	extern u_char one;
3455737b690SBen Gras	extern char two;
3465737b690SBen Gras	struct foo three, *four;
3475737b690SBen Gras	double five;
3485737b690SBen Gras	int *six, seven;
3495737b690SBen Gras	char *eight, *nine, ten, eleven, twelve, thirteen;
3505737b690SBen Gras	char fourteen, fifteen, sixteen;
3515737b690SBen Gras
3525737b690SBen Gras	/*
3535737b690SBen Gras	 * Casts and sizeof's are not followed by a space.  NULL is any
3545737b690SBen Gras	 * pointer type, and doesn't need to be cast, so use NULL instead
3555737b690SBen Gras	 * of (struct foo *)0 or (struct foo *)NULL.  Also, test pointers
3565737b690SBen Gras	 * against NULL.  I.e. use:
3575737b690SBen Gras	 *
3585737b690SBen Gras	 *	(p = f()) == NULL
3595737b690SBen Gras	 * not:
3605737b690SBen Gras	 *	!(p = f())
3615737b690SBen Gras	 *
362*84d9c625SLionel Sambuc	 * The notable exception here is variadic functions. Since our
3635737b690SBen Gras	 * code is designed to compile and work on different environments
3645737b690SBen Gras	 * where we don't have control over the NULL definition (on NetBSD
3655737b690SBen Gras	 * it is defined as ((void *)0), but on other systems it can be
3665737b690SBen Gras	 * defined as (0) and both definitions are valid under ANSI C), it
3675737b690SBen Gras	 * it advised to cast NULL to a pointer on varyadic functions,
3685737b690SBen Gras	 * because on machines where sizeof(pointer) != sizeof(int) and in
3695737b690SBen Gras	 * the absence of a prototype in scope, passing an un-casted NULL,
3705737b690SBen Gras	 * will result in passing an int on the stack instead of a pointer.
3715737b690SBen Gras	 *
3725737b690SBen Gras	 * Don't use `!' for tests unless it's a boolean.
3735737b690SBen Gras	 * E.g. use "if (*p == '\0')", not "if (!*p)".
3745737b690SBen Gras	 *
3755737b690SBen Gras	 * Routines returning ``void *'' should not have their return
3765737b690SBen Gras	 * values cast to more specific pointer types.
3775737b690SBen Gras	 *
3785737b690SBen Gras	 * Prefer sizeof(*var) over sizeof(type) because if type changes,
3795737b690SBen Gras	 * the change needs to be done in one place.
3805737b690SBen Gras	 *
3815737b690SBen Gras	 * Use err/warn(3), don't roll your own!
3825737b690SBen Gras	 */
3835737b690SBen Gras	if ((four = malloc(sizeof(*four))) == NULL)
3845737b690SBen Gras		err(1, NULL);
3855737b690SBen Gras	if ((six = (int *)overflow()) == NULL)
3865737b690SBen Gras		errx(1, "Number overflowed.");
3875737b690SBen Gras
3885737b690SBen Gras	/* No parentheses are needed around the return value. */
3895737b690SBen Gras	return eight;
3905737b690SBen Gras}
3915737b690SBen Gras
3925737b690SBen Gras/*
3935737b690SBen Gras * Use ANSI function declarations.  ANSI function braces look like
3945737b690SBen Gras * old-style (K&R) function braces.
3955737b690SBen Gras * As per the wrapped prototypes, use your discretion on how to format
3965737b690SBen Gras * the subsequent lines.
3975737b690SBen Gras */
3985737b690SBen Grasstatic int
3995737b690SBen Grasdirinfo(const char *p, struct stat *sb, struct dirent *de, struct statfs *sf,
4005737b690SBen Gras	int *rargc, char **rargv[])
4015737b690SBen Gras{	/* Insert an empty line if the function has no local variables. */
4025737b690SBen Gras
4035737b690SBen Gras	/*
4045737b690SBen Gras	 * In system libraries, catch obviously invalid function arguments
4055737b690SBen Gras	 * using _DIAGASSERT(3).
4065737b690SBen Gras	 */
4075737b690SBen Gras	_DIAGASSERT(p != NULL);
4085737b690SBen Gras	_DIAGASSERT(filedesc != -1);
4095737b690SBen Gras
4105737b690SBen Gras	if (stat(p, sb) < 0)
4115737b690SBen Gras		err(1, "Unable to stat %s", p);
4125737b690SBen Gras
4135737b690SBen Gras	/*
4145737b690SBen Gras	 * To printf quantities that might be larger that "long", include
4155737b690SBen Gras	 * <inttypes.h>, cast quantities to intmax_t or uintmax_t and use
4165737b690SBen Gras	 * PRI?MAX constants.
4175737b690SBen Gras	 */
4185737b690SBen Gras	(void)printf("The size of %s is %" PRIdMAX " (%#" PRIxMAX ")\n", p,
4195737b690SBen Gras	    (intmax_t)sb->st_size, (uintmax_t)sb->st_size);
4205737b690SBen Gras
4215737b690SBen Gras	/*
4225737b690SBen Gras	 * To printf quantities of known bit-width, use the corresponding
4235737b690SBen Gras	 * defines (generally only done within NetBSD for quantities that
4245737b690SBen Gras	 * exceed 32-bits).
4255737b690SBen Gras	 */
4265737b690SBen Gras	(void)printf("%s uses %" PRId64 " blocks and has flags %#" PRIx32 "\n",
4275737b690SBen Gras	    p, sb->st_blocks, sb->st_flags);
4285737b690SBen Gras
4295737b690SBen Gras	/*
4305737b690SBen Gras	 * There are similar constants that should be used with the *scanf(3)
4315737b690SBen Gras	 * family of functions: SCN?MAX, SCN?64, etc.
4325737b690SBen Gras	 */
4335737b690SBen Gras}
4345737b690SBen Gras
4355737b690SBen Gras/*
4365737b690SBen Gras * Functions that support variable numbers of arguments should look like this.
4375737b690SBen Gras * (With the #include <stdarg.h> appearing at the top of the file with the
4385737b690SBen Gras * other include files.)
4395737b690SBen Gras */
4405737b690SBen Gras#include <stdarg.h>
4415737b690SBen Gras
4425737b690SBen Grasvoid
4435737b690SBen Grasvaf(const char *fmt, ...)
4445737b690SBen Gras{
4455737b690SBen Gras	va_list ap;
4465737b690SBen Gras
4475737b690SBen Gras	va_start(ap, fmt);
4485737b690SBen Gras	STUFF;
4495737b690SBen Gras	va_end(ap);
4505737b690SBen Gras				/* No return needed for void functions. */
4515737b690SBen Gras}
4525737b690SBen Gras
4535737b690SBen Grasstatic void
4545737b690SBen Grasusage(void)
4555737b690SBen Gras{
4565737b690SBen Gras
4575737b690SBen Gras	/*
4585737b690SBen Gras	 * Use printf(3), not fputs/puts/putchar/whatever, it's faster and
4595737b690SBen Gras	 * usually cleaner, not to mention avoiding stupid bugs.
4605737b690SBen Gras	 * Use snprintf(3) or strlcpy(3)/strlcat(3) instead of sprintf(3);
4615737b690SBen Gras	 * again to avoid stupid bugs.
4625737b690SBen Gras	 *
4635737b690SBen Gras	 * Usage statements should look like the manual pages.
4645737b690SBen Gras	 * Options w/o operands come first, in alphabetical order
4655737b690SBen Gras	 * inside a single set of braces, upper case before lower case
4665737b690SBen Gras	 * (AaBbCc...).  Next are options with operands, in the same
4675737b690SBen Gras	 * order, each in braces.  Then required arguments in the
4685737b690SBen Gras	 * order they are specified, followed by optional arguments in
4695737b690SBen Gras	 * the order they are specified.  A bar (`|') separates
4705737b690SBen Gras	 * either/or options/arguments, and multiple options/arguments
4715737b690SBen Gras	 * which are specified together are placed in a single set of
4725737b690SBen Gras	 * braces.
4735737b690SBen Gras	 *
4745737b690SBen Gras	 * Use getprogname() instead of hardcoding the program name.
4755737b690SBen Gras	 *
4765737b690SBen Gras	 * "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
4775737b690SBen Gras	 * "usage: f [-a | -b] [-c [-de] [-n number]]\n"
4785737b690SBen Gras	 */
4795737b690SBen Gras	(void)fprintf(stderr, "usage: %s [-ab]\n", getprogname());
4805737b690SBen Gras	exit(EXIT_FAILURE);
4815737b690SBen Gras}
482