fnmatch

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

fnmatch - ファイル名またはパス名へのマッチを行う  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <fnmatch.h>

int fnmatch(const char *pattern, const char *string, int flags);
 

説明

fnmatch() 関数は strings 引数が pattern 引数にマッチするかをチェックする。 pattern にはシェルのワイルドカードパターンを与える (glob(7) 参照)。

flags 引数により動作を変更できる。 flags は以下のフラグのビット毎の OR で指定する。

FNM_NOESCAPE
このフラグがセットされていると、バックスラッシュ (\) をエスケープ文字 ではなく通常の文字として扱う。
FNM_PATHNAME
このフラグがセットされていると、 string 中のスラッシュ (/) を pattern にあるスラッシュそのものにだけマッチさせ、 アスタリスク (*) や疑問符 (?) のメタキャラクターや、 スラッシュを含むブラケット表現 ([]) にはマッチさせない。
FNM_PERIOD
このフラグがセットされていると、 string の先頭ピリオド (leading period) は pattern 中のピリオドそのものにしかマッチしない。先頭ピリオドとは、 string の最初の文字位置にあるピリオドのことである。ただし FNM_PATHNAME フラグが同時にセットされている場合には、スラッシュの直後に続くピリオド も先頭ピリオドとみなされる。
FNM_FILE_NAME
これは FNM_PATHNAME に対する GNU での同義語である.
FNM_LEADING_DIR
このフラグは GNU での拡張である。これがセットされている場合には、 パターンが string の最初の部分 (にスラッシュを付けたもの) にマッチすれば、 マッチしたものとみなされる。 このフラグは主として glibc で内部的に使用するもので、そのためにのみ実装されている。
FNM_CASEFOLD
FNM_IGNORECASE (FNM_CASEFOLD と同じ)
このフラグがセットされている場合には、 パターンのマッチに大文字小文字が区別されない。
FNM_EXTMATCH
If this flag (a GNU extension) is set, extended patterns are supported, as introduced by 'ksh' and now supported by other shells. The extended format is as follows, with pattern-list being a '|' separated list of patterns.
'?(pattern-list)'
The pattern matches if zero or one occurrences of any of the patterns in the pattern-list match the input string.
'*(pattern-list)'
The pattern matches if zero or more occurrences of any of the patterns in the pattern-list match the input string.
'+(pattern-list)'
The pattern matches if one or more occurrences of any of the patterns in the pattern-list match the input string.
'@(pattern-list)'
The pattern matches if exactly one occurrence of any of the patterns in the pattern-list match the input string.
'!(pattern-list)'
The pattern matches if the input string cannot be matched with any of the patterns in the pattern-list.
 

返り値

string が pattern にマッチすれば 0 を返す。マッチしなかった場合には FNM_NOMATCH を返す。エラーの場合にはそれ以外の非ゼロ値を返す。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
fnmatch() Thread safetyMT-Safe env locale
 

標準規格

fnmatch()
POSIX.1-2008.
FNM_CASEFOLD
FNM_IGNORECASE
POSIX.1-2024.
FNM_FILE_NAME
FNM_LEADING_DIR
GNU.
 

歴史

fnmatch()
POSIX.1-2001, POSIX.2.
FNM_CASEFOLD
has been available on many systems even before POSIX.1-2024.
 

関連項目

sh(1), glob(3), scandir(3), wordexp(3), glob(7)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
関連項目

This document was created by man2html, using the manual pages.