From owner-svn-src-all@freebsd.org Thu Dec 17 12:41:48 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 381684B70A5; Thu, 17 Dec 2020 12:41:48 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CxWpN1561z3MnV; Thu, 17 Dec 2020 12:41:48 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 184CE18867; Thu, 17 Dec 2020 12:41:48 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BHCflEU008503; Thu, 17 Dec 2020 12:41:47 GMT (envelope-from 0mp@FreeBSD.org) Received: (from 0mp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BHCfl1r008452; Thu, 17 Dec 2020 12:41:47 GMT (envelope-from 0mp@FreeBSD.org) Message-Id: <202012171241.0BHCfl1r008452@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: 0mp set sender to 0mp@FreeBSD.org using -f From: Mateusz Piotrowski <0mp@FreeBSD.org> Date: Thu, 17 Dec 2020 12:41:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368714 - head/lib/libc/string X-SVN-Group: head X-SVN-Commit-Author: 0mp X-SVN-Commit-Paths: head/lib/libc/string X-SVN-Commit-Revision: 368714 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2020 12:41:48 -0000 Author: 0mp (doc,ports committer) Date: Thu Dec 17 12:41:47 2020 New Revision: 368714 URL: https://svnweb.freebsd.org/changeset/base/368714 Log: strerror.3: Add an example for perror() This is a nice and quick reference. Reviewed by: jilles, yuripv MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27623 Modified: head/lib/libc/string/strerror.3 Modified: head/lib/libc/string/strerror.3 ============================================================================== --- head/lib/libc/string/strerror.3 Thu Dec 17 03:42:54 2020 (r368713) +++ head/lib/libc/string/strerror.3 Thu Dec 17 12:41:47 2020 (r368714) @@ -32,7 +32,7 @@ .\" @(#)strerror.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd December 7, 2020 +.Dd December 17, 2020 .Dt STRERROR 3 .Os .Sh NAME @@ -170,6 +170,31 @@ The use of these variables is deprecated; or .Fn strerror_r should be used instead. +.Sh EXAMPLES +The following example shows how to use +.Fn perror +to report an error. +.Bd -literal -offset 2n +#include +#include +#include + +int +main(void) +{ + int fd; + + if ((fd = open("/nonexistent", O_RDONLY)) == -1) { + perror("open()"); + exit(1); + } + printf("File descriptor: %d\en", fd); + return (0); +} +.Ed +.Pp +When executed, the program will print an error message along the lines of +.Ql "open(): No such file or directory" . .Sh SEE ALSO .Xr intro 2 , .Xr err 3 ,