static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader,
                                        const char *uri,
                                        const UI_METHOD *ui_method,
                                        void *ui_data)
{
    OSSL_STORE_LOADER_CTX *ctx = NULL;
    struct stat st;
    struct {
        const char *path;
        unsigned int check_absolute:1;
    } path_data[2];
    size_t path_data_n = 0, i;
    const char *path;
    path_data[path_data_n].check_absolute = 0;
    path_data[path_data_n++].path = uri;
    if (strncasecmp(uri, "file:", 5) == 0) {
        const char *p = &uri[5];
        if (strncmp(&uri[5], "//", 2) == 0) {
            path_data_n--;
            if (strncasecmp(&uri[7], "localhost/", 10) == 0) {
                p = &uri[16];
            } else if (uri[7] == '/') {
                p = &uri[7];
            } else {
                OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN,
                              OSSL_STORE_R_URI_AUTHORITY_UNSUPPORTED);
                return NULL;
            }
        }
        path_data[path_data_n].check_absolute = 1;
#ifdef _WIN32
        if (p[0] == '/' && p[2] == ':' && p[3] == '/') {
            char c = tolower(p[1]);
            if (c >= 'a' && c <= 'z') {
                p++;
                path_data[path_data_n].check_absolute = 0;
            }
        }
#endif
        path_data[path_data_n++].path = p;
    }
    for (i = 0, path = NULL; path == NULL && i < path_data_n; i++) {
        if (path_data[i].check_absolute && path_data[i].path[0] != '/') {
            OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN,
                          OSSL_STORE_R_PATH_MUST_BE_ABSOLUTE);
            ERR_add_error_data(1, path_data[i].path);
            return NULL;
        }
        if (stat(path_data[i].path, &st) < 0) {
            SYSerr(SYS_F_STAT, errno);
            ERR_add_error_data(1, path_data[i].path);
        } else {
            path = path_data[i].path;
        }
    }
    if (path == NULL) {
        return NULL;
    }
    ERR_clear_error();
    ctx = OPENSSL_zalloc(sizeof(*ctx));
    if (ctx == NULL) {
        OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    if ((st.st_mode & S_IFDIR) == S_IFDIR) {
        ctx->_.dir.uri = OPENSSL_strdup(uri);
        ctx->type = is_dir;
        if (ctx->_.dir.uri == NULL)
            goto err;
        ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, path);
        ctx->_.dir.last_errno = errno;
        if (ctx->_.dir.last_entry == NULL) {
            if (ctx->_.dir.last_errno != 0) {
                char errbuf[256];
                errno = ctx->_.dir.last_errno;
                openssl_strerror_r(errno, errbuf, sizeof(errbuf));
                OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN, ERR_R_SYS_LIB);
                ERR_add_error_data(1, errbuf);
                goto err;
            }
            ctx->_.dir.end_reached = 1;
        }
    } else {
        BIO *buff = NULL;
        char peekbuf[4096];
        if ((buff = BIO_new(BIO_f_buffer())) == NULL
            || (ctx->_.file.file = BIO_new_file(path, "rb")) == NULL) {
            BIO_free_all(buff);
            goto err;
        }
        ctx->_.file.file = BIO_push(buff, ctx->_.file.file);
        if (BIO_buffer_peek(ctx->_.file.file, peekbuf, sizeof(peekbuf)-1) > 0) {
            peekbuf[sizeof(peekbuf)-1] = '\0';
            if (strstr(peekbuf, "-----BEGIN ") != NULL)
                ctx->type = is_pem;
        }
    }
    return ctx;
 err:
    OSSL_STORE_LOADER_CTX_free(ctx);
    return NULL;
}
['static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader,\n                                        const char *uri,\n                                        const UI_METHOD *ui_method,\n                                        void *ui_data)\n{\n    OSSL_STORE_LOADER_CTX *ctx = NULL;\n    struct stat st;\n    struct {\n        const char *path;\n        unsigned int check_absolute:1;\n    } path_data[2];\n    size_t path_data_n = 0, i;\n    const char *path;\n    path_data[path_data_n].check_absolute = 0;\n    path_data[path_data_n++].path = uri;\n    if (strncasecmp(uri, "file:", 5) == 0) {\n        const char *p = &uri[5];\n        if (strncmp(&uri[5], "//", 2) == 0) {\n            path_data_n--;\n            if (strncasecmp(&uri[7], "localhost/", 10) == 0) {\n                p = &uri[16];\n            } else if (uri[7] == \'/\') {\n                p = &uri[7];\n            } else {\n                OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN,\n                              OSSL_STORE_R_URI_AUTHORITY_UNSUPPORTED);\n                return NULL;\n            }\n        }\n        path_data[path_data_n].check_absolute = 1;\n#ifdef _WIN32\n        if (p[0] == \'/\' && p[2] == \':\' && p[3] == \'/\') {\n            char c = tolower(p[1]);\n            if (c >= \'a\' && c <= \'z\') {\n                p++;\n                path_data[path_data_n].check_absolute = 0;\n            }\n        }\n#endif\n        path_data[path_data_n++].path = p;\n    }\n    for (i = 0, path = NULL; path == NULL && i < path_data_n; i++) {\n        if (path_data[i].check_absolute && path_data[i].path[0] != \'/\') {\n            OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN,\n                          OSSL_STORE_R_PATH_MUST_BE_ABSOLUTE);\n            ERR_add_error_data(1, path_data[i].path);\n            return NULL;\n        }\n        if (stat(path_data[i].path, &st) < 0) {\n            SYSerr(SYS_F_STAT, errno);\n            ERR_add_error_data(1, path_data[i].path);\n        } else {\n            path = path_data[i].path;\n        }\n    }\n    if (path == NULL) {\n        return NULL;\n    }\n    ERR_clear_error();\n    ctx = OPENSSL_zalloc(sizeof(*ctx));\n    if (ctx == NULL) {\n        OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    if ((st.st_mode & S_IFDIR) == S_IFDIR) {\n        ctx->_.dir.uri = OPENSSL_strdup(uri);\n        ctx->type = is_dir;\n        if (ctx->_.dir.uri == NULL)\n            goto err;\n        ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, path);\n        ctx->_.dir.last_errno = errno;\n        if (ctx->_.dir.last_entry == NULL) {\n            if (ctx->_.dir.last_errno != 0) {\n                char errbuf[256];\n                errno = ctx->_.dir.last_errno;\n                openssl_strerror_r(errno, errbuf, sizeof(errbuf));\n                OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN, ERR_R_SYS_LIB);\n                ERR_add_error_data(1, errbuf);\n                goto err;\n            }\n            ctx->_.dir.end_reached = 1;\n        }\n    } else {\n        BIO *buff = NULL;\n        char peekbuf[4096];\n        if ((buff = BIO_new(BIO_f_buffer())) == NULL\n            || (ctx->_.file.file = BIO_new_file(path, "rb")) == NULL) {\n            BIO_free_all(buff);\n            goto err;\n        }\n        ctx->_.file.file = BIO_push(buff, ctx->_.file.file);\n        if (BIO_buffer_peek(ctx->_.file.file, peekbuf, sizeof(peekbuf)-1) > 0) {\n            peekbuf[sizeof(peekbuf)-1] = \'\\0\';\n            if (strstr(peekbuf, "-----BEGIN ") != NULL)\n                ctx->type = is_pem;\n        }\n    }\n    return ctx;\n err:\n    OSSL_STORE_LOADER_CTX_free(ctx);\n    return NULL;\n}']