]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/rpmatch.3
fd7b889f9330645332e0fd78c5fff2a23cfd1d39
[thirdparty/man-pages.git] / man3 / rpmatch.3
1 .\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
2 .\"
3 .\" %%%LICENSE_START(PERMISSIVE_MISC)
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.
22 .\" %%%LICENSE_END
23 .\"
24 .\" References:
25 .\" glibc manual and source
26 .\"
27 .\" 2006-05-19, mtk, various edits and example program
28 .\"
29 .TH RPMATCH 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
30 .SH NAME
31 rpmatch \- determine if the answer to a question is affirmative or negative
32 .SH LIBRARY
33 Standard C library
34 .RI ( libc ", " \-lc )
35 .SH SYNOPSIS
36 .nf
37 .B #include <stdlib.h>
38 .PP
39 .BI "int rpmatch(const char *" response );
40 .fi
41 .PP
42 .RS -4
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
45 .RE
46 .PP
47 .BR rpmatch ():
48 .nf
49 Since glibc 2.19:
50 _DEFAULT_SOURCE
51 Glibc 2.19 and earlier:
52 _SVID_SOURCE
53 .fi
54 .SH DESCRIPTION
55 .BR rpmatch ()
56 handles a user response to yes or no questions, with
57 support for internationalization.
58 .PP
59 .I response
60 should be a null-terminated string containing a
61 user-supplied response, perhaps obtained with
62 .BR fgets (3)
63 or
64 .BR getline (3).
65 .PP
66 The user's language preference is taken into account per the
67 environment variables
68 .BR LANG ,
69 .BR LC_MESSAGES ,
70 and
71 .BR LC_ALL ,
72 if the program has called
73 .BR setlocale (3)
74 to effect their changes.
75 .PP
76 Regardless of the locale, responses matching
77 .B \(ha[Yy]
78 are always accepted as affirmative, and those matching
79 .B \(ha[Nn]
80 are always accepted as negative.
81 .SH RETURN VALUE
82 After examining
83 .IR response ,
84 .BR rpmatch ()
85 returns 0 for a recognized negative response ("no"), 1
86 for a recognized positive response ("yes"), and \-1 when the value
87 of
88 .I response
89 is unrecognized.
90 .SH ERRORS
91 A return value of \-1 may indicate either an invalid input, or some
92 other error.
93 It is incorrect to only test if the return value is nonzero.
94 .PP
95 .BR rpmatch ()
96 can fail for any of the reasons that
97 .BR regcomp (3)
98 or
99 .BR regexec (3)
100 can fail; the cause of the error
101 is not available from
102 .I errno
103 or anywhere else, but indicates a
104 failure of the regex engine (but this case is indistinguishable from
105 that of an unrecognized value of
106 .IR response ).
107 .SH ATTRIBUTES
108 For an explanation of the terms used in this section, see
109 .BR attributes (7).
110 .ad l
111 .nh
112 .TS
113 allbox;
114 lbx lb lb
115 l l l.
116 Interface Attribute Value
117 T{
118 .BR rpmatch ()
119 T} Thread safety MT-Safe locale
120 .TE
121 .hy
122 .ad
123 .sp 1
124 .SH STANDARDS
125 .BR rpmatch ()
126 is not required by any standard,
127 but available under the GNU C library, FreeBSD, and AIX.
128 .SH BUGS
129 The
130 .BR YESEXPR " and " NOEXPR
131 of some locales (including "C") only inspect the first character of the
132 .IR response .
133 This can mean that "yno" et al. resolve to
134 .BR 1 .
135 This is an unfortunate historical side-effect which should be fixed in time
136 with proper localisation, and should not deter from
137 .BR rpmatch ()
138 being the proper way to distinguish between binary answers.
139 .SH EXAMPLES
140 The following program displays the results when
141 .BR rpmatch ()
142 is applied to the string given in the program's command-line argument.
143 .PP
144 .EX
145 #define _SVID_SOURCE
146 #include <locale.h>
147 #include <stdlib.h>
148 #include <string.h>
149 #include <stdio.h>
150
151 int
152 main(int argc, char *argv[])
153 {
154 if (argc != 2 || strcmp(argv[1], "\-\-help") == 0) {
155 fprintf(stderr, "%s response\en", argv[0]);
156 exit(EXIT_FAILURE);
157 }
158
159 setlocale(LC_ALL, "");
160 printf("rpmatch() returns: %d\en", rpmatch(argv[1]));
161 exit(EXIT_SUCCESS);
162 }
163 .EE
164 .SH SEE ALSO
165 .BR fgets (3),
166 .BR getline (3),
167 .BR nl_langinfo (3),
168 .BR regcomp (3),
169 .BR setlocale (3)