I now introduce a case study of a real-world function library manual, in particular the manual for the getc, fgetc, getw, and getchar functions from OpenBSD. The
original file may be viewed on-line at src/lib/libc/stdio/getc.3,
file version 1.12. This is not the manual for the full function library, but only a handful of similar functions.
.\" $OpenBSD: getc.3,v 1.12 2007/05/31 19:19:31 jmc Exp $
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek and the American National Standards Committee X3,
.\" on Information Processing Systems.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
This is the standard comment header to manual files in OpenBSD. The $OpenBSD$ line
is automatically updated by the revision control system, cvs, whenever an
update to the file is committed. The line following is the copyright message, and following that is the text form of
the BSD license.
.Dd $Mdocdate: May 31 2007 $
.Dt GETC 3
This classifies our manual in category 3 as a function or function library. The title of the
manual, GETC, is chosen as the most general of those functions listed below in the NAME section.
.Nm fgetc ,
.Nm getc ,
.Nm getchar ,
.Nd get next character or word from input stream
Lists (alphabetically) all the functions that will be documented, and some general notes about their collective
function. We next jump down into the SYNOPSIS; since this set of functions is part of the C Standard Library, it needs no special linking information.
.Fd #include <stdio.h>
.Fn fgetc "FILE *stream"
.Fn getc "FILE *stream"
.Fn getchar "void"
.Fn getw "FILE *stream"
This documents the calling syntax of all functions. Note that the Fd
macro is used instead of the In macro. This invocation is
historically relevant, but new manuals should always use In.
Next, each function and its arguments is explained as a free-flowing paragraph. This was probably chosen instead of
using a list item for each argument (with Bl) due to the small number
function obtains the next input character (if present) from the stream
pointed at by
.Fa stream ,
or the next character pushed back on the stream via
.Xr ungetc 3 .
function acts essentially identically to
.Fn fgetc ,
but is a macro that expands in-line.
function is equivalent to
with the argument
.Em stdin .
function obtains the next
from the stream pointed at by
.Fa stream .
The usage of the Em macro is not correct: the Va or Dv macro
would have been more appropriate. The same applies to the Li. The
mdoc language is semantic, so using presentation macros such as Li and Em is
.Sh RETURN VALUES
If successful, these routines return the next requested object from the
.Fa stream .
If the stream is at end-of-file or a read error occurs, the routines return
.Dv EOF .
.Xr feof 3
.Xr ferror 3
must be used to distinguish between end-of-file and error.
If an error occurs, the global variable
is set to indicate the error.
The end-of-file condition is remembered, even on a terminal, and all
subsequent attempts to read will return
until the condition is cleared with
.Xr clearerr 3 .
.Sh SEE ALSO
.Xr ferror 3 ,
.Xr fopen 3 ,
.Xr fread 3 ,
.Xr putc 3 ,
.Xr ungetc 3
All possible return values are correctly documented in the RETURN VALUES section and relevant
functions cross-linked in the SEE ALSO section. Note that the cross-linked manuals are also
.Fn fgetc ,
.Fn getc ,
functions conform to
.St -ansiC .
Noting standards conformance is extremely important: it allows programmers and administrators to depend on your
component in a cross-platform fashion. These functions are part of the C
is a valid integer value,
.Xr feof 3
.Xr ferror 3
must be used to check for failure after calling
.Fn getw .
Since the size and byte order of an
may vary from one machine to another,
is not recommended for portable applications.
The BUGS section should be used very carefully — bugs preferably should be fixed. In
this section, design bugs have been documented. Whether the CAVEATS section would be more
appropriate is up to the manual author.
We found several inconsistent uses of mdoc in this manual. In general, if you find unusual or
erroneous macros or styles in UNIX manuals, notify the authors! A bug in a manual is just as important as a bug in the
Last edited by $Author: kristaps $ on $Date: 2011/11/04 01:06:28 $. Copyright © 2011, Kristaps Dzonsons. CC BY-SA.