Changeset 904b1bc in mainline for uspace/lib/posix/src/fnmatch.c


Ignore:
Timestamp:
2018-05-22T10:36:58Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
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)
Message:

Fix remaining ccheck issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/src/fnmatch.c

    r4f8772d4 r904b1bc  
    3333 */
    3434
    35 /* This file contains an implementation of the fnmatch() pattern matching
     35/*
     36 * This file contains an implementation of the fnmatch() pattern matching
    3637 * function. There is more code than necessary to account for the possibility
    3738 * of adding POSIX-like locale support to the system in the future. Functions
     
    5455#define INVALID_PATTERN -1
    5556
    56 /* Type for collating element, simple identity with characters now,
     57/*
     58 * Type for collating element, simple identity with characters now,
    5759 * but may be extended for better locale support.
    5860 */
     
    7072 * @return Matching collating element or COLL_ELM_INVALID.
    7173 */
    72 static coll_elm_t _coll_elm_get(const char* str)
     74static coll_elm_t _coll_elm_get(const char *str)
    7375{
    7476        if (str[0] == '\0' || str[1] != '\0') {
     
    306308}
    307309
    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) { \
    329311                int _match = match; \
    330312                if (_match < 0) { \
     
    337319        }
    338320
     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 */
     333static 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
    339341        assert(*p == '[');  /* calling code should ensure this */
    340342        p++;
     
    342344        if (*str == '\0' || (pathname && *str == '/') ||
    343345            (pathname && special_period && *str == '.' && *(str - 1) == '/')) {
    344                 /* No bracket expression matches end of string,
     346                /*
     347                 * No bracket expression matches end of string,
    345348                 * slash in pathname match or initial period with FNM_PERIOD
    346349                 * option.
     
    398401                return negative ? 0 : matched;
    399402        }
    400 
    401         #undef _matched
    402403}
    403404
     
    416417static bool _partial_match(const char **pattern, const char **string, int flags)
    417418{
    418         /* Only a single *-delimited subpattern is matched here.
     419        /*
     420         * Only a single *-delimited subpattern is matched here.
    419421         * So in this function, '*' is understood as the end of pattern.
    420422         */
     
    473475
    474476                if (*p == '\0') {
    475                         /* End of pattern, must match end of string or
     477                        /*
     478                         * End of pattern, must match end of string or
    476479                         * an end of subdirectory name (optional).
    477480                         */
     
    628631#include <stdio.h>
    629632
     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
    630637void __posix_fnmatch_test()
    631638{
    632639        int fail = 0;
    633640
    634         #undef assert
    635         #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)
    638641
    639642        static_assert(FNM_PATHNAME == FNM_FILE_NAME);
Note: See TracChangeset for help on using the changeset viewer.