summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMateusz Piotrowski <0mp@FreeBSD.org>2020-12-17 12:41:47 +0000
committerMateusz Piotrowski <0mp@FreeBSD.org>2020-12-17 12:41:47 +0000
commit87394cdd011a57807fe044046476981f2b0142c2 (patch)
treef9f167597e0a7d6e4a629abe0d5d7592c8b16e91 /lib
parentebebc41e4cfe44b8e8fd881badf2fa2c4be65aa4 (diff)
downloadsrc-test2-87394cdd011a57807fe044046476981f2b0142c2.tar.gz
src-test2-87394cdd011a57807fe044046476981f2b0142c2.zip
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
Notes
Notes: svn path=/head/; revision=368714
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/string/strerror.327
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3
index 39f49d3007ac..3ea4145080cd 100644
--- a/lib/libc/string/strerror.3
+++ b/lib/libc/string/strerror.3
@@ -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 <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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 ,