Merge branch 'master' into cde-next
[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 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * isfab.c
34  *
35  * Description:
36  *      The ISAM file access block functions.
37  *
38  */
39 #include <stdlib.h>
40
41 #include "isam_impl.h"
42
43
44 /*
45  * fab = *fab_new(isfname, mode, varlen, minreclen, maxreclen)
46  *
47  * Fab_new() creates an File access block (fab object) that is used
48  * for all subsequent operations in this file. Return a pointer to 
49  * the fab object, or NULL in the case of an error.
50  
51  * isfname, Local path on the host 
52  * varlen, 0/1 flag
53  */
54
55 Fab *
56 _fab_new(char *isfname, enum openmode openmode, Bool varlen, int minreclen, int maxreclen)
57 {
58     Fab *fab;
59
60     /* Allocate memory for the fab object. */
61     fab = (Fab *) _ismalloc(sizeof(*fab));
62     memset((char *)fab, 0, sizeof(*fab));
63
64     if (fab == NULL) {
65       iserrno = EFATAL;
66       return (NULL);
67     }
68
69     /* Set fields in the fab objects. */
70     fab->openmode = openmode;
71     fab->varlength = varlen;
72     fab->minreclen = minreclen;
73     fab->maxreclen = maxreclen;
74     fab->isfname = _isallocstring(isfname);
75
76     if (fab->isfname == NULL) {
77       free((char *)fab);
78       iserrno = EFATAL;
79       return (NULL);
80     }
81
82     return (fab);
83 }
84
85 void
86 _fab_destroy(Fab *fab)
87 {
88     assert(fab != NULL);
89     assert(fab->isfname != NULL);
90
91     _isfreestring(fab->isfname);
92
93     _bytearr_free(&fab->isfhandle);
94     _bytearr_free(&fab->curpos);
95
96     free((char *)fab);
97 }