1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM *
4*9781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM *
8*9781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM *
13*9781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM *
19*9781SMoriah.Waterland@Sun.COM * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM */
21*9781SMoriah.Waterland@Sun.COM
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
24*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM */
26*9781SMoriah.Waterland@Sun.COM
27*9781SMoriah.Waterland@Sun.COM
28*9781SMoriah.Waterland@Sun.COM
29*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
30*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
31*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
32*9781SMoriah.Waterland@Sun.COM #include <limits.h>
33*9781SMoriah.Waterland@Sun.COM #include <string.h>
34*9781SMoriah.Waterland@Sun.COM #include <errno.h>
35*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
36*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
37*9781SMoriah.Waterland@Sun.COM #include "libadm.h"
38*9781SMoriah.Waterland@Sun.COM
39*9781SMoriah.Waterland@Sun.COM #define ERR_CHDIR "unable to chdir back to <%s>, errno=%d"
40*9781SMoriah.Waterland@Sun.COM #define ERR_GETCWD "unable to determine the current working directory, " \
41*9781SMoriah.Waterland@Sun.COM "errno=%d"
42*9781SMoriah.Waterland@Sun.COM
43*9781SMoriah.Waterland@Sun.COM char *
flex_device(char * device_name,int dev_ok)44*9781SMoriah.Waterland@Sun.COM flex_device(char *device_name, int dev_ok)
45*9781SMoriah.Waterland@Sun.COM {
46*9781SMoriah.Waterland@Sun.COM char new_device_name[PATH_MAX];
47*9781SMoriah.Waterland@Sun.COM char *np = device_name;
48*9781SMoriah.Waterland@Sun.COM char *cwd = NULL;
49*9781SMoriah.Waterland@Sun.COM
50*9781SMoriah.Waterland@Sun.COM if (!device_name || !*device_name) /* NULL or empty */
51*9781SMoriah.Waterland@Sun.COM return (np);
52*9781SMoriah.Waterland@Sun.COM
53*9781SMoriah.Waterland@Sun.COM if (dev_ok == 1 && listdev(np) != (char **) NULL) /* device.tab */
54*9781SMoriah.Waterland@Sun.COM return (np);
55*9781SMoriah.Waterland@Sun.COM
56*9781SMoriah.Waterland@Sun.COM if (!strncmp(np, "/dev", 4)) /* /dev path */
57*9781SMoriah.Waterland@Sun.COM return (np);
58*9781SMoriah.Waterland@Sun.COM
59*9781SMoriah.Waterland@Sun.COM if ((cwd = getcwd(NULL, PATH_MAX)) == NULL) {
60*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_GETCWD), errno);
61*9781SMoriah.Waterland@Sun.COM exit(99);
62*9781SMoriah.Waterland@Sun.COM }
63*9781SMoriah.Waterland@Sun.COM
64*9781SMoriah.Waterland@Sun.COM if (realpath(np, new_device_name) == NULL) { /* path */
65*9781SMoriah.Waterland@Sun.COM if (chdir(cwd) == -1) {
66*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_CHDIR), cwd, errno);
67*9781SMoriah.Waterland@Sun.COM (void) free(cwd);
68*9781SMoriah.Waterland@Sun.COM exit(99);
69*9781SMoriah.Waterland@Sun.COM }
70*9781SMoriah.Waterland@Sun.COM if (*np != '/' && dev_ok == 2) {
71*9781SMoriah.Waterland@Sun.COM (void) sprintf(new_device_name, "%s/%s", cwd, np);
72*9781SMoriah.Waterland@Sun.COM canonize(new_device_name);
73*9781SMoriah.Waterland@Sun.COM if ((np = strdup(new_device_name)) == NULL)
74*9781SMoriah.Waterland@Sun.COM np = device_name;
75*9781SMoriah.Waterland@Sun.COM }
76*9781SMoriah.Waterland@Sun.COM (void) free(cwd);
77*9781SMoriah.Waterland@Sun.COM return (np);
78*9781SMoriah.Waterland@Sun.COM }
79*9781SMoriah.Waterland@Sun.COM
80*9781SMoriah.Waterland@Sun.COM if (strcmp(np, new_device_name)) {
81*9781SMoriah.Waterland@Sun.COM if ((np = strdup(new_device_name)) == NULL)
82*9781SMoriah.Waterland@Sun.COM np = device_name;
83*9781SMoriah.Waterland@Sun.COM }
84*9781SMoriah.Waterland@Sun.COM
85*9781SMoriah.Waterland@Sun.COM (void) free(cwd);
86*9781SMoriah.Waterland@Sun.COM return (np);
87*9781SMoriah.Waterland@Sun.COM }
88