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: isopen.c /main/3 1995/10/23 11:42:40 rswiston $ */
29 * Copyright (c) 1988 by Sun Microsystems, Inc.
39 #include "isam_impl.h"
44 static int _am_open();
46 * isfd = isopen(isfname, mode)
48 * Isopen() determines on which machine the ISAM file resides,
49 * checks if the file exists, creates a File access block,
50 * and initilizes it. It also checks permissions. Returns an ISAM file
51 * descriptor (isfd), or a value of -1 if the open failed.
54 * EBADARG Improper mode parameter
55 * EBADFILE ISAM file is corrupted or it is not an NetISAM file
56 * EFLOCKED The file is exclusively locked by other process.
57 * EFNAME Invalid ISAM file name
58 * EFNAME ISAM file does not exist
59 * ETOOMANY Too many ISAM file descriptors are in use (128 is the limit)
61 * The following error code is "borrowed" from UNIX:
62 * EACCES UNIX file system protection denies access to the file:
63 * - mode is INOUT or OUTPUT and ISAM file is on
64 * a Read-Only mounted file system
65 * - UNIX file permissions don't allow access to the file
69 isopen(char *isfname, int mode)
73 enum openmode openmode;
76 * Check if the user is allowed to access the ISAM file.
77 * Use UNIX and NFS permissions.
80 /* Get file open mode part of the mode parameter. */
81 if ((openmode = _getopenmode(mode)) == OM_BADMODE) {
82 _setiserrno2(EBADARG, '9', '0');
85 /* Create a Fab object. */
86 fab = _fab_new(isfname,
88 (Bool)((mode & ISLENMODE) == ISVARLEN),
92 return (NOISFD); /* iserrno is set by fab_new */
95 /* Get an ISAM file descriptor for this fab */
96 if ((isfd = _isfd_insert(fab)) == NOISFD) {
97 /* Table of ISAM file descriptors would overflow. */
99 _setiserrno2(ETOOMANY, '9', '0');
102 FAB_ISFDSET(fab, isfd);
104 _seterr_errcode(&fab->errcode);
109 isreclen = fab->maxreclen;
111 return ((int)isfd); /* Successful isopen() */
114 Static int _am_open(Fab *fab)
116 return (_amopen(fab->isfname, fab->openmode, &fab->varlength,
117 &fab->minreclen, &fab->maxreclen, &fab->isfhandle,
118 &fab->curpos, &fab->errcode));