#include <stdlib.h> int rpmatch(const char *response);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
rpmatch():
Since glibc 2.19:
_DEFAULT_SOURCE
glibc 2.19 and earlier:
_SVID_SOURCE
response にはユーザーからの応答を格納したヌル終端文字列が入っている必要がある。 たいていは、 fgets(3) や getline(3) で取り込んだものであろう。
プログラムが setlocale(3) を呼び出して環境変数の変更を有効にした場合、 環境変数 LANG, LC_MESSAGES, LC_ALL が ユーザーの言語設定として考慮される。
Regardless of the locale, responses matching ^[Yy] are always accepted as affirmative, and those matching ^[Nn] are always accepted as negative.
rpmatch() can fail for any of the reasons that regcomp(3) or regexec(3) can fail; the error is not available from errno or anywhere else, but indicates a failure of the regex engine (but this case is indistinguishable from that of an unrecognized value of response).
| インターフェース | 属性 | 値 |
| rpmatch() | Thread safety | MT-Safe locale |
#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);
}