d8684b90d12bbca9bc725105946858aacd87f2e3
[oweals/cde.git] / cde / lib / tt / mini_isam / isfab.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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: isfab.c /main/3 1995/10/23 11:38:24 rswiston $                                                       */
28 #ifndef lint
29 static char sccsid[] = "@(#)isfab.c 1.8 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * isfab.c
37  *
38  * Description:
39  *      The ISAM file access block functions.
40  *
41  */
42 #include <stdlib.h>
43
44 #include "isam_impl.h"
45
46
47 /*
48  * fab = *fab_new(isfname, mode, varlen, minreclen, maxreclen)
49  *
50  * Fab_new() creates an File access block (fab object) that is used
51  * for all subsequent operations in this file. Return a pointer to 
52  * the fab object, or NULL in the case of an error.
53  
54  * isfname, Local path on the host 
55  * varlen, 0/1 flag
56  */
57
58 Fab *
59 _fab_new(char *isfname, enum openmode openmode, Bool varlen, int minreclen, int maxreclen)
60 {
61     register Fab        *fab;
62
63     /* Allocate memory for the fab object. */
64     fab = (Fab *) _ismalloc(sizeof(*fab));
65     memset((char *)fab, 0, sizeof(*fab));
66
67     if (fab == NULL) {
68       iserrno = EFATAL;
69       return (NULL);
70     }
71
72     /* Set fields in the fab objects. */
73     fab->openmode = openmode;
74     fab->varlength = varlen;
75     fab->minreclen = minreclen;
76     fab->maxreclen = maxreclen;
77     fab->isfname = _isallocstring(isfname);
78
79     if (fab->isfname == NULL) {
80       free((char *)fab);
81       iserrno = EFATAL;
82       return (NULL);
83     }
84
85     return (fab);
86 }
87
88 void
89 _fab_destroy(register Fab *fab)
90 {
91     assert(fab != NULL);
92     assert(fab->isfname != NULL);
93
94     _isfreestring(fab->isfname);
95
96     _bytearr_free(&fab->isfhandle);
97     _bytearr_free(&fab->curpos);
98
99     free((char *)fab);
100 }