rpmatch(3)

πŸ’– rpmatch(3) πŸ’–

okay bestie, so rpmatch is a little library function from the Library Functions Manual (yes, that's the rpmatch(3) page you're reading right now, hi πŸ‘‹), and it's the girl who answers the question "did they say yes or no?" for you. let's get into it 🩷


✨ NAME ✨

rpmatch β€” figure out whether the answer to a question is affirmative or negative πŸ’…


πŸŽ€ LIBRARY πŸŽ€

Standard C library (libc, -lc) β€” you know her, you love her 🫢


🌸 SYNOPSIS 🌸

#include <stdlib.h>

int rpmatch(const char *response);

πŸ¦‹ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

rpmatch():

  • Since glibc 2.19:
    • _DEFAULT_SOURCE
  • glibc 2.19 and earlier:
    • _SVID_SOURCE
ok so lowkey this is the part where you have to prove you're allowed to use her before she shows up. no macro, no function, no cap πŸ’€

πŸ’œ DESCRIPTION πŸ’œ

rpmatch() handles a user's response to a yes-or-no question, and it does it with internationalization support, which is so main character of it actually 🌍✨

response should be a null-terminated string holding a user-supplied response β€” probs something you grabbed with fgets(3) or getline(3), you know the drill.

The user's language preference gets taken into account based on the environment variables LANG, LC_MESSAGES, and LC_ALL β€” but ONLY if the program has called setlocale(3) to make those changes actually happen. no setlocale, no vibe check, sorry babe πŸ™ˆ

And regardless of the locale, responses matching ^[Yy] are ALWAYS accepted as affirmative, and the ones matching ^[Nn] are ALWAYS accepted as negative. always. periodt. πŸ‘‘


⭐ RETURN VALUE ⭐

After examining response, rpmatch() hands you back:

  • 0 β€” for a recognized negative response ("no") πŸ™…
  • 1 β€” for a recognized positive response ("yes") πŸ’―
  • -1 β€” when the value of response is unrecognized 😭

πŸ’€ ERRORS πŸ’€

A return value of -1 may indicate EITHER an invalid input OR some other error. so it is incorrect to only test whether the return value is nonzero. like, you cannot just go "oh it's not zero, we're fine." no ma'am. 🚫

rpmatch() can also fail for any of the reasons that regcomp(3) or regexec(3) can fail β€” and the error is not available from errno or anywhere else, it just indicates a failure of the regex engine. (but honestly this case is indistinguishable from that of an unrecognized value of response, so good luck bestie 🫠)


🧚 ATTRIBUTES 🧚

For an explanation of the terms used in this section, see attributes(7).

  • Interface: rpmatch()
  • Attribute: Thread safety
  • Value: MT-Safe locale

🌈 STANDARDS 🌈

None. she's not in any standard. she's just out here living her truth πŸ’…


πŸ“œ HISTORY πŸ“œ

GNU, FreeBSD, AIX. the iconic trio 🎬


πŸ› BUGS πŸ›

ok so this is the messy part, listen up πŸ‘€

The YESEXPR and NOEXPR of some locales (including "C") only inspect the first character of the response. which means "yno" et al. can resolve to 1. yeah. πŸ’€

This is an unfortunate historical side-effect which should be fixed in time with proper localisation β€” and it should not deter you from using rpmatch() as the proper way to distinguish between binary answers. she's still the one, fr fr 🫢


✨ EXAMPLES ✨

This program below displays the results when rpmatch() is applied to the string given in the program's command-line argument πŸ“

#define _DEFAULT_SOURCE
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define streq(...)  (strcmp(__VA_ARGS__) == 0)

int
main(int argc, char *argv[])
{
    if (argc != 2 || streq(argv[1], "--help")) {
        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 πŸ‘‘

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


<div align="center">🌸 πŸ’– 🌸</div>

and that's the whole page bestie πŸ’• this was Linux man-pages 6.20, dated 2026-02-22 β€” mwah, go forth and never test != 0 again πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms