1 /* 2 * CDDL HEADER START 3 * 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. 8 * 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. 13 * 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] 19 * 20 * CDDL HEADER END 21 */ 22 #ident "%Z%%M% %I% %E% SMI" 23 24 /* 25 * Copyright 1997 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 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> 34 35 int 36 resolvepath(char *path, char *buf, size_t count) 37 { 38 struct pathname lookpn; 39 struct pathname resolvepn; 40 int error; 41 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; 53 } 54 pn_free(&resolvepn); 55 pn_free(&lookpn); 56 57 if (error) 58 return (set_errno(error)); 59 return ((int)count); 60 } 61