]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/man-pages.7
Fix description of return value.
[thirdparty/man-pages.git] / man7 / man-pages.7
CommitLineData
ba83bc0d
MK
1.\" (C) Copyright 1992-1999 Rickard E. Faith and David A. Wheeler
2.\" (faith@cs.unc.edu and dwheeler@ida.org)
3.\" and (C) Copyright 2007 Michael Kerrisk <mtk-manpages@gmx.net>
4.\"
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
988db661
MK
24.\"
25.\" 2007-05-30 created by mtk, using text from old man.7 plus
04bc8827 26.\" rewrites and additional text.
ba83bc0d 27.\"
ba83bc0d
MK
28.TH MAN-PAGES 7 2007-05-30 "Linux" "Linux Programmer's Manual"
29.SH NAME
30man-pages \- conventions for writing Linux man pages
31.SH SYNOPSIS
32.B man
33.RI [ section ]
34.I title
35.SH DESCRIPTION
36This page describes the conventions that should be employed
37when writing man pages for the Linux \fIman-pages\fP project,
38which comprises Sections 2, 3, 4, 5, and 7 of the Linux manual pages.
39The conventions described on this page may also be useful
40for authors writing man pages for other projects.
41.SS Sections of the Manual Pages
42.PP
43The manual Sections are traditionally defined as follows:
ba83bc0d
MK
44.TP 10
45.B 1 Commands (Programs)
46Those commands that can be executed by the user from within
47a shell.
48.TP
49.B 2 System calls
50Those functions which must be performed by the kernel.
51.TP
52.B 3 Library calls
53Most of the
54.I libc
55functions.
56.TP
57.B 4 Special files (devices)
58Files found in
59.IR /dev .
60.TP
61.B 5 File formats and conventions
62The format for
63.I /etc/passwd
64and other human-readable files.
65.TP
66.B 6 Games
67.TP
68.B 7 Conventions and miscellaneous
69Overviews of various topics, conventions and protocols,
70character set standards, and miscellaneous other things.
71.TP
72.B 8 System management commands
73Commands like
74.BR mount (8),
75many of which only root can execute.
76.\" .TP
77.\" .B 9 Kernel routines
78.\" This is an obsolete manual section.
79.\" Once it was thought a good idea to document the Linux kernel here,
80.\" but in fact very little has been documented, and the documentation
81.\" that exists is outdated already.
82.\" There are better sources of
83.\" information for kernel developers.
ba83bc0d
MK
84.SS Macro package
85New manual pages should be marked up using the
86.B groff tmac.an
87package described in
88.BR man (7).
988db661 89This choice is mainly for consistency: the vast majority of
ba83bc0d
MK
90existing Linux manual pages are marked up using these macros.
91.SS Conventions for source file layout
988db661 92Please limit source code line length to no more than about 75 characters
ba83bc0d
MK
93wherever possible.
94This helps avoid line-wrapping in some mail clients when patches are
95submitted inline.
96
97New sentences should be started on new lines.
98This makes it easier to see the effect of patches,
99which often operate at the level of individual sentences.
100.SS Title line
101The first command in a man page should be a \fBTH\fP command:
102.RS
103.sp
104.B \&.TH
105.IR "title section date source manual"
106.sp
107.RE
108where:
109.RS
110.TP 10
111.I title
112The title of the man page, written in all caps (e.g.,
113.IR MAN-PAGES ).
114.TP
115.I section
116The section number in which the man page should be placed (e.g.,
117.IR 7 ).
118.TP
119.I date
120The date of the last revision\(emremember to change this every time a
04bc8827
MK
121change is made to the man page,
122since this is the most general way of doing version control.
ba83bc0d
MK
123Dates should be written in the form YYYY-MM-DD.
124.TP
125.I source
126The source of the command, function, or system call.
127.sp
128For those few \fIman-pages\fP pages in Sections 1 and 8,
129probably you just want to write
130.IR GNU .
131.sp
132For system calls, just write
133.IR "Linux" .
134(An earlier practice was to write the version number
135of the kernel from which the manual page was being written/checked.
136However, this was never done consistently, and so was
137probably worse than including no version number.
138Henceforth, avoid including a version number.)
139.sp
988db661 140For library calls that are part of glibc or one of the
ba83bc0d
MK
141other common GNU libraries, just use
142.IR "GNU C Library" ", " GNU ,
143or an empty string.
144.sp
145For Section 4 pages, use
146.IR "Linux" .
147.sp
148In cases of doubt, just write
149.IR Linux ", or " GNU .
150.TP
151.I manual
988db661 152The title of the manual (e.g., for Section 2 and 3 pages in
ba83bc0d
MK
153the \fIman-pages\fP package, use
154.IR "Linux Programmer's Manual" ).
155.RE
156.SS Sections within a manual page
157The list below shows conventional or suggested sections.
988db661 158Most manual pages should include at least the
ba83bc0d
MK
159.B highlighted
160sections.
04bc8827 161Arrange a new manual page so that sections
ba83bc0d
MK
162are placed in the order shown in the list.
163.in +0.5i
164.nf
165
166\fBNAME\fP
167\fBSYNOPSIS\fP
168\fBDESCRIPTION\fP
169OPTIONS [Normally only in Sections 1, 8]
170EXIT STATUS [Normally only in Sections 1, 8]
171RETURN VALUE [Normally only in Sections 2, 3]
172.\" May 07: Few current man pages have an ERROR HANDLING section,,,
173.\" ERROR HANDLING,
174ERRORS [Typically only in Sections 2, 3]
175.\" May 07: Almost no current man pages have a USAGE section,,,
988db661
MK
176.\" USAGE,
177..\" DIAGNOSTICS,
ba83bc0d
MK
178.\" May 07: Almost no current man pages have a SECURITY section,,,
179.\" SECURITY,
180ENVIRONMENT
181FILES
182VERSIONS [Normally only in Sections 2, 3]
183CONFORMING TO
184NOTES
185BUGS
186EXAMPLE
dcbc136a
MK
187.\" AUTHORS sections are discouraged
188.\" AUTHORS [Discouraged]
ba83bc0d
MK
189\fBSEE ALSO\fP
190
191.fi
192.in
193.IR "Where a traditional heading would apply" ", " "please use it" ;
194this kind of consistency can make the information easier to understand.
988db661 195If you must, you can create your own
ba83bc0d
MK
196headings if they make things easier to understand (this can
197be especially useful for pages in Sections 4 and 5).
198However, before doing this, consider whether you could use the
199traditional headings, with some subsections (\fI.SS\fP) within
200those sections.
201
988db661 202The following list elaborates on the contents of each of
ba83bc0d
MK
203the above sections.
204.TP 14
205.B NAME
206The name of this manual page.
988db661 207See
ba83bc0d
MK
208.BR man (7)
209for important details of the line(s) that should follow the
210\fB.SH NAME\fI command.
211.TP
212.B SYNOPSIS
213briefly describes the command or function's interface.
214For commands, this shows the syntax of the command and its arguments
215(including options);
04bc8827
MK
216boldface is used for as-is text and italics are used to
217indicate replaceable arguments.
ba83bc0d
MK
218Brackets ([]) surround optional arguments, vertical bars (|)
219separate choices, and ellipses (\&...) can be repeated.
220For functions, it shows any required data declarations or
221.B #include
222directives, followed by the function declaration.
223.TP
224.B DESCRIPTION
225gives an explanation of what the program, function, or format does.
226Discuss how it interacts with files and standard input, and what it
227produces on standard output or standard error.
228Omit internals and implementation details unless they're critical for
229understanding the interface.
230Describe the usual case;
231for information on command-line options of a program use the
232.B OPTIONS
233section.
234.\" If there is some kind of input grammar or complex set of subcommands,
235.\" consider describing them in a separate
236.\" .B USAGE
237.\" section (and just place an overview in the
238.\" .B DESCRIPTION
239.\" section).
240.TP
241.B OPTIONS
988db661 242describes the command-line options accepted by a
ba83bc0d
MK
243program and how they change its behavior.
244This section should only appear for Section 1 and 8 manual pages.
245.\" .TP
246.\" .B USAGE
247.\" describes the grammar of any sublanguage this implements.
ba83bc0d
MK
248.TP
249.B EXIT STATUS
250lists the possible exit status values of a program and
251the conditions that cause these values to be returned.
252This section should only appear for Section 1 and 8 manual pages.
253.TP
254.B RETURN VALUE
255For Section 2 and 3 pages, this section gives a
256list of the values the library routine will return to the caller
257and the conditions that cause these values to be returned.
258.TP
259.B ERRORS
260For Section 2 and 3 manual pages, this is a list of the
261values that may be placed in
262.I errno
263in the event of an error, along with information about the cause
264of the errors.
09f49246 265.IR "The error list should be in alphabetical order" .
ba83bc0d
MK
266.TP
267.B ENVIRONMENT
268lists all environment variables that affect the program or function
269and how they affect it.
270.TP
271.B FILES
272lists the files the program or function uses, such as
273configuration files, startup files,
274and files the program directly operates on.
275Give the full pathname of these files, and use the installation
276process to modify the directory part to match user preferences.
277For many programs, the default installation location is in
278.IR /usr/local ,
279so your base manual page should use
280.I /usr/local
281as the base.
282.\" May 07: Almost no current man pages have a DIAGNOSTICS section;
283.\" "RETURN VALUE" or "EXIT STATUS" is preferred.
284.\" .TP
285.\" .B DIAGNOSTICS
286.\" gives an overview of the most common error messages and how to
287.\" cope with them.
288.\" You don't need to explain system error messages
289.\" or fatal signals that can appear during execution of any program
290.\" unless they're special in some way to the program.
291.\"
292.\" May 07: Almost no current man pages have a SECURITY section.
293.\".TP
294.\".B SECURITY
295.\"discusses security issues and implications.
296.\"Warn about configurations or environments that should be avoided,
297.\"commands that may have security implications, and so on, especially
298.\"if they aren't obvious.
299.\"Discussing security in a separate section isn't necessary;
300.\"if it's easier to understand, place security information in the
301.\"other sections (such as the
302.\" .B DESCRIPTION
303.\" or
304.\" .B USAGE
305.\" section).
306.\" However, please include security information somewhere!
307.TP
308.B VERSIONS
309A brief summary of the Linux kernel or glibc versions where a
310system call or library function appeared,
311or changed significantly in its operation.
312.TP
313.B CONFORMING TO
04bc8827
MK
314describes any standards or conventions that relate to the function
315or command described by the manual page.
316For a page in Section 2 or 3,
317this section should note the POSIX.1
318version(s) that the call conforms to,
319and also whether the call is specified in C99.
320(Don't worry too much about other standards like SUS, SUSv2, and XPG,
321or the SVr4 and 4.xBSD implementation standards,
322unless the call was specified in those standards,
323but isn't in the current version of POSIX.1.)
324(See
325.BR standards (7).)
326
988db661
MK
327If the call is not governed by any standards but commonly
328exists on other systems, note them.
ba83bc0d 329If the call is Linux specific, note this.
ba83bc0d
MK
330.TP
331.B NOTES
332provides miscellaneous notes.
f8843c2e 333For Section 2 and 3 man pages you may find it useful to include
ba83bc0d
MK
334subsections (\fBSS\fP) named \fILinux Notes\fP and \fIGlibc Notes\fP.
335.TP
336.B BUGS
337lists limitations, known defects or inconveniences,
338and other questionable activities.
339.TP
340.B EXAMPLE
341provides one or more examples describing how this function, file or
342command is used.
04bc8827
MK
343For details on writing example programs,
344see \fIExample Programs\fP below.
ba83bc0d 345.TP
dcbc136a 346.B AUTHORS
f8843c2e 347lists authors of the documentation or program.
dcbc136a 348\fBUse of an AUTHORS section is strongly discouraged\fP.
ba83bc0d
MK
349Generally, it is better not to clutter every page with a list
350of (over time potentially numerous) authors;
351if you write or significantly amend a page,
352add a copyright notice as a comment in the source file.
f8843c2e
MK
353If you are the author a device driver and what to include
354an address for reporting bugs, place this under the BUGS section.
ba83bc0d
MK
355.TP
356.B SEE ALSO
988db661 357lists related man pages, ordered by section number and
ba83bc0d
MK
358alphabetically by name, possibly followed by
359other related pages or documents.
360.SS Font conventions
361.PP
362For functions, the arguments are always specified using italics,
363.IR "even in the SYNOPSIS section" ,
364where the rest of the function is specified in bold:
365.PP
366.RS
367.BI " int myfunction(int " argc ", char **" argv );
368.RE
369.PP
370Filenames are always in italics (e.g.,
371.IR "/usr/include/stdio.h" ),
372except in the SYNOPSIS section, where included files are in bold (e.g.,
373.BR "#include <stdio.h>" ).
374.PP
375Special macros, which are usually in upper case, are in bold (e.g.,
376.BR MAXINT ).
377Exception: don't boldface NULL.
378.PP
379When enumerating a list of error codes, the codes are in bold (this list
380usually uses the
381.B \&.TP
382macro).
383.PP
384Any reference to the subject of the current manual page
f8843c2e
MK
385should be written with the name in bold.
386If the subject is a function (i.e., this is a Section 2 or 3 page),
988db661 387then the name should be followed by a pair of parentheses
f8843c2e
MK
388in Roman (normal) font.
389For example, in the
390.BR fcntl (2)
391man page, references to the subject of the page would be written as:
392.BR fcntl ().
ba83bc0d
MK
393The preferred way to write this in the source file is:
394.nf
395
f8843c2e 396 .BR fcntl ()
ba83bc0d
MK
397
398.fi
399(Using this format, rather than the use of "\\fB...\\fP()"
400makes it easier to write tools that parse man page source files.)
401.PP
402Any reference to another man page
403should be written with the name in bold,
404\fIalways\fP followed by the section number,
405formatted in Roman (normal) font, without any
406separating spaces (e.g.,
407.BR intro (2)).
408The preferred way to write this in the source file is:
409.nf
410
411 .BR intro (2)
412
413.fi
414(Including the section number in cross references lets tools like
415.BR man2html (1)
416create properly hyperlinked pages.)
55f7ee2a 417.SS Spelling
9daed026 418Starting with release 2.59,
55f7ee2a
MK
419.I man-pages
420follows American spelling conventions;
421please write all new pages and patches according to these conventions.
ba83bc0d 422.SS Example Programs
988db661 423Manual pages can include example programs demonstrating how to
ba83bc0d
MK
424use a system call or library function.
425However, note the following:
426.TP 3
427*
428Example programs should be written in C.
429.TP
430*
431An example program is only necessary and useful if it demonstrates
432something beyond what can easily be provided in a textual
433description of the interface.
434An example program that does nothing
435other than call an interface usually serves little purpose.
436.TP
437*
438Example programs should be fairly short (preferably < 100 lines;
439ideally < 50 lines).
440.TP
441*
442Example programs should do error checking after system calls and
443library function calls.
444.TP
445*
446Example programs should be complete, and compile without
447warnings when compiled with \fIcc -Wall\fP.
448.TP
449*
450Where possible and appropriate, example programs should allow
d9bfdb9c 451experimentation, by varying their behavior based on inputs
ba83bc0d
MK
452(ideally from command-line arguments, or alternatively, via
453input read by the program).
454.TP
455*
456Example programs should be laid out according to Kernighan and
5998eb25 457Ritchie style, with 4-space indents.
ba83bc0d 458(Avoid the use of TAB characters in source code!)
ba83bc0d
MK
459.PP
460For some examples of what example programs should look like, see
461.BR wait (2)
462and
463.BR pipe (2).
464.SH EXAMPLE
465For canonical examples of how man pages in the
f0a15fe0 466.IR man-pages
ba83bc0d
MK
467package should look, see
468.BR pipe (2)
469and
470.BR fcntl (2).
471.SH SEE ALSO
472.BR man (1),
473.BR man2html (1),
474.BR man (7),
475.BR mdoc (7)