Use shortcut links to the POSIX specification.
[gnulib.git] / doc / standards.texi
index 2facefa..c9c5a15 100644 (file)
@@ -3,7 +3,7 @@
 @setfilename standards.info
 @settitle GNU Coding Standards
 @c This date is automagically updated when you save this file:
-@set lastupdate February 20, 2004
+@set lastupdate June 8, 2005
 @c %**end of header
 
 @dircategory GNU organization
@@ -33,7 +33,7 @@
 The GNU coding standards, last updated @value{lastupdate}.
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.1
@@ -94,15 +94,9 @@ This release of the GNU Coding Standards was last updated
 @cindex downloading this manual
 If you did not obtain this file directly from the GNU project and
 recently, please check for a newer version.  You can get the GNU
-Coding Standards from the GNU World Wide Web server host in several
-different formats: @uref{http://www.gnu.org/prep/standards.text},
-@uref{http://www.gnu.org/prep/standards.info}, and
-@uref{http://www.gnu.org/prep/standards.dvi}, as well as the
-Texinfo ``source'' which is divided in two files:
-@uref{http://www.gnu.org/prep/standards.texi} and
-@uref{http://www.gnu.org/prep/make-stds.texi}.  The GNU Coding
-Standards are also available in HTML format starting at
-@uref{http://www.gnu.org/prep/standards_toc.html}.
+Coding Standards from the GNU web server in many
+different formats, including the Texinfo source, PDF, HTML, DVI, plain
+text, and more, at: @uref{http://www.gnu.org/prep/standards/}.
 
 Corrections or suggestions for this document should be sent to
 @email{bug-standards@@gnu.org}.  If you make a suggestion, please include a
@@ -130,7 +124,7 @@ world!}.  @uref{http://www.gnu.org/software/hello/hello.html}.
 @chapter Keeping Free Software Free
 @cindex legal aspects
 
-This @value{CHAPTER} discusses how you can make sure that GNU software
+This chapter discusses how you can make sure that GNU software
 avoids legal difficulties, and other related issues.
 
 @menu
@@ -208,7 +202,7 @@ You might have to take that code out again!
 You don't need papers for changes of a few lines here or there, since
 they are not significant for copyright purposes.  Also, you don't need
 papers if all you get from the suggestion is some ideas, not actual code
-which you use.  For example, if someone send you one implementation, but
+which you use.  For example, if someone sent you one implementation, but
 you write a different implementation of the same idea, you don't need to
 get papers.
 
@@ -218,7 +212,8 @@ result.
 
 We have more detailed advice for maintainers of programs; if you have
 reached the stage of actually maintaining a program for GNU (whether
-released or not), please ask us for a copy.
+released or not), please ask us for a copy.  It is also available
+online for your perusal: @uref{http://www.gnu.org/prep/maintain/}.
 
 @node Trademarks
 @section Trademarks
@@ -244,9 +239,9 @@ C'' as a label for the compiler rather than for the language.
 
 Please don't use ``win'' as an abbreviation for Microsoft Windows in
 GNU software or documentation.  In hacker terminology, calling
-something a "win" is a form of praise.  If you wish to praise
+something a ``win'' is a form of praise.  If you wish to praise
 Microsoft Windows when speaking on your own, by all means do so, but
-not in GNU software.  Usually we write the word ``windows'' in full,
+not in GNU software.  Usually we write the name ``Windows'' in full,
 but when brevity is very important (as in file names and sometimes
 symbol names), we abbreviate it to ``w''.  For instance, the files and
 functions in Emacs that deal with Windows start with @samp{w32}.
@@ -255,7 +250,7 @@ functions in Emacs that deal with Windows start with @samp{w32}.
 @chapter General Program Design
 @cindex program design
 
-This @value{CHAPTER} discusses some of the issues you should take into
+This chapter discusses some of the issues you should take into
 account when designing your program.
 
 @c                         Standard or ANSI C
@@ -269,7 +264,7 @@ account when designing your program.
 @c A major revision of the C Standard appeared in 1999.
 
 @menu
-* Source Language::             Which languges to use.
+* Source Language::             Which languages to use.
 * Compatibility::               Compatibility with other implementations
 * Using Extensions::            Using non-standard features
 * Standard C::                  Using Standard C features
@@ -278,7 +273,7 @@ account when designing your program.
 
 @node Source Language
 @section Which Languages to Use
-@cindex programming languges
+@cindex programming languages
 
 When you want to use a language that gets compiled and runs at high
 speed, the best language to use is C.  Using another language is like
@@ -518,7 +513,7 @@ an easy workaround.  Simply introduce another macro
 @node Program Behavior
 @chapter Program Behavior for All Programs
 
-This @value{CHAPTER} describes conventions for writing robust
+This chapter describes conventions for writing robust
 software.  It also describes general standards for error messages, the
 command line interface, and how libraries should behave.
 
@@ -855,7 +850,7 @@ All programs should support two standard options: @samp{--version}
 and @samp{--help}.  CGI programs should accept these as command-line
 options, and also if given as the @env{PATH_INFO}; for instance,
 visiting @url{http://example.org/p.cgi/--help} in a browser should
-output the same information as inokving @samp{p.cgi --help} from the
+output the same information as invoking @samp{p.cgi --help} from the
 command line.
 
 @table @code
@@ -1497,9 +1492,7 @@ Used in @code{gawk}.
 Used in @code{su}.
 
 @item machine
-No listing of which programs already use this;
-someone should check to
-see if any actually do, and tell @email{gnu@@gnu.org}.
+Used in @code{uname}.
 
 @item macro-name
 @samp{-M} in @code{ptx}.
@@ -2137,7 +2130,7 @@ directory.
 @node Writing C
 @chapter Making The Best Use of C
 
-This @value{CHAPTER} provides advice on how best to use the C language
+This chapter provides advice on how best to use the C language
 when writing GNU software.
 
 @menu
@@ -2167,13 +2160,12 @@ These tools will not work on code not formatted that way.
 It is also important for function definitions to start the name of the
 function in column zero.  This helps people to search for function
 definitions, and may also help certain tools recognize them.  Thus,
-the proper format is this:
+using Standard C syntax, the format is this:
 
 @example
 static char *
-concat (s1, s2)        /* Name starts in column zero here */
-     char *s1, *s2;
-@{                     /* Open brace in column zero here */
+concat (char *s1, char *s2)
+@{
   @dots{}
 @}
 @end example
@@ -2184,8 +2176,9 @@ this:
 
 @example
 static char *
-concat (char *s1, char *s2)
-@{
+concat (s1, s2)        /* Name starts in column zero here */
+     char *s1, *s2;
+@{                     /* Open brace in column zero here */
   @dots{}
 @}
 @end example
@@ -2623,11 +2616,11 @@ Avoid using the format of semi-internal data bases (e.g., directories)
 when there is a higher-level alternative (@code{readdir}).
 
 @cindex non-@sc{posix} systems, and portability
-As for systems that are not like Unix, such as MSDOS, Windows, the
-Macintosh, VMS, and MVS, supporting them is often a lot of work.  When
-that is the case, it is better to spend your time adding features that
-will be useful on GNU and GNU/Linux, rather than on supporting other
-incompatible systems.
+As for systems that are not like Unix, such as MSDOS, Windows, VMS,
+MVS, and older Macintosh systems, supporting them is often a lot of
+work.  When that is the case, it is better to spend your time adding
+features that will be useful on GNU and GNU/Linux, rather than on
+supporting other incompatible systems.
 
 If you do support Windows, please do not abbreviate it as ``win''.  In
 hacker terminology, calling something a ``win'' is a form of praise.
@@ -2692,37 +2685,50 @@ while ((c = getchar()) != EOF)
   write(file_descriptor, &c, 1);
 @end example
 
-When calling functions, you need not worry about the difference between
-pointers of various types, or between pointers and integers.  On most
-machines, there's no difference anyway.  As for the few machines where
-there is a difference, all of them support Standard C prototypes, so you can
-use prototypes (perhaps conditionalized to be active only in Standard C)
-to make the code work on those systems.
+It used to be ok to not worry about the difference between pointers
+and integers when passing arguments to functions.  However, on most
+modern 64-bit machines pointers are wider than @code{int}.
+Conversely, integer types like @code{long long int} and @code{off_t}
+are wider than pointers on most modern 32-bit machines.  Hence it's
+often better nowadays to use prototypes to define functions whose
+argument types are not trivial.
 
-In certain cases, it is ok to pass integer and pointer arguments
-indiscriminately to the same function, and use no prototype on any
-system.  For example, many GNU programs have error-reporting functions
-that pass their arguments along to @code{printf} and friends:
+In particular, if functions accept varying argument counts or types
+they should be declared using prototypes containing @samp{...} and
+defined using @file{stdarg.h}.  For an example of this, please see the
+@uref{http://www.gnu.org/software/gnulib/, Gnulib} error module, which
+declares and defines the following function:
 
 @example
-error (s, a1, a2, a3)
-     char *s;
-     char *a1, *a2, *a3;
-@{
-  fprintf (stderr, "error: ");
-  fprintf (stderr, s, a1, a2, a3);
-@}
+/* Print a message with `fprintf (stderr, FORMAT, ...)';
+   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+   If STATUS is nonzero, terminate the program with `exit (STATUS)'.  */
+
+void error (int status, int errnum, const char *format, ...);
 @end example
 
-@noindent
-In practice, this works on all machines, since a pointer is generally
-the widest possible kind of argument; it is much simpler than any
-``correct'' alternative.  Be sure @emph{not} to use a prototype for such
-functions.
+A simple way to use the Gnulib error module is to obtain the two
+source files @file{error.c} and @file{error.h} from the Gnulib library
+source code repository at
+@uref{http://savannah.gnu.org/cgi-bin/viewcvs/gnulib/gnulib/lib/}.
+Here's a sample use:
+
+@example
+#include "error.h"
+#include <errno.h>
+#include <stdio.h>
+
+char *program_name = "myprogram";
 
-If you have decided to use Standard C, then you can instead define
-@code{error} using @file{stdarg.h}, and pass the arguments along to
-@code{vfprintf}.
+FILE *
+xfopen (char const *name)
+@{
+  FILE *fp = fopen (name, "r");
+  if (! fp)
+    error (1, errno, "cannot read %s", name);
+  return fp;
+@}
+@end example
 
 @cindex casting pointers to integers
 Avoid casting pointers to integers if you can.  Such casts greatly
@@ -3081,9 +3087,9 @@ functions, variables, options, and important concepts that are part of
 the program.  One combined Index should do for a short manual, but
 sometimes for a complex package it is better to use multiple indices.
 The Texinfo manual includes advice on preparing good index entries, see
-@ref{Index Entries, , Making Index Entries, texinfo, The GNU Texinfo
-Manual}, and see @ref{Indexing Commands, , Defining the Entries of an
-Index, texinfo, The GNU Texinfo manual}.
+@ref{Index Entries, , Making Index Entries, texinfo, GNU Texinfo}, and
+see @ref{Indexing Commands, , Defining the Entries of an
+Index, texinfo, GNU Texinfo}.
 
 Don't use Unix man pages as a model for how to write GNU documentation;
 most of them are terse, badly structured, and give inadequate
@@ -3143,7 +3149,7 @@ Each program documented in the manual should have a node named
 @samp{@var{program} Invocation} or @samp{Invoking @var{program}}.  This
 node (together with its subnodes, if any) should describe the program's
 command line arguments and how to run it (the sort of information people
-would look in a man page for).  Start with an @samp{@@example}
+would look for in a man page).  Start with an @samp{@@example}
 containing a template for all the options and arguments that the program
 uses.
 
@@ -3469,6 +3475,25 @@ page explaining that you don't maintain it and that the Texinfo manual
 is more authoritative.  The note should say how to access the Texinfo
 documentation.
 
+Be sure that man pages include a copyright statement and free
+license.  The simple all-permissive license is appropriate for simple
+man pages:
+
+@example
+Copying and distribution of this file, with or without modification,
+are permitted in any medium without royalty provided the copyright
+notice and this notice are preserved.
+@end example
+
+For long man pages, with enough explanation and documentation that
+they can be considered true manuals, use the GFDL (@pxref{License for
+Manuals}).
+
+Finally, the GNU help2man program
+(@uref{http://www.gnu.org/software/help2man/}) is one way to automate
+generation of a man page, in this case from @option{--help} output.
+This is sufficient in many cases.
+
 @node Reading other Manuals
 @section Reading other Manuals
 
@@ -3770,9 +3795,9 @@ advertise them to new potential customers.  Proprietary software is a
 social and ethical problem, and the point of GNU is to solve that
 problem.
 
-The GNU definition of free software is found in
-@url{http://www.gnu.org/philosophy/free-sw.html}, with a list of
-important licenses and whether they qualify as free in
+The GNU definition of free software is found on the GNU web site at
+@url{http://www.gnu.org/philosophy/free-sw.html}.  A list of
+important licenses and whether they qualify as free is in
 @url{http://www.gnu.org/licenses/license-list.html}.  The terms
 ``free'' and ``non-free'', used in this document, refer to that
 definition.  If it is not clear whether a license qualifies as free
@@ -3829,7 +3854,7 @@ scope of an operating system project.
 Referring to a web site that describes or recommends a non-free
 program is in effect promoting that software, so please do not make
 links (or mention by name) web sites that contain such material.  This
-policy is relevant particulary for the web pages for a GNU package.
+policy is relevant particularly for the web pages for a GNU package.
 
 Following links from nearly any web site can lead to non-free
 software; this is an inescapable aspect of the nature of the web, and