1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A * in-place path name canonicalization -- preserves the logical view 1N/A * pointer to trailing 0 in path returned 1N/A * remove redundant .'s and /'s 1N/A * move ..'s to the front 1N/A * /.. preserved (for pdu and newcastle hacks) 1N/A * if (flags&PATH_PHYSICAL) then symlinks resolved at each component 1N/A * if (flags&PATH_DOTDOT) then each .. checked for access 1N/A * if (flags&PATH_EXISTS) then path must exist at each component 1N/A * if (flags&PATH_VERIFIED(n)) then first n chars of path exist 1N/A * longer pathname possible if (flags&PATH_PHYSICAL) or FS_3D ... involved 1N/A * 0 returned on error and if (flags&(PATH_DOTDOT|PATH_EXISTS)) then path 1N/A * will contain the components following the failure point 1N/A switch (*t++ = *s++)
1N/A while (*s ==
'/') s++;
1N/A if (t -
5 < r) r = t;
1N/A if (t -
4 == r) t = r +
1;
1N/A else for (t -=
5; t > r && *(t -
1) !=
'/'; t--);
1N/A if (t == r +
1) x = r;
1N/A if (*s) *(t -
1) =
'/';
1N/A else if (t >
path +
1 && *(t -
1) ==
'/') t--;
1N/A else if ((s <=
path || *(s -
1) !=
'/') && t >
path +
1 && *(t -
1) ==
'/') t--;