diff options
| -rw-r--r-- | man3/strverscmp.3 | 42 |
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), |
