From patchwork Sun Oct 26 07:21:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rical Jasan X-Patchwork-Id: 3378 Received: (qmail 12911 invoked by alias); 26 Oct 2014 07:19:48 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12892 invoked by uid 89); 26 Oct 2014 07:19:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail.pacific.net Message-ID: <544CA0EB.8030205@pacific.net> Date: Sun, 26 Oct 2014 00:21:15 -0700 From: ricaljasan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: libc-alpha@sourceware.org Subject: [PATCH v2] Complete example in error message documentation. X-Null-Tag: d282531f78a52e33b23ee3b61219a5ee Previously unquoted #include at beginning of line caused it to disappear from commit message. Diff unchanged. ---- The manual gives "an example showing how to handle failure to open a file correctly." The example function, open_sesame, uses the newly-introduced strerror function and errno and program_invocation_short_name variables. It fails to specify GNU extensions, however, so attempts to use it in the following way: int main (void) {open_sesame ("badname");} fail during compilation with "error: ‘program_invocation_short_name’ undeclared", indicating the example is incomplete. The presence of "#include"s suggest everything neccesary for the function to work should be present. For completeness, the example is lacking the following line: #define _GNU_SOURCE as the declarations of program_invocation_*name in errno.h are wrapped in an "#ifdef __USE_GNU" conditional. The documentation of the variables is also expanded, adding that their definition lies in errno.h and noting specifically they are GNU extensions. manual/errno.texi: Complete example function and expand documentation of program_invocation*_name variables. 2014-10-25 Rical Jasan * manual/errno.texi (Error Messages): Complete example function by adding missing #define. (program_invocation_name): Add statement indicating GNU extension and reference which header file declares the variable. (program_invocation_short_name): Likewise. diff --git a/manual/errno.texi b/manual/errno.texi index eb9617e..8d575a7 100644 --- a/manual/errno.texi +++ b/manual/errno.texi @@ -1380,6 +1380,8 @@ This variable's value is the name that was used to invoke the program running in the current process. It is the same as @code{argv[0]}. Note that this is not necessarily a useful file name; often it contains no directory names. @xref{Program Arguments}. + +This variable is a GNU extension and is declared in @file{errno.h}. @end deftypevar @comment errno.h @@ -1389,17 +1391,19 @@ This variable's value is the name that was used to invoke the program running in the current process, with directory names removed. (That is to say, it is the same as @code{program_invocation_name} minus everything up to the last slash, if any.) + +This variable is a GNU extension and is declared in @file{errno.h}. @end deftypevar The library initialization code sets up both of these variables before calling @code{main}. -@strong{Portability Note:} These two variables are GNU extensions. If -you want your program to work with non-GNU libraries, you must save the -value of @code{argv[0]} in @code{main}, and then strip off the directory -names yourself. We added these extensions to make it possible to write -self-contained error-reporting subroutines that require no explicit -cooperation from @code{main}. +@strong{Portability Note:} If you want your program to work with +non-GNU libraries, you must save the value of @code{argv[0]} in +@code{main}, and then strip off the directory names yourself. We +added these extensions to make it possible to write self-contained +error-reporting subroutines that require no explicit cooperation from +@code{main}. Here is an example showing how to correctly handle failure to open a file. The function @code{open_sesame} tries to open the named file @@ -1413,6 +1417,8 @@ save it in a local variable instead, because those other library functions might overwrite @code{errno} in the meantime. @smallexample +#define _GNU_SOURCE + #include #include #include