Merge commit '7e3488dc6cdcb0c04e1ce167a1a3bfef83b5f2e0'
[unleashed.git] / kernel / syscall / resolvepath.c
blobe6cb678761772ce97b2c22acf348123ac82ad878
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 #ident "%Z%%M% %I% %E% SMI"
25 * Copyright 1997 by Sun Microsystems, Inc.
26 * All rights reserved.
29 #include <sys/param.h>
30 #include <sys/types.h>
31 #include <sys/systm.h>
32 #include <sys/errno.h>
33 #include <sys/pathname.h>
35 int
36 resolvepath(char *path, char *buf, size_t count)
38 struct pathname lookpn;
39 struct pathname resolvepn;
40 int error;
42 if (count == 0)
43 return (0);
44 if (error = pn_get(path, UIO_USERSPACE, &lookpn))
45 return (set_errno(error));
46 pn_alloc(&resolvepn);
47 error = lookuppn(&lookpn, &resolvepn, FOLLOW, NULL, NULL);
48 if (error == 0) {
49 if (count > resolvepn.pn_pathlen)
50 count = resolvepn.pn_pathlen;
51 if (copyout(resolvepn.pn_path, buf, count))
52 error = EFAULT;
54 pn_free(&resolvepn);
55 pn_free(&lookpn);
57 if (error)
58 return (set_errno(error));
59 return ((int)count);