CINXE.COM

rpmatch

<html> <head> <title>rpmatch</title> <META NAME="KEYWORDS" CONTENT="rpmatch"> </head> <body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#0000ff" ALINK="#0000ff" TEXT="#000000"> <center> <h1><b>rpmatch</b></h1></center> <PRE> <STRONG><A HREF="/man3/RPMATCH">RPMATCH(3)</A></STRONG> Linux Programmer's Manual <STRONG><A HREF="/man3/RPMATCH">RPMATCH(3)</A></STRONG> NAME rpmatch - determine if the answer to a question is affirmative or nega- tive SYNOPSIS #include &lt;stdlib.h&gt; int rpmatch(const char *response); Feature Test Macro Requirements for glibc (see <STRONG><A HREF="/man7/feature_test_macros">feature_test_macros(7)</A></STRONG>): rpmatch(): Since glibc 2.19: _DEFAULT_SOURCE Glibc 2.19 and earlier: _SVID_SOURCE DESCRIPTION rpmatch() handles a user response to yes or no questions, with support for internationalization. response should be a null-terminated string containing a user-supplied response, perhaps obtained with <STRONG><A HREF="/man3/fgets">fgets(3)</A></STRONG> or <STRONG><A HREF="/man3/getline">getline(3)</A></STRONG>. The user's language preference is taken into account per the environ- ment variables LANG, LC_MESSAGES, and LC_ALL, if the program has called <STRONG><A HREF="/man3/setlocale">setlocale(3)</A></STRONG> to effect their changes. Regardless of the locale, responses matching ^[Yy] are always accepted as affirmative, and those matching ^[Nn] are always accepted as nega- tive. RETURN VALUE After examining response, rpmatch() returns 0 for a recognized negative response ("no"), 1 for a recognized positive response ("yes"), and -1 when the value of response is unrecognized. ERRORS A return value of -1 may indicate either an invalid input, or some other error. It is incorrect to only test if the return value is non- zero. rpmatch() can fail for any of the reasons that <STRONG><A HREF="/man3/regcomp">regcomp(3)</A></STRONG> or <STRONG><A HREF="/man3/regexec">regexec(3)</A></STRONG> can fail; the cause of the error is not available from errno or any- where else, but indicates a failure of the regex engine (but this case is indistinguishable from that of an unrecognized value of response). ATTRIBUTES For an explanation of the terms used in this section, see at- <STRONG><A HREF="/man7/tributes">tributes(7)</A></STRONG>. +----------+---------------+----------------+ |Interface | Attribute | Value | +----------+---------------+----------------+ |rpmatch() | Thread safety | MT-Safe locale | +----------+---------------+----------------+ CONFORMING TO rpmatch() is not required by any standard, but is available on a few other systems. BUGS The rpmatch() implementation looks at only the first character of re- sponse. As a consequence, "nyes" returns 0, and "ynever; not in a mil- lion years" returns 1. It would be preferable to accept input strings much more strictly, for example (using the extended regular expression notation described in <STRONG><A HREF="/man7/regex">regex(7)</A></STRONG>): ^([yY]|yes|YES)$ and ^([nN]|no|NO)$. EXAMPLE The following program displays the results when rpmatch() is applied to the string given in the program's command-line argument. #define _SVID_SOURCE #include &lt;locale.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;stdio.h&gt; int main(int argc, char *argv[]) { if (argc != 2 || strcmp(argv[1], "--help") == 0) { fprintf(stderr, "%s response\n", argv[0]); exit(EXIT_FAILURE); } setlocale(LC_ALL, ""); printf("rpmatch() returns: %d\n", rpmatch(argv[1])); exit(EXIT_SUCCESS); } SEE ALSO <STRONG><A HREF="/man3/fgets">fgets(3)</A></STRONG>, <STRONG><A HREF="/man3/getline">getline(3)</A></STRONG>, <STRONG><A HREF="/man3/nl_langinfo">nl_langinfo(3)</A></STRONG>, <STRONG><A HREF="/man3/regcomp">regcomp(3)</A></STRONG>, <STRONG><A HREF="/man3/setlocale">setlocale(3)</A></STRONG> COLOPHON This page is part of release 5.05 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU 2019-03-06 <STRONG><A HREF="/man3/RPMATCH">RPMATCH(3)</A></STRONG></PRE> <center> <h6>Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2025 <a href="http://www.he.net">Hurricane Electric</a>. All Rights Reserved.</h6></center> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10