man-pages/man3/rpmatch.3.html
2021-03-31 01:06:50 +01:00

241 lines
6.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of RPMATCH</TITLE>
</HEAD><BODY>
<H1>RPMATCH</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
rpmatch - determine if the answer to a question is affirmative or negative
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;</B>
<B>int rpmatch(const char *</B><I>response</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>rpmatch</B>():
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Since&nbsp;glibc&nbsp;2.19:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Glibc&nbsp;2.19&nbsp;and&nbsp;earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_SVID_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>rpmatch</B>()
handles a user response to yes or no questions, with
support for internationalization.
<P>
<I>response</I>
should be a null-terminated string containing a
user-supplied response, perhaps obtained with
<B><A HREF="/cgi-bin/man/man2html?3+fgets">fgets</A></B>(3)
or
<B><A HREF="/cgi-bin/man/man2html?3+getline">getline</A></B>(3).
<P>
The user's language preference is taken into account per the
environment variables
<B>LANG</B>,
<B>LC_MESSAGES</B>,
and
<B>LC_ALL</B>,
if the program has called
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3)
to effect their changes.
<P>
Regardless of the locale, responses matching
<B>^[Yy]</B>
are always accepted as affirmative, and those matching
<B>^[Nn]</B>
are always accepted as negative.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
After examining
<I>response</I>,
<B>rpmatch</B>()
returns 0 for a recognized negative response (&quot;no&quot;), 1
for a recognized positive response (&quot;yes&quot;), and -1 when the value
of
<I>response</I>
is unrecognized.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
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 nonzero.
<P>
<B>rpmatch</B>()
can fail for any of the reasons that
<B><A HREF="/cgi-bin/man/man2html?3+regcomp">regcomp</A></B>(3)
or
<B><A HREF="/cgi-bin/man/man2html?3+regexec">regexec</A></B>(3)
can fail; the cause of the error
is not available from
<I>errno</I>
or anywhere else, but indicates a
failure of the regex engine (but this case is indistinguishable from
that of an unrecognized value of
<I>response</I>).
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>rpmatch</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>rpmatch</B>()
is not required by any standard, but
is available on a few other systems.
<A NAME="lbAI">&nbsp;</A>
<H2>BUGS</H2>
The
<B>rpmatch</B>()
implementation looks at only the first character
of
<I>response</I>.
As a consequence, &quot;nyes&quot; returns 0, and
&quot;ynever; not in a million years&quot; returns 1.
It would be preferable to accept input strings much more
strictly, for example (using the extended regular
expression notation described in
<B><A HREF="/cgi-bin/man/man2html?7+regex">regex</A></B>(7)):
<B>^([yY]|yes|YES)$</B>
and
<B>^([nN]|no|NO)$</B>.
<A NAME="lbAJ">&nbsp;</A>
<H2>EXAMPLE</H2>
The following program displays the results when
<B>rpmatch</B>()
is applied to the string given in the program's command-line argument.
<P>
#define _SVID_SOURCE
#include &lt;<A HREF="file:///usr/include/locale.h">locale.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/string.h">string.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
<P>
int
main(int argc, char *argv[])
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(argc&nbsp;!=&nbsp;2&nbsp;||&nbsp;strcmp(argv[1],&nbsp;&quot;--help&quot;)&nbsp;==&nbsp;0)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;&quot;%s&nbsp;response\n&quot;,&nbsp;argv[0]);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_FAILURE);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;setlocale(LC_ALL,&nbsp;&quot;&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;rpmatch()&nbsp;returns:&nbsp;%d\n&quot;,&nbsp;rpmatch(argv[1]));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+fgets">fgets</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getline">getline</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+nl_langinfo">nl_langinfo</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+regcomp">regcomp</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="6"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="7"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="8"><A HREF="#lbAI">BUGS</A><DD>
<DT id="9"><A HREF="#lbAJ">EXAMPLE</A><DD>
<DT id="10"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="11"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:54 GMT, March 31, 2021
</BODY>
</HTML>