1rpmatch(3)                 Library Functions Manual                 rpmatch(3)
2
3
4

NAME

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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <stdlib.h>
14
15       int rpmatch(const char *response);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       rpmatch():
20           Since glibc 2.19:
21               _DEFAULT_SOURCE
22           glibc 2.19 and earlier:
23               _SVID_SOURCE
24

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

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

STANDARDS

66       None.
67

HISTORY

69       GNU, FreeBSD, AIX.
70

BUGS

72       The YESEXPR and NOEXPR of some locales (including "C") only inspect the
73       first  character  of  the  response.   This  can mean that "yno" et al.
74       resolve to 1.  This is  an  unfortunate  historical  side-effect  which
75       should  be fixed in time with proper localisation, and should not deter
76       from rpmatch() being the  proper  way  to  distinguish  between  binary
77       answers.
78

EXAMPLES

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

SEE ALSO

103       fgets(3), getline(3), nl_langinfo(3), regcomp(3), setlocale(3)
104
105
106
107Linux man-pages 6.05              2023-07-20                        rpmatch(3)
Impressum