]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/rpmatch.3
pow.3: Minor tweak to BUGS
[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.\"
9ba01802 29.TH RPMATCH 3 2019-03-06 "GNU" "Linux Programmer's Manual"
d2b53444
MK
30.SH NAME
31rpmatch \- determine if the answer to a question is affirmative or negative
32.SH SYNOPSIS
3b158837 33.nf
ddba45e1 34.B #include <stdlib.h>
f90f031e 35.PP
ddba45e1 36.BI "int rpmatch(const char *" response );
3b158837 37.fi
68e4db0a 38.PP
cc4615cc
MK
39.in -4n
40Feature Test Macro Requirements for glibc (see
41.BR feature_test_macros (7)):
42.in
68e4db0a 43.PP
cc4615cc 44.BR rpmatch ():
51c612fb
MK
45 Since glibc 2.19:
46 _DEFAULT_SOURCE
47 Glibc 2.19 and earlier:
48 _SVID_SOURCE
d2b53444 49.SH DESCRIPTION
60a90ecd
MK
50.BR rpmatch ()
51handles a user response to yes or no questions, with
c13182ef 52support for internationalization.
847e0d88 53.PP
c6fa0841
MK
54.I response
55should be a null-terminated string containing a
60a90ecd
MK
56user-supplied response, perhaps obtained with
57.BR fgets (3)
58or
59.BR getline (3).
847e0d88 60.PP
6a39becb 61The user's language preference is taken into account per the
c6fa0841
MK
62environment variables
63.BR LANG ,
64.BR LC_MESSAGES ,
65and
66.BR LC_ALL ,
60a90ecd
MK
67if the program has called
68.BR setlocale (3)
69to effect their changes.
847e0d88 70.PP
c6fa0841
MK
71Regardless of the locale, responses matching
72.B ^[Yy]
73are always accepted as affirmative, and those matching
74.B ^[Nn]
75are always accepted as negative.
47297adb 76.SH RETURN VALUE
c13182ef
MK
77After examining
78.IR response ,
60a90ecd
MK
79.BR rpmatch ()
80returns 0 for a recognized negative response ("no"), 1
d2b53444 81for a recognized positive response ("yes"), and \-1 when the value
c6fa0841
MK
82of
83.I response
84is unrecognized.
d2b53444
MK
85.SH ERRORS
86A return value of \-1 may indicate either an invalid input, or some
c13182ef 87other error.
c7094399 88It is incorrect to only test if the return value is nonzero.
847e0d88 89.PP
60a90ecd
MK
90.BR rpmatch ()
91can fail for any of the reasons that
92.BR regcomp (3)
93or
94.BR regexec (3)
95can fail; the cause of the error
c6fa0841
MK
96is not available from
97.I errno
98or anywhere else, but indicates a
d2b53444 99failure of the regex engine (but this case is indistinguishable from
c6fa0841
MK
100that of an unrecognized value of
101.IR response ).
c17fc186
ZL
102.SH ATTRIBUTES
103For an explanation of the terms used in this section, see
104.BR attributes (7).
105.TS
106allbox;
107lb lb lb
108l l l.
109Interface Attribute Value
110T{
111.BR rpmatch ()
112T} Thread safety MT-Safe locale
113.TE
847e0d88 114.sp 1
47297adb 115.SH CONFORMING TO
60a90ecd
MK
116.BR rpmatch ()
117is not required by any standard, but
d2b53444
MK
118is available on a few other systems.
119.\" It is available on at least AIX 5.1 and FreeBSD 6.0.
120.SH BUGS
60a90ecd
MK
121The
122.BR rpmatch ()
123implementation looks at only the first character
c6fa0841
MK
124of
125.IR response .
c13182ef 126As a consequence, "nyes" returns 0, and
d2b53444
MK
127"ynever; not in a million years" returns 1.
128It would be preferable to accept input strings much more
c13182ef 129strictly, for example (using the extended regular
60a90ecd
MK
130expression notation described in
131.BR regex (7)):
c6fa0841
MK
132.B ^([yY]|yes|YES)$
133and
134.BR ^([nN]|no|NO)$ .
3721893a 135.SH EXAMPLE
d2b53444
MK
136The following program displays the results when
137.BR rpmatch ()
138is applied to the string given in the program's command-line argument.
207050fa
MK
139.PP
140.EX
d2b53444
MK
141#define _SVID_SOURCE
142#include <locale.h>
143#include <stdlib.h>
144#include <string.h>
145#include <stdio.h>
146
147int
148main(int argc, char *argv[])
149{
29059a65 150 if (argc != 2 || strcmp(argv[1], "\-\-help") == 0) {
d1a71985 151 fprintf(stderr, "%s response\en", argv[0]);
d2b53444 152 exit(EXIT_FAILURE);
c13182ef 153 }
d2b53444
MK
154
155 setlocale(LC_ALL, "");
d1a71985 156 printf("rpmatch() returns: %d\en", rpmatch(argv[1]));
d2b53444
MK
157 exit(EXIT_SUCCESS);
158}
207050fa 159.EE
d2b53444 160.SH SEE ALSO
d2b53444
MK
161.BR fgets (3),
162.BR getline (3),
163.BR nl_langinfo (3),
f0c34053 164.BR regcomp (3),
cc4615cc 165.BR setlocale (3)