static int fnmatch_normalize(const char *pattern, const char *string, int flags) {
    int i, j, r;
    char *pattern_norm = NULL;

    r = ALLOC_N(pattern_norm, strlen(pattern) + 1);
    if (r < 0)
        goto error;

    for (i = 0, j = 0; i < strlen(pattern); i++) {
        if (pattern[i] != '/' || pattern[i+1] != '/') {
            pattern_norm[j] = pattern[i];
            j++;
        }
    }
    pattern_norm[j] = 0;

    r = fnmatch(pattern_norm, string, flags);
    FREE(pattern_norm);
    return r;

 error:
    if (pattern_norm != NULL)
        FREE(pattern_norm);
    return -1;
}
static int fnmatch_normalize(const char *pattern, const char *string, int flags) {
    int i, j, r;
    char *pattern_norm = NULL;

    r = ALLOC_N(pattern_norm, strlen(pattern) + 1);
    if (r < 0)
        goto error;

    for (i = 0, j = 0; i < strlen(pattern); i++) {
        if (pattern[i] != '/' || pattern[i+1] != '/') {
            pattern_norm[j] = pattern[i];
            j++;
        }
    }
    pattern_norm[j] = 0;

    r = fnmatch(pattern_norm, string, flags);
    FREE(pattern_norm);
    return r;

 error:
    if (pattern_norm != NULL)
        FREE(pattern_norm);
    return -1;
}