Esempio n. 1
0
static int do_open_via_path(const char *dir, const char *name,
    const char *ext, char *dirresult, char **nameresult, unsigned int size,
    int bin, t_namelist *searchpath)
{
    t_namelist *nl;
    int fd = -1;

        /* first check if "name" is absolute (and if so, try to open) */
    if (sys_open_absolute(name, ext, dirresult, nameresult, size, bin, &fd))
        return (fd);
    
        /* otherwise "name" is relative; try the directory "dir" first. */
    if ((fd = sys_trytoopenone(dir, name, ext,
        dirresult, nameresult, size, bin)) >= 0)
            return (fd);

        /* next go through the search path */
    for (nl = searchpath; nl; nl = nl->nl_next)
        if ((fd = sys_trytoopenone(nl->nl_string, name, ext,
            dirresult, nameresult, size, bin)) >= 0)
                return (fd);

        /* next look in built-in paths like "extra" */
    if (sys_usestdpath)
        for (nl = sys_staticpath; nl; nl = nl->nl_next)
            if ((fd = sys_trytoopenone(nl->nl_string, name, ext,
                dirresult, nameresult, size, bin)) >= 0)
                    return (fd);

    *dirresult = 0;
    *nameresult = dirresult;
    return (-1);
}
Esempio n. 2
0
static int do_open_via_path(const char *dir, const char *name,
    const char *ext, char *dirresult, char **nameresult, unsigned int size,
    int bin, t_namelist *searchpath)
{
    t_namelist *nl;
    int fd = -1;
	char final_name[FILENAME_MAX];

		/* first check for @ and ~ (and later others) and replace */
	sys_expandpathelems(name, final_name);	

        /* first check if "name" is absolute (and if so, try to open) */
    if (sys_open_absolute(final_name, ext, dirresult, nameresult, size, bin, &fd))
        goto do_open_via_path_end;
    
        /* otherwise "name" is relative; try the directory "dir" first. */
    if ((fd = sys_trytoopenone(dir, final_name, ext,
        dirresult, nameresult, size, bin)) >= 0)
            goto do_open_via_path_end;

        /* next go through the search path */
    for (nl = searchpath; nl; nl = nl->nl_next)
        if ((fd = sys_trytoopenone(nl->nl_string, final_name, ext,
            dirresult, nameresult, size, bin)) >= 0)
				goto do_open_via_path_end;

        /* next look in built-in paths like "extra" */
    if (sys_usestdpath)
        for (nl = pd_extrapath; nl; nl = nl->nl_next)
            if ((fd = sys_trytoopenone(nl->nl_string, final_name, ext,
                dirresult, nameresult, size, bin)) >= 0)
                    goto do_open_via_path_end;

    *dirresult = 0;
    *nameresult = dirresult;
    return (-1);
do_open_via_path_end:
	return (fd);
}