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 libraries 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 * Copyright (c) 1988 by Sun Microsystems, Inc.
40 #include "isam_impl.h"
44 static void _unlink_datfile(), _unlink_indfile(), _unlink_varfile();
45 static int _amerase();
48 * isfd = iserase(isfname, mode)
52 * EBADFILE ISAM file is corrupted or it is not an NetISAM file
53 * EFLOCKED The file is exclusively locked by other process.
54 * EFNAME Invalid ISAM file name
55 * EFNAME ISAM file does not exist
56 * ETOOMANY Too many ISAM file descriptors are in use (128 is the limit)
58 * The following error code is "borrowed" from UNIX:
59 * EACCES UNIX file system protection denies access to the file:
60 * - mode is INOUT or OUTPUT and ISAM file is on
61 * a Read-Only mounted file system
62 * - UNIX file permissions don't allow access to the file
66 iserase(char *isfname)
74 if ((isfd = isopen(isfname, ISINOUT)) == -1)
75 return (ISERROR); /* iserrno is set */
78 * Get File Access Block.
80 if ((fab = _isfd_find(isfd)) == NULL) {
81 _isfatal_error("iserase() cannot find FAB");
82 _setiserrno2(EFATAL, '9', '0');
86 if (_amerase(&fab->isfhandle, &fab->errcode)
87 && fab->errcode.iserrno != ENOENT) {
88 _seterr_errcode(&fab->errcode);
93 _fab_destroy(fab); /* Deallocate Fab object */
96 return (ISOK); /* Successful iserase() */
100 * _amerase(isfhandle)
102 * _amerase() erases ISAM file
105 * isfhandle Handle of ISAM file
113 _amerase(Bytearray *isfhandle, struct errcode *errcode)
116 char *isfname = _getisfname(isfhandle);
121 * Get FCB corresponding to the isfhandle handle.
123 if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
128 * Delete FCB and remove it from FCB cache.
130 (void) _watchfd_decr(_isfcb_nfds(fcb));
132 _mngfcb_delete(isfhandle);
135 * Unlink all UNIX files.
137 _unlink_datfile(isfname);
138 _unlink_indfile(isfname);
139 _unlink_varfile(isfname);
152 _unlink_datfile(char *isfname)
154 char namebuf[MAXPATHLEN];
156 snprintf(namebuf, sizeof(namebuf), "%s", isfname);
157 _makedat_isfname(namebuf);
159 (void)unlink(namebuf);
164 _unlink_indfile(char *isfname)
166 char namebuf[MAXPATHLEN];
168 snprintf(namebuf, sizeof(namebuf), "%s", isfname);
169 _makeind_isfname(namebuf);
171 (void)unlink(namebuf);
176 _unlink_varfile(char *isfname)
178 char namebuf[MAXPATHLEN];
180 snprintf(namebuf, sizeof(namebuf), "%s", isfname);
181 _makevar_isfname(namebuf);
183 (void)unlink(namebuf);