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