/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Bell Laboratories25*26* return path to file a/b with access mode using : separated dirs27* both a and b may be 028* if a==".." then relative paths in dirs are ignored29* if (mode&PATH_REGULAR) then path must not be a directory30* if (mode&PATH_ABSOLUTE) then path must be rooted31* path returned in path buffer32*/3334#define _AST_API_H 13536#include <ast.h>3738char*39pathaccess(char* path, const char* dirs, const char* a, const char* b, int mode)40{41return pathaccess_20100601(dirs, a, b, mode, path, PATH_MAX);42}4344#undef _AST_API_H4546#include <ast_api.h>4748char*49pathaccess_20100601(register const char* dirs, const char* a, const char* b, register int mode, register char* path, size_t size)50{51int sib = a && a[0] == '.' && a[1] == '.' && a[2] == 0;52int sep = ':';53char cwd[PATH_MAX];5455do56{57dirs = pathcat(dirs, sep, a, b, path, size);58pathcanon(path, size, 0);59if ((!sib || *path == '/') && pathexists(path, mode))60{61if (*path == '/' || !(mode & PATH_ABSOLUTE))62return path;63dirs = getcwd(cwd, sizeof(cwd));64sep = 0;65}66} while (dirs);67return 0;68}697071