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 static char sccsid[] = "@(#)isopen.c 1.12 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
42 #include "isam_impl.h"
47 extern char _isam_version[];
48 static char *_version_ = _isam_version;
50 static int _am_open();
52 * isfd = isopen(isfname, mode)
54 * Isopen() determines on which machine the ISAM file resides,
55 * checks if the file exists, creates a File access block,
56 * and initilizes it. It also checks permissions. Returns an ISAM file
57 * descriptor (isfd), or a value of -1 if the open failed.
60 * EBADARG Improper mode parameter
61 * EBADFILE ISAM file is corrupted or it is not an NetISAM file
62 * EFLOCKED The file is exclusively locked by other process.
63 * EFNAME Invalid ISAM file name
64 * EFNAME ISAM file does not exist
65 * ETOOMANY Too many ISAM file descriptors are in use (128 is the limit)
67 * The following error code is "borrowed" from UNIX:
68 * EACCES UNIX file system protection denies access to the file:
69 * - mode is INOUT or OUTPUT and ISAM file is on
70 * a Read-Only mounted file system
71 * - UNIX file permissions don't allow access to the file
75 isopen(char *isfname, int mode)
79 enum openmode openmode;
82 * Check if the user is allowed to access the ISAM file.
83 * Use UNIX and NFS permissions.
86 /* Get file open mode part of the mode parameter. */
87 if ((openmode = _getopenmode(mode)) == OM_BADMODE) {
88 _setiserrno2(EBADARG, '9', '0');
91 /* Create a Fab object. */
92 fab = _fab_new(isfname,
94 (Bool)((mode & ISLENMODE) == ISVARLEN),
98 return (NOISFD); /* iserrno is set by fab_new */
101 /* Get an ISAM file descriptor for this fab */
102 if ((isfd = _isfd_insert(fab)) == NOISFD) {
103 /* Table of ISAM file descriptors would overflow. */
105 _setiserrno2(ETOOMANY, '9', '0');
108 FAB_ISFDSET(fab, isfd);
110 _seterr_errcode(&fab->errcode);
115 isreclen = fab->maxreclen;
117 return ((int)isfd); /* Successful isopen() */
120 Static int _am_open(Fab *fab)
122 return (_amopen(fab->isfname, fab->openmode, &fab->varlength,
123 &fab->minreclen, &fab->maxreclen, &fab->isfhandle,
124 &fab->curpos, &fab->errcode));