* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $";
+static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
realpath(const char *path, char *resolved)
{
struct stat sb;
- int fd, n, needslash, serrno = 0;
+ int fd, n, rootd, serrno = 0;
char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN];
int symlinks = 0;
/* Save the starting point. */
getcwd(start,MAXPATHLEN);
if ((fd = open(".", O_RDONLY)) < 0) {
- (void)strlcpy(resolved, ".", MAXPATHLEN);
+ (void)strcpy(resolved, ".");
return (NULL);
}
close(fd);
- /* Convert "." -> "" to optimize away a needless lstat() and chdir() */
- if (path[0] == '.' && path[1] == '\0')
- path = "";
-
/*
* Find the dirname and basename from the path to be resolved.
* Change directory to the dirname component.
p = resolved;
/* Deal with the last component. */
- if (*p != '\0' && lstat(p, &sb) == 0) {
+ if (lstat(p, &sb) == 0) {
if (S_ISLNK(sb.st_mode)) {
if (++symlinks > MAXSYMLINKS) {
serrno = ELOOP;
* Save the last component name and get the full pathname of
* the current directory.
*/
- (void)strlcpy(wbuf, p, sizeof wbuf);
+ (void)strcpy(wbuf, p);
if (getcwd(resolved, MAXPATHLEN) == 0)
goto err1;
* happens if the last component is empty, or the dirname is root.
*/
if (resolved[0] == '/' && resolved[1] == '\0')
- needslash = 0;
+ rootd = 1;
else
- needslash = 1;
+ rootd = 0;
if (*wbuf) {
- if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) {
+ if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) {
serrno = ENAMETOOLONG;
goto err1;
}
- if (needslash == 0)
- strlcat(resolved, "/", MAXPATHLEN);
- strlcat(resolved, wbuf, MAXPATHLEN);
+ if (rootd == 0)
+ (void)strcat(resolved, "/");
+ (void)strcat(resolved, wbuf);
}
/* Go back to where we came from. */