Changeset 904b1bc in mainline for uspace/lib/posix/src/fnmatch.c
- Timestamp:
- 2018-05-22T10:36:58Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a4eb3ba2
- Parents:
- 4f8772d4
- git-author:
- Jiri Svoboda <jiri@…> (2018-05-21 17:36:30)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-05-22 10:36:58)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/fnmatch.c
r4f8772d4 r904b1bc 33 33 */ 34 34 35 /* This file contains an implementation of the fnmatch() pattern matching 35 /* 36 * This file contains an implementation of the fnmatch() pattern matching 36 37 * function. There is more code than necessary to account for the possibility 37 38 * of adding POSIX-like locale support to the system in the future. Functions … … 54 55 #define INVALID_PATTERN -1 55 56 56 /* Type for collating element, simple identity with characters now, 57 /* 58 * Type for collating element, simple identity with characters now, 57 59 * but may be extended for better locale support. 58 60 */ … … 70 72 * @return Matching collating element or COLL_ELM_INVALID. 71 73 */ 72 static coll_elm_t _coll_elm_get(const char *str)74 static coll_elm_t _coll_elm_get(const char *str) 73 75 { 74 76 if (str[0] == '\0' || str[1] != '\0') { … … 306 308 } 307 309 308 /** 309 * Matches the beginning of the given string against a bracket expression 310 * the pattern begins with. 311 * 312 * @param pattern Pointer to the beginning of a bracket expression in a pattern. 313 * On success, the pointer is moved to the first character after the 314 * bracket expression. 315 * @param str Unmatched part of the string. 316 * @param flags Flags given to fnmatch(). 317 * @return INVALID_PATTERN if the pattern is invalid, 0 if there is no match 318 * or the number of matched characters on success. 319 */ 320 static int _match_bracket_expr(const char **pattern, const char *str, int flags) 321 { 322 const bool pathname = (flags & FNM_PATHNAME) != 0; 323 const bool special_period = (flags & FNM_PERIOD) != 0; 324 const char *p = *pattern; 325 bool negative = false; 326 int matched = 0; 327 328 #define _matched(match) { \ 310 #define _matched(match) { \ 329 311 int _match = match; \ 330 312 if (_match < 0) { \ … … 337 319 } 338 320 321 /** 322 * Matches the beginning of the given string against a bracket expression 323 * the pattern begins with. 324 * 325 * @param pattern Pointer to the beginning of a bracket expression in a pattern. 326 * On success, the pointer is moved to the first character after the 327 * bracket expression. 328 * @param str Unmatched part of the string. 329 * @param flags Flags given to fnmatch(). 330 * @return INVALID_PATTERN if the pattern is invalid, 0 if there is no match 331 * or the number of matched characters on success. 332 */ 333 static int _match_bracket_expr(const char **pattern, const char *str, int flags) 334 { 335 const bool pathname = (flags & FNM_PATHNAME) != 0; 336 const bool special_period = (flags & FNM_PERIOD) != 0; 337 const char *p = *pattern; 338 bool negative = false; 339 int matched = 0; 340 339 341 assert(*p == '['); /* calling code should ensure this */ 340 342 p++; … … 342 344 if (*str == '\0' || (pathname && *str == '/') || 343 345 (pathname && special_period && *str == '.' && *(str - 1) == '/')) { 344 /* No bracket expression matches end of string, 346 /* 347 * No bracket expression matches end of string, 345 348 * slash in pathname match or initial period with FNM_PERIOD 346 349 * option. … … 398 401 return negative ? 0 : matched; 399 402 } 400 401 #undef _matched402 403 } 403 404 … … 416 417 static bool _partial_match(const char **pattern, const char **string, int flags) 417 418 { 418 /* Only a single *-delimited subpattern is matched here. 419 /* 420 * Only a single *-delimited subpattern is matched here. 419 421 * So in this function, '*' is understood as the end of pattern. 420 422 */ … … 473 475 474 476 if (*p == '\0') { 475 /* End of pattern, must match end of string or 477 /* 478 * End of pattern, must match end of string or 476 479 * an end of subdirectory name (optional). 477 480 */ … … 628 631 #include <stdio.h> 629 632 633 #define fnmatch_test(x) { if (x) printf("SUCCESS: "#x"\n"); else { printf("FAILED: "#x"\n"); fail++; } } 634 #define match(s1, s2, flags) fnmatch_test(fnmatch(s1, s2, flags) == 0) 635 #define nomatch(s1, s2, flags) fnmatch_test(fnmatch(s1, s2, flags) == FNM_NOMATCH) 636 630 637 void __posix_fnmatch_test() 631 638 { 632 639 int fail = 0; 633 640 634 #undef assert635 #define assert(x) { if (x) printf("SUCCESS: "#x"\n"); else { printf("FAILED: "#x"\n"); fail++; } }636 #define match(s1, s2, flags) assert(fnmatch(s1, s2, flags) == 0)637 #define nomatch(s1, s2, flags) assert(fnmatch(s1, s2, flags) == FNM_NOMATCH)638 641 639 642 static_assert(FNM_PATHNAME == FNM_FILE_NAME);
Note:
See TracChangeset
for help on using the changeset viewer.