#include <fnmatch.h>
#include "ruby.h"

static VALUE f_fnmatch(VALUE self, VALUE pattern, VALUE string, VALUE flags)
{
    int ret;

    ret = fnmatch(STR2CSTR(pattern), STR2CSTR(string), NUM2INT(flags));
    switch (ret) {
    case 0:
        return Qtrue;
    case FNM_NOMATCH:
        return Qfalse;
    default:
        rb_raise(rb_eRuntimeError, "error");
    }
}

void Init_fnmatch()
{
    rb_define_global_function("fnmatch", f_fnmatch, 3);
    rb_define_global_const("FNM_NOESCAPE", INT2NUM(FNM_NOESCAPE));
    rb_define_global_const("FNM_PATHNAME", INT2NUM(FNM_PATHNAME));
    rb_define_global_const("FNM_PERIOD", INT2NUM(FNM_PERIOD));
}

