Cwd.xs revision 1
1N/A/* The realpath() implementation from OpenBSD 2.9 (realpath.c 1.4) 1N/A * Renamed here to bsd_realpath() to avoid library conflicts. 1N/A * --jhi 2000-06-20 */ 1N/A * Copyright (c) 1994 1N/A * The Regents of the University of California. All rights reserved. 1N/A * This code is derived from software contributed to Berkeley by 1N/A * Redistribution and use in source and binary forms, with or without 1N/A * modification, are permitted provided that the following conditions 1N/A * 1. Redistributions of source code must retain the above copyright 1N/A * notice, this list of conditions and the following disclaimer. 1N/A * 2. Redistributions in binary form must reproduce the above copyright 1N/A * notice, this list of conditions and the following disclaimer in the 1N/A * documentation and/or other materials provided with the distribution. 1N/A * 3. All advertising materials mentioning features or use of this software 1N/A * must display the following acknowledgement: 1N/A * This product includes software developed by the University of 1N/A * California, Berkeley and its contributors. 1N/A * 4. Neither the name of the University nor the names of its contributors 1N/A * may be used to endorse or promote products derived from this software 1N/A * without specific prior written permission. 1N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1N/A#
endif /* LIBC_SCCS and not lint */ 1N/A/* OpenBSD system #includes removed since the Perl ones should do. --jhi */ 1N/A * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); 1N/A * Find the real name of path, by removing all ".", ".." and symlink 1N/A * components. Returns (resolved) on success, or (NULL) on failure, 1N/A * in which case the path which caused trouble is left in (resolved). 1N/A /* Save the starting point. */ 1N/A * Find the dirname and basename from the path to be resolved. 1N/A * Change directory to the dirname component. 1N/A * lstat the basename part. 1N/A * if it is a symlink, read in the value and loop. 1N/A * if it is a directory, then change to that directory. 1N/A * get the current directory name and append the basename. 1N/A /* Deal with the last component. */ 1N/A * Save the last component name and get the full pathname of 1N/A * the current directory. 1N/A * Join the two strings together, ensuring that the right thing 1N/A * happens if the last component is empty, or the dirname is root. 1N/A /* Go back to where we came from. */ 1N/A /* It's okay if the close fails, what's an fd more or less? */ 1N/A /* Some getcwd()s automatically allocate a buffer of the given 1N/A * size from the heap if they are given a NULL buffer pointer. 1N/A * The problem is that this behaviour is not portable. */ 1N/A /* prepend current directory to the front */ 1N/A "current directory changed unexpectedly");