#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pkgstrct.h>
#include <locale.h>
#include <libintl.h>
#include <pkglib.h>
#include <libadm.h>
#include <libinst.h>
extern int dbchg, warnflag, otherstoo;
extern char *pkginst;
#define EPTMALLOC 128
#define ERR_WRENT "write of entry failed, errno=%d"
#define ERR_MEMORY "no memory, errno=%d"
#define ERR_READ_C "bad read of contents file"
#define ERR_READ_DB "bad read of the database"
extern struct cfent **eptlist;
extern int eptnum;
int
delmap(int flag, char *pkginst, PKGserver *pkgserver, VFP_T **tmpfp)
{
struct cfent *ept;
struct pinfo *pinfo;
int n;
char *unknown = "Unknown";
if (!ocfile(pkgserver, tmpfp, 0L) ||
pkgopenfilter(*pkgserver, pkginst) != 0) {
quit(99);
}
(void) pathdup(NULL);
if (eptlist != NULL)
free(eptlist);
eptlist = (struct cfent **)calloc(EPTMALLOC,
sizeof (struct cfent *));
if (eptlist == NULL) {
progerr(gettext(ERR_MEMORY), errno);
quit(99);
}
ept = (struct cfent *)calloc(1,
(unsigned)sizeof (struct cfent));
if (!ept) {
progerr(gettext(ERR_MEMORY), errno);
quit(99);
}
eptnum = 0;
while (n = srchcfile(ept, "*", *pkgserver)) {
if (n < 0) {
char *errstr = getErrstr();
progerr(gettext("bad read of contents file"));
progerr(gettext("pathname=%s"),
(ept->path && *ept->path) ? ept->path :
unknown);
progerr(gettext("problem=%s"),
(errstr && *errstr) ? errstr : unknown);
exit(99);
}
pinfo = eptstat(ept, pkginst, (flag ? '@' : '-'));
if (ept->npkgs > 0) {
if (putcvfpfile(ept, *tmpfp)) {
progerr(gettext(ERR_WRENT), errno);
quit(99);
}
} else if (ept->path != NULL) {
(void) vfpSetModified(*tmpfp);
vfpPutc(*tmpfp, '-');
vfpPuts(*tmpfp, ept->path);
vfpPutc(*tmpfp, '\n');
}
if (flag || (pinfo == NULL))
continue;
dbchg++;
if (!pinfo->editflag && otherstoo)
ept->ftype = (ept->ftype == 'e') ? '^' : '\0';
if (*pinfo->aclass)
(void) strcpy(ept->pkg_class, pinfo->aclass);
eptlist[eptnum] = ept;
ept->path = pathdup(ept->path);
if (ept->ainfo.local != NULL)
ept->ainfo.local = pathdup(ept->ainfo.local);
ept = (struct cfent *)calloc(1, sizeof (struct cfent));
if ((++eptnum % EPTMALLOC) == 0) {
eptlist = (struct cfent **)realloc(eptlist,
(eptnum+EPTMALLOC)*sizeof (struct cfent *));
if (eptlist == NULL) {
progerr(gettext(ERR_MEMORY), errno);
quit(99);
}
}
}
eptlist[eptnum] = (struct cfent *)NULL;
n = swapcfile(*pkgserver, tmpfp, pkginst, dbchg);
if (n == RESULT_WRN) {
warnflag++;
} else if (n == RESULT_ERR) {
quit(99);
}
return (0);
}