2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: iserase.c /main/3 1995/10/23 11:38:08 rswiston $ */
29 static char sccsid[] = "@(#)iserase.c 1.8 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
43 #include "isam_impl.h"
46 static void _unlink_datfile(), _unlink_indfile(), _unlink_varfile();
47 static int _amerase();
50 * isfd = iserase(isfname, mode)
54 * EBADFILE ISAM file is corrupted or it is not an NetISAM file
55 * EFLOCKED The file is exclusively locked by other process.
56 * EFNAME Invalid ISAM file name
57 * EFNAME ISAM file does not exist
58 * ETOOMANY Too many ISAM file descriptors are in use (128 is the limit)
60 * The following error code is "borrowed" from UNIX:
61 * EACCES UNIX file system protection denies access to the file:
62 * - mode is INOUT or OUTPUT and ISAM file is on
63 * a Read-Only mounted file system
64 * - UNIX file permissions don't allow access to the file
77 if ((isfd = isopen(isfname, ISINOUT)) == -1)
78 return (ISERROR); /* iserrno is set */
81 * Get File Access Block.
83 if ((fab = _isfd_find(isfd)) == NULL) {
84 _isfatal_error("iserase() cannot find FAB");
85 _setiserrno2(EFATAL, '9', '0');
89 if (_amerase(&fab->isfhandle, &fab->errcode)
90 && fab->errcode.iserrno != ENOENT) {
91 _seterr_errcode(&fab->errcode);
96 _fab_destroy(fab); /* Deallocate Fab object */
99 return (ISOK); /* Successful iserase() */
103 * _amerase(isfhandle)
105 * _amerase() erases ISAM file
108 * isfhandle Handle of ISAM file
116 _amerase(isfhandle, errcode)
117 Bytearray *isfhandle;
118 struct errcode *errcode;
121 char *isfname = _getisfname(isfhandle);
126 * Get FCB corresponding to the isfhandle handle.
128 if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
133 * Delete FCB and remove it from FCB cache.
135 (void) _watchfd_decr(_isfcb_nfds(fcb));
137 _mngfcb_delete(isfhandle);
140 * Unlink all UNIX files.
142 _unlink_datfile(isfname);
143 _unlink_indfile(isfname);
144 _unlink_varfile(isfname);
157 _unlink_datfile(isfname)
160 char namebuf[MAXPATHLEN];
162 (void) strcpy(namebuf, isfname);
163 _makedat_isfname(namebuf);
165 (void)unlink(namebuf);
170 _unlink_indfile(isfname)
173 char namebuf[MAXPATHLEN];
175 (void) strcpy(namebuf, isfname);
176 _makeind_isfname(namebuf);
178 (void)unlink(namebuf);
183 _unlink_varfile(isfname)
186 char namebuf[MAXPATHLEN];
188 (void) strcpy(namebuf, isfname);
189 _makevar_isfname(namebuf);
191 (void)unlink(namebuf);