1RPMATCH(3)                 Linux Programmer's Manual                RPMATCH(3)
2
3
4

NAME

6       rpmatch - determine if the answer to a question is affirmative or nega‐
7       tive
8

SYNOPSIS

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():
17           Since glibc 2.19:
18               _DEFAULT_SOURCE
19           Glibc 2.19 and earlier:
20               _SVID_SOURCE
21

DESCRIPTION

23       rpmatch() handles a user response to yes or no questions, with  support
24       for internationalization.
25
26       response  should be a null-terminated string containing a user-supplied
27       response, perhaps obtained with fgets(3) or getline(3).
28
29       The user's language preference is taken into account per  the  environ‐
30       ment variables LANG, LC_MESSAGES, and LC_ALL, if the program has called
31       setlocale(3) to effect their changes.
32
33       Regardless of the locale, responses matching ^[Yy] are always  accepted
34       as  affirmative,  and those matching ^[Nn] are always accepted as nega‐
35       tive.
36

RETURN VALUE

38       After examining response, rpmatch() returns 0 for a recognized negative
39       response  ("no"),  1 for a recognized positive response ("yes"), and -1
40       when the value of response is unrecognized.
41

ERRORS

43       A return value of -1 may indicate either  an  invalid  input,  or  some
44       other  error.  It is incorrect to only test if the return value is non‐
45       zero.
46
47       rpmatch() can fail for any of the reasons that regcomp(3) or regexec(3)
48       can  fail;  the  cause of the error is not available from errno or any‐
49       where else, but indicates a failure of the regex engine (but this  case
50       is indistinguishable from that of an unrecognized value of response).
51

ATTRIBUTES

53       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
54       tributes(7).
55
56       ┌──────────┬───────────────┬────────────────┐
57Interface Attribute     Value          
58       ├──────────┼───────────────┼────────────────┤
59rpmatch() │ Thread safety │ MT-Safe locale │
60       └──────────┴───────────────┴────────────────┘
61

CONFORMING TO

63       rpmatch() is not required by any standard, but is available  on  a  few
64       other systems.
65

BUGS

67       The  rpmatch()  implementation looks at only the first character of re‐
68       sponse.  As a consequence, "nyes" returns 0, and "ynever; not in a mil‐
69       lion  years" returns 1.  It would be preferable to accept input strings
70       much more strictly, for example (using the extended regular  expression
71       notation described in regex(7)): ^([yY]|yes|YES)$ and ^([nN]|no|NO)$.
72

EXAMPLES

74       The following program displays the results when rpmatch() is applied to
75       the string given in the program's command-line argument.
76
77       #define _SVID_SOURCE
78       #include <locale.h>
79       #include <stdlib.h>
80       #include <string.h>
81       #include <stdio.h>
82
83       int
84       main(int argc, char *argv[])
85       {
86           if (argc != 2 || strcmp(argv[1], "--help") == 0) {
87               fprintf(stderr, "%s response\n", argv[0]);
88               exit(EXIT_FAILURE);
89           }
90
91           setlocale(LC_ALL, "");
92           printf("rpmatch() returns: %d\n", rpmatch(argv[1]));
93           exit(EXIT_SUCCESS);
94       }
95

SEE ALSO

97       fgets(3), getline(3), nl_langinfo(3), regcomp(3), setlocale(3)
98

COLOPHON

100       This page is part of release 5.10 of the Linux  man-pages  project.   A
101       description  of  the project, information about reporting bugs, and the
102       latest    version    of    this    page,    can     be     found     at
103       https://www.kernel.org/doc/man-pages/.
104
105
106
107GNU                               2020-06-09                        RPMATCH(3)
Impressum