aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2016-08-30 09:22:27 +1200
committerMichael Kerrisk <mtk.manpages@gmail.com>2016-08-31 07:23:03 +1200
commit1f73bfaf6ed2e025480e639a2b55c4180eb8860f (patch)
tree63e7652ae2d78e536f2921e644befae4f238e98e
parentd695a48cdf9a29f5e9565cfe021abcc7bb774a74 (diff)
downloadman-pages-1f73bfaf6ed2e025480e639a2b55c4180eb8860f.tar.gz
strverscmp.3: Add an example program
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man3/strverscmp.342
1 files changed, 42 insertions, 0 deletions
diff --git a/man3/strverscmp.3 b/man3/strverscmp.3
index 501ee2e320..7864916fa4 100644
--- a/man3/strverscmp.3
+++ b/man3/strverscmp.3
@@ -1,4 +1,5 @@
.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
+.\" and Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
@@ -108,6 +109,47 @@ T} Thread safety MT-Safe
.TE
.SH CONFORMING TO
This function is a GNU extension.
+.SH EXAMPLE
+The program below can be used to demonstrate the behavior of
+.BR strverscmp ().
+It uses
+.BR strverscmp ()
+to compare the two strings given as its command-line arguments.
+An example of its use is the following:
+
+.in
+.in +4n
+.nf
+$ i\fB./a.out jan1 jan10\fP
+jan1 < jan10
+.fi
+.in
+.SS Program source
+\&
+.nf
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char *argv[])
+{
+ int res;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s <string1> <string2>\\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ res = strverscmp(argv[1], argv[2]);
+
+ printf("%s %s %s\\n", argv[1],
+ (res == \-1) ? "<" : (res == 0) ? "==" : ">", argv[2]);
+
+ exit(EXIT_SUCCESS);
+}
+.fi
.SH SEE ALSO
.BR rename (1),
.BR strcasecmp (3),