1 /* $Id: $ */
2
3 /* Copyright (C) 1997 Sverre Hvammen Johansen,
4 * Department of Informatics, University of Oslo.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "file.h"
21 #include "simfile.h"
22
23 /******************************************************************************
24 BOOLEAN PROCEDURE OPEN */
25
26 char
__rdbopen(p)27 __rdbopen (p)
28 __bs10FILE *p;
29 {
30 if (!((__bs1FILE *) p)->open)
31 {
32 ((__bs1FILE *) p)->file
33 = fopen (((__bs1FILE *) p)->filename.obj->string, "r");
34 if (((__bs1FILE *) p)->file != __NULL)
35 (void) fclose (((__bs1FILE *) p)->file);
36 if (((__bs1FILE *) p)->create == __CREATE
37 && ((__bs1FILE *) p)->file != __NULL)
38 return (__FALSE);
39 if (((__bs1FILE *) p)->create == __NOCREATE
40 && ((__bs1FILE *) p)->file == __NULL)
41 return (__FALSE);
42 #if VMS_DIRECTFILE
43 if (((__bs1FILE *) p)->file == __NULL)
44 {
45 if ((((__bs1FILE *) p)->file
46 = fopen (((__bs1FILE *) p)->filename.obj->string
47 ,"w")) == __NULL)
48 return (__FALSE);
49 (void) fclose (((__bs1FILE *) p)->file);
50 }
51 if ((((__bs1FILE *) p)->file
52 = fopen (((__bs1 *) p)->filename.obj->string
53 ,"r+")) == __NULL)
54 return (__FALSE);
55 #else
56 if ((((__bs1FILE *) p)->file
57 = fopen (((__bs1FILE *) p)->filename.obj->string
58 ,((__bs1FILE *) p)->file == __NULL ? "w+" :
59 ((__bs1FILE *) p)->readwrite == __READONLY
60 ? "r" : "r+")) == __NULL)
61 return (__FALSE);
62 #endif
63 if (((__bs1FILE *) p)->append == __APPEND)
64 {
65 if (fseek (((__bs1FILE *) p)->file, 0L, 2) == __EOF)
66 {
67 (void) fclose (((__bs1FILE *) p)->file);
68 return (__FALSE);
69 }
70 p->loc = p->minwriteloc = ftell (((__bs1FILE *) p)->file);
71 }
72 else
73 p->loc = p->minwriteloc = 1;
74 p->lastop = __SEEK;
75 p->maxloc = MAX_INT - 1;
76 if (((__bs1FILE *) p)->readwrite == __READONLY)
77 p->minwriteloc = MAX_INT;
78 if (((__bs1FILE *) p)->readwrite == __WRITEONLY)
79 p->writeonly = __TRUE;
80 return (((__bs1FILE *) p)->open = __TRUE);
81 }
82 else
83 return (__FALSE);
84 }
85