removef.c revision 9781:ccf49524d5dc
1132718Skan/*
2132718Skan * CDDL HEADER START
3132718Skan *
4132718Skan * The contents of this file are subject to the terms of the
5132718Skan * Common Development and Distribution License (the "License").
6132718Skan * You may not use this file except in compliance with the License.
7132718Skan *
8132718Skan * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9132718Skan * or http://www.opensolaris.org/os/licensing.
10132718Skan * See the License for the specific language governing permissions
11132718Skan * and limitations under the License.
12132718Skan *
13132718Skan * When distributing Covered Code, include this CDDL HEADER in each
14132718Skan * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15132718Skan * If applicable, add the following below this CDDL HEADER, with the
16132718Skan * fields enclosed by brackets "[]" replaced with your own identifying
17132718Skan * information: Portions Copyright [yyyy] [name of copyright owner]
18132718Skan *
19132718Skan * CDDL HEADER END
20132718Skan */
21132718Skan
22132718Skan/*
23132718Skan * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24132718Skan * Use is subject to license terms.
25132718Skan */
26132718Skan
27161651Skan/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28161651Skan/* All Rights Reserved */
29161651Skan
30161651Skan#include <stdio.h>
31161651Skan#include <errno.h>
32161651Skan#include <string.h>
33161651Skan#include <limits.h>
34132718Skan#include <stdlib.h>
35161651Skan#include <unistd.h>
36161651Skan#include <sys/types.h>
37161651Skan#include <locale.h>
38161651Skan#include <libintl.h>
39161651Skan#include <pkglib.h>
40132718Skan#include <install.h>
41132718Skan#include <libinst.h>
42132718Skan#include <libadm.h>
43132718Skan#include "installf.h"
44132718Skan
45132718Skanvoid
46132718Skanremovef(int argc, char *argv[])
47132718Skan{
48	struct cfextra *new;
49	char	buf[PATH_MAX];
50	char	*path;
51	int	flag;
52	int	len;
53	int	max_eptnum;
54
55	flag = strcmp(argv[0], "-") == 0;
56
57	eptnum = 0;
58	max_eptnum = 64;	/* starting size of array */
59	extlist = malloc(max_eptnum * sizeof (struct cfextra *));
60
61	for (;;) {
62		if (flag) {
63			if (fgets(buf, PATH_MAX, stdin) == NULL)
64				break;
65
66			/* strip trailing new line */
67			len = strlen(buf);
68			if (buf[len - 1] == '\n')
69				buf[len - 1] = '\0';
70
71			path = buf;
72		} else {
73			if (argc-- <= 0)
74				break;
75			path = argv[argc];
76		}
77
78		/*
79		 * This strips the install root from the path using
80		 * a questionable algorithm. This should go away as
81		 * we define more precisely the command line syntax
82		 * with our '-R' option. - JST
83		 */
84		path = orig_path_ptr(path);
85
86		if (path == NULL) {
87			logerr(gettext("ERROR: no pathname was provided"));
88			warnflag++;
89			continue;
90		}
91
92		if (*path != '/') {
93			logerr(gettext(
94			    "WARNING: relative pathname <%s> ignored"), path);
95			warnflag++;
96			continue;
97		}
98
99		new = calloc(1, sizeof (struct cfextra));
100		if (new == NULL) {
101			progerr(strerror(errno));
102			quit(99);
103		}
104		new->cf_ent.ftype = '-';
105
106		(void) eval_path(&(new->server_path), &(new->client_path),
107		    &(new->map_path), path);
108
109		new->cf_ent.path = new->client_path;
110
111		extlist[eptnum++] = new;
112		if (eptnum >= max_eptnum) {
113			/* array size grows exponentially */
114			max_eptnum <<= 1;
115			extlist = realloc(extlist,
116			    max_eptnum * sizeof (struct cfextra *));
117			if (extlist == NULL) {
118				progerr(strerror(errno));
119				quit(99);
120			}
121		}
122	}
123	extlist[eptnum] = (struct cfextra *)NULL;
124
125	qsort((char *)extlist,
126	    (unsigned)eptnum, sizeof (struct cfextra *), cfentcmp);
127}
128