realpath.c revision 24da5b34f49324ed742a340010ed5bd3d4e06625
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <errno.h>
/*
* Resolve all links for the given "name" and returns the result
* in "actual". Returns pointer to the result if successful, else
* NULL and errno is set. "actual" contains the path name of the
* fault point.
*/
static char *
register char *name;
char *actual;
{ int last_is_slash = 0;
register char *p = actual;
char namebuf[MAXPATHLEN];
return (actual);
if (name[0] == '/') {
actual[0] = '/';
return (actual);
++p;
}
/*
* "tmpname" points to the yet unresolved path name.
* "actual" points to the resolved path name so far.
*/
while (tmpname) {
register char *start; /* The new step */
/* start points to the new step */
return (NULL);
}
char buf[MAXPATHLEN];
int count;
return (NULL);
} else {
char tmpdir[MAXPATHLEN];
char tmpbuf[MAXPATHLEN];
char *resolved_res;
/*
* Recursively check for all new links.
*/
return (NULL);
return (NULL);
if (tmpbuf[0] == '/')
/* The link starts from root */
for (p = &actual[0];
else
if (resolved_res == NULL) {
return (NULL);
}
return (NULL);
}
} else
/* Append start to actual */
if (*(p - sizeof (char)) != '/')
*p++ = '/'; /* Append '/' to actual */
*p = NULL;
}
if (last_is_slash == 0) {
*--p = NULL;
} else if (*(p - sizeof (char)) != '/')
*p++ = '/';
*p = NULL;
return (actual);
}
/*
* Given a path, it removes all the '.' and '..' in it and returns
* pointer to the result if successful, else returns NULL and the
* error number is set. The partially prepared result is in "dots".
*/
static char *
register char *actual;
register char *dots; /* The result */
{
int last_is_slash = 0;
char pwd[MAXPATHLEN];
char *endp;
return (NULL);
}
return (dots);
return (NULL);
return (NULL);
}
char dir[MAXPATHLEN];
return (NULL);
}
if ((actual[0] != '/') &&
/* Copy only the relative part of the name */
else
} else {
/*
* Last component is a file. Find the resolved
* name of the parent of this file, and then append
* the name of this file.
*/
char *pdir;
else {
char partial_dir[MAXPATHLEN];
return (NULL);
}
if ((actual[0] != '/') &&
else
(char *) (&partial_dir[0] +
} else
*--pdir = '/';
}
}
return (NULL);
if (last_is_slash == 0) {
} else if (*(endp - sizeof (char)) != '/') {
*endp++ = '/';
}
return (dots);
}
/*
* Given a path, it resolves all links, '.' and '..' in it and
* returns pointer to the result if successful, else returns NULL and
* error number is set. The partially prepared result is in "linkdots".
* Assumes that "linkdots" has enough space allocated to it.
*/
char *
{
char buf[MAXPATHLEN];
return (NULL);
}
}