1 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
2 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
3 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
4 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
5 /*%% $TOG: isgarbage.c /main/5 1998/04/10 08:04:25 mgreess $ */
12 isgarbage(char * isfname)
14 char isfname2[MAXPATHLEN];
15 int isfd = -1, isfd2 = -1;
16 char buffer[ISMAXRECLEN];
19 struct keydesc keybuf;
23 (void)strcpy(isfname2, isfname);
24 (void)strcat(isfname2, "~");
26 if ((isfd = isopen(isfname, ISEXCLLOCK + ISINPUT)) == ISERROR) {
30 if (isindexinfo(isfd, (struct keydesc *)&info, 0) == ISERROR) {
34 if (strlen(isfname) + 5 >= ISMAXRECLEN)
35 recbuf = (char*) malloc(strlen(isfname) + 5);
39 sprintf(recbuf, "%s.rec", isfname);
40 if (stat(recbuf, &statbuf) < 0) {
44 iserase(isfname2); /* Delete any old backup (~) files. */
46 if ((isfd2 = isbuild(isfname2, info.di_recsize, nokey,
47 (DICTVARLENBIT&info.di_nkeys?ISVARLEN: ISFIXLEN)
48 + ISEXCLLOCK + ISINOUT)) == ISERROR) {
52 /* Copy all records */
54 while (isread(isfd, recbuf, ISNEXT) == ISOK) {
55 iswrite(isfd2, recbuf);
59 if (count != info.di_nrecords) {
63 /* Build all indexes from index info */
65 for (i = 1; i <= (info.di_nkeys & DICTNKEYSMASK); i++) {
66 if (isindexinfo(isfd, &keybuf, i) == ISERROR) {
69 if (i == 1 && keybuf.k_nparts != 0) {
70 /* Add primary index */
71 if (isaddprimary(isfd2, &keybuf) == ISERROR) {
76 /* Add secondary index */
77 if (isaddindex(isfd2, &keybuf) == ISERROR) {
86 iserase(isfname); /* cannot abort at this point ! */
87 if (isrename(isfname2, isfname) == ISERROR) {
100 (void)iserase(isfname2);
102 if (recbuf != buffer) free(recbuf);