1RPMATCH(3) Linux Programmer's Manual RPMATCH(3)
2
3
4
6 rpmatch - determine if the answer to a question is affirmative or nega‐
7 tive
8
10 #include <stdlib.h>
11
12 int rpmatch(const char *response);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 rpmatch(): _SVID_SOURCE
17
19 rpmatch() handles a user response to yes or no questions, with support
20 for internationalization.
21
22 response should be a null-terminated string containing a user-supplied
23 response, perhaps obtained with fgets(3) or getline(3).
24
25 The user's language preference is taken into account per the environ‐
26 ment variables LANG, LC_MESSAGES, and LC_ALL, if the program has called
27 setlocale(3) to effect their changes.
28
29 Regardless of the locale, responses matching ^[Yy] are always accepted
30 as affirmative, and those matching ^[Nn] are always accepted as nega‐
31 tive.
32
34 After examining response, rpmatch() returns 0 for a recognized negative
35 response ("no"), 1 for a recognized positive response ("yes"), and -1
36 when the value of response is unrecognized.
37
39 A return value of -1 may indicate either an invalid input, or some
40 other error. It is incorrect to only test if the return value is
41 nonzero.
42
43 rpmatch() can fail for any of the reasons that regcomp(3) or regexec(3)
44 can fail; the cause of the error is not available from errno or any‐
45 where else, but indicates a failure of the regex engine (but this case
46 is indistinguishable from that of an unrecognized value of response).
47
49 rpmatch() is not required by any standard, but is available on a few
50 other systems.
51
53 The rpmatch() implementation looks at only the first character of
54 response. As a consequence, "nyes" returns 0, and "ynever; not in a
55 million years" returns 1. It would be preferable to accept input
56 strings much more strictly, for example (using the extended regular
57 expression notation described in regex(7)): ^([yY]|yes|YES)$ and
58 ^([nN]|no|NO)$.
59
61 The following program displays the results when rpmatch() is applied to
62 the string given in the program's command-line argument.
63
64 #define _SVID_SOURCE
65 #include <locale.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #include <stdio.h>
69
70 int
71 main(int argc, char *argv[])
72 {
73 if (argc != 2 || strcmp(argv[1], "--help") == 0) {
74 fprintf(stderr, "%s response\n", argv[0]);
75 exit(EXIT_FAILURE);
76 }
77
78 setlocale(LC_ALL, "");
79 printf("rpmatch() returns: %d\n", rpmatch(argv[1]));
80 exit(EXIT_SUCCESS);
81 }
82
84 fgets(3), getline(3), nl_langinfo(3), regcomp(3), setlocale(3)
85
87 This page is part of release 3.25 of the Linux man-pages project. A
88 description of the project, and information about reporting bugs, can
89 be found at http://www.kernel.org/doc/man-pages/.
90
91
92
93GNU 2007-07-26 RPMATCH(3)