]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/rpmatch.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / rpmatch.3
CommitLineData
d2b53444
MK
1.\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
2.\"
7c576f45 3.\" %%%LICENSE_START(PERMISSIVE_MISC)
d2b53444
MK
4.\" Permission is hereby granted, free of charge, to any person obtaining
5.\" a copy of this software and associated documentation files (the
6.\" "Software"), to deal in the Software without restriction, including
7.\" without limitation the rights to use, copy, modify, merge, publish,
8.\" distribute, sublicense, and/or sell copies of the Software, and to
9.\" permit persons to whom the Software is furnished to do so, subject to
10.\" the following conditions:
11.\"
12.\" The above copyright notice and this permission notice shall be
13.\" included in all copies or substantial portions of the Software.
14.\"
15.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18.\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19.\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20.\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21.\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8ff7380d 22.\" %%%LICENSE_END
d2b53444
MK
23.\"
24.\" References:
25.\" glibc manual and source
6a39becb 26.\"
451d74fc 27.\" 2006-05-19, mtk, various edits and example program
6a39becb 28.\"
45186a5d 29.TH RPMATCH 3 2021-03-22 "Linux man-pages (unreleased)"
d2b53444
MK
30.SH NAME
31rpmatch \- determine if the answer to a question is affirmative or negative
3ba835c7
AC
32.SH LIBRARY
33Standard C library
8fc3b2cf 34.RI ( libc ", " \-lc )
d2b53444 35.SH SYNOPSIS
3b158837 36.nf
ddba45e1 37.B #include <stdlib.h>
f90f031e 38.PP
ddba45e1 39.BI "int rpmatch(const char *" response );
3b158837 40.fi
68e4db0a 41.PP
d39ad78f 42.RS -4
cc4615cc
MK
43Feature Test Macro Requirements for glibc (see
44.BR feature_test_macros (7)):
d39ad78f 45.RE
68e4db0a 46.PP
cc4615cc 47.BR rpmatch ():
9d281e06 48.nf
51c612fb
MK
49 Since glibc 2.19:
50 _DEFAULT_SOURCE
51 Glibc 2.19 and earlier:
52 _SVID_SOURCE
9d281e06 53.fi
d2b53444 54.SH DESCRIPTION
60a90ecd
MK
55.BR rpmatch ()
56handles a user response to yes or no questions, with
c13182ef 57support for internationalization.
847e0d88 58.PP
c6fa0841
MK
59.I response
60should be a null-terminated string containing a
60a90ecd
MK
61user-supplied response, perhaps obtained with
62.BR fgets (3)
63or
64.BR getline (3).
847e0d88 65.PP
6a39becb 66The user's language preference is taken into account per the
c6fa0841
MK
67environment variables
68.BR LANG ,
69.BR LC_MESSAGES ,
70and
71.BR LC_ALL ,
60a90ecd
MK
72if the program has called
73.BR setlocale (3)
74to effect their changes.
847e0d88 75.PP
c6fa0841 76Regardless of the locale, responses matching
9ca13180 77.B \(ha[Yy]
c6fa0841 78are always accepted as affirmative, and those matching
9ca13180 79.B \(ha[Nn]
c6fa0841 80are always accepted as negative.
47297adb 81.SH RETURN VALUE
c13182ef
MK
82After examining
83.IR response ,
60a90ecd
MK
84.BR rpmatch ()
85returns 0 for a recognized negative response ("no"), 1
d2b53444 86for a recognized positive response ("yes"), and \-1 when the value
c6fa0841
MK
87of
88.I response
89is unrecognized.
d2b53444
MK
90.SH ERRORS
91A return value of \-1 may indicate either an invalid input, or some
c13182ef 92other error.
c7094399 93It is incorrect to only test if the return value is nonzero.
847e0d88 94.PP
60a90ecd
MK
95.BR rpmatch ()
96can fail for any of the reasons that
97.BR regcomp (3)
98or
99.BR regexec (3)
100can fail; the cause of the error
c6fa0841
MK
101is not available from
102.I errno
103or anywhere else, but indicates a
d2b53444 104failure of the regex engine (but this case is indistinguishable from
c6fa0841
MK
105that of an unrecognized value of
106.IR response ).
c17fc186
ZL
107.SH ATTRIBUTES
108For an explanation of the terms used in this section, see
109.BR attributes (7).
c466875e
MK
110.ad l
111.nh
c17fc186
ZL
112.TS
113allbox;
c466875e 114lbx lb lb
c17fc186
ZL
115l l l.
116Interface Attribute Value
117T{
118.BR rpmatch ()
119T} Thread safety MT-Safe locale
120.TE
c466875e
MK
121.hy
122.ad
847e0d88 123.sp 1
3113c7f3 124.SH STANDARDS
60a90ecd 125.BR rpmatch ()
a1426ea9 126is not required by any standard,
127but available under the GNU C library, FreeBSD, and AIX.
d2b53444 128.SH BUGS
60a90ecd 129The
627472ed 130.BR YESEXPR " and " NOEXPR
131of some locales (including "C") only inspect the first character of the
c6fa0841 132.IR response .
627472ed 133This can mean that "yno" et al. resolve to
134.BR 1 .
135This is an unfortunate historical side-effect which should be fixed in time
136with proper localisation, and should not deter from
137.BR rpmatch ()
138being the proper way to distinguish between binary answers.
a14af333 139.SH EXAMPLES
d2b53444
MK
140The following program displays the results when
141.BR rpmatch ()
142is applied to the string given in the program's command-line argument.
207050fa
MK
143.PP
144.EX
d2b53444
MK
145#define _SVID_SOURCE
146#include <locale.h>
147#include <stdlib.h>
148#include <string.h>
149#include <stdio.h>
150
151int
152main(int argc, char *argv[])
153{
29059a65 154 if (argc != 2 || strcmp(argv[1], "\-\-help") == 0) {
d1a71985 155 fprintf(stderr, "%s response\en", argv[0]);
d2b53444 156 exit(EXIT_FAILURE);
c13182ef 157 }
d2b53444
MK
158
159 setlocale(LC_ALL, "");
d1a71985 160 printf("rpmatch() returns: %d\en", rpmatch(argv[1]));
d2b53444
MK
161 exit(EXIT_SUCCESS);
162}
207050fa 163.EE
d2b53444 164.SH SEE ALSO
d2b53444
MK
165.BR fgets (3),
166.BR getline (3),
167.BR nl_langinfo (3),
f0c34053 168.BR regcomp (3),
cc4615cc 169.BR setlocale (3)