Skip to content

Commit

Permalink
match.c: Add support for fnmatch based patterns (not yet used)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceg committed Mar 18, 2014
1 parent fa4c3d9 commit 2d14db2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion match.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <fnmatch.h>
#include "byte.h"
#include "match.h"

int match(const char *pattern,const char *buf,unsigned int len)
int match_simple(const char *pattern,const char *buf,unsigned int len)
{
char ch;

Expand All @@ -22,3 +24,13 @@ int match(const char *pattern,const char *buf,unsigned int len)
++buf; --len;
}
}

int match_fnmatch(const char *pattern,const char *buf,unsigned int len)
{
char tmp[len+1];
byte_copy(tmp,len,buf);
tmp[len] = 0;
return fnmatch(pattern,tmp,0) == 0;
}

int (*match)(const char *pattern,const char *buf,unsigned int len) = match_simple;
4 changes: 3 additions & 1 deletion match.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef MATCH_H
#define MATCH_H

extern int match(const char *,const char *,unsigned int);
extern int match_simple(const char *,const char *,unsigned int);
extern int match_fnmatch(const char *,const char *,unsigned int);
extern int (*match)(const char *,const char *,unsigned int);

#endif

0 comments on commit 2d14db2

Please sign in to comment.