pipe_fopen(gx_io_device * iodev, const char *fname, const char *access,
           gp_file ** pfile, char *rfname, uint rnamelen, gs_memory_t *mem)
{
#ifdef GS_NO_FILESYSTEM
    return 0;
#else
    gs_lib_ctx_t *ctx = mem->gs_lib_ctx;
    gs_fs_list_t *fs = ctx->core->fs;
    /* The pipe device can be reached in two ways, explicltly with %pipe%
       or implicitly with "|", so we have to check for both
     */
    char f[gp_file_name_sizeof];
    const char *pipestr = "|";
    const size_t pipestrlen = strlen(pipestr);
    const size_t preflen = strlen(iodev->dname);
    const size_t nlen = strlen(fname);
    int code1;

    if (preflen + nlen >= gp_file_name_sizeof)
        return_error(gs_error_invalidaccess);

    memcpy(f, iodev->dname, preflen);
    memcpy(f + preflen, fname, nlen + 1);

    code1 = gp_validate_path(mem, f, access);

    memcpy(f, pipestr, pipestrlen);
    memcpy(f + pipestrlen, fname, nlen + 1);

    if (code1 != 0 && gp_validate_path(mem, f, access) != 0 )
        return gs_error_invalidfileaccess;

    /*
     * Some platforms allow opening a pipe with a '+' in the access
     * mode, even though pipes are not positionable.  Detect this here.
     */
    if (strchr(access, '+'))
        return_error(gs_error_invalidfileaccess);

    *pfile = NULL;
    for (fs = ctx->core->fs; fs != NULL; fs = fs->next)
    {
        int code = 0;
        if (fs->fs.open_pipe)
            code = fs->fs.open_pipe(mem, fs->secret, fname, rfname, access, pfile);
        if (code < 0)
            return code;
        if (*pfile != NULL)
            break;
    }

    return 0;
#endif
}
pipe_fopen(gx_io_device * iodev, const char *fname, const char *access,
           gp_file ** pfile, char *rfname, uint rnamelen, gs_memory_t *mem)
{
#ifdef GS_NO_FILESYSTEM
    return 0;
#else
    gs_lib_ctx_t *ctx = mem->gs_lib_ctx;
    gs_fs_list_t *fs = ctx->core->fs;
     
    char f[gp_file_name_sizeof];
    const char *pipestr = "|";
    const size_t pipestrlen = strlen(pipestr);
    const size_t preflen = strlen(iodev->dname);
    const size_t nlen = strlen(fname);
    int code1;

    if (preflen + nlen >= gp_file_name_sizeof)
        return_error(gs_error_invalidaccess);

    memcpy(f, iodev->dname, preflen);
    memcpy(f + preflen, fname, nlen + 1);

    code1 = gp_validate_path(mem, f, access);

    memcpy(f, pipestr, pipestrlen);
    memcpy(f + pipestrlen, fname, nlen + 1);

    if (code1 != 0 && gp_validate_path(mem, f, access) != 0 )
        return gs_error_invalidfileaccess;

     
    if (strchr(access, '+'))
        return_error(gs_error_invalidfileaccess);

    *pfile = NULL;
    for (fs = ctx->core->fs; fs != NULL; fs = fs->next)
    {
        int code = 0;
        if (fs->fs.open_pipe)
            code = fs->fs.open_pipe(mem, fs->secret, fname, rfname, access, pfile);
        if (code < 0)
            return code;
        if (*pfile != NULL)
            break;
    }

    return 0;
#endif
}