]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MINICERN/packlib/kernlib/kerngen/ccgencf/os9gs/cfopei.c
This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / MINICERN / packlib / kernlib / kerngen / ccgencf / os9gs / cfopei.c
1 /*
2  * $Id$
3  *
4  * $Log$
5  * Revision 1.1.1.1  1996/02/15 17:49:37  mclareni
6  * Kernlib
7  *
8  */
9 /*>    ROUTINE CFOPEI
10   CERN PROGLIB# Z310    CFOPEI          .VERSION KERNOS9  1.01  940801
11   ORIG. 12/01/91, JZ
12       CALL CFOPEN (LUNDES, MEDIUM, NWREC, MODE, NBUF, TEXT, ISTAT)
13       open a file :
14       *LUNDES  file descriptor
15        MEDIUM  = 0,1,2,3 : primary disk/tape, secondary disk/tape
16        NWREC   record length in number of words
17        MODE    string selecting IO mode
18                = 'r ', 'w ', 'a ', 'r+ ', ...
19        NBUF    number of buffers to be allocated, (not used)
20        TEXT    name of the file
21       *ISTAT   status, =zero if success
22 */
23 #include "kerngen/cf#open.h"
24 #include <errno.h>
25 #include <modes.h>
26 #include "kerngen/cf#xaft.h"
27 #include "kerngen/fortchar.h"
28 #include "kerngen/wordsizc.h"
29       int cfopen_perm = 0;
30
31 void cfopei_(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
32       char *ftext;
33       int  *lundes, *medium, *nwrec, *nbuf, *stat, *lgtx;
34       int  *mode;
35 {
36       char *pttext, *fchtak();
37       int  flags;
38       int  fildes;
39       int  perm;
40
41       *lundes = 0;
42       *stat   = -1;
43
44       perm = cfopen_perm;
45       cfopen_perm = 0;
46
47 /*
48  *    construct flags :
49  *      mode[0] =    0 r    1 w    2 a
50  *      mode[1] =    1 +
51  */
52
53       if ((*medium == 1) || (*medium == 3))
54       {
55
56 /*
57  *    flags for tape
58  */
59
60           if (mode[0] == 0)
61           {
62               if (mode[1] == 0)
63                   flags = FAM_READ;
64               else
65                   flags = FAM_READ | FAM_WRITE;
66
67           } else if (mode[0] == 1) {
68
69               if (mode[1] == 0)
70                   flags = FAM_WRITE;
71               else
72                   flags = FAM_READ | FAM_WRITE;
73
74           } else if (mode[0] == 2)       return;
75
76       } else {
77
78 /*
79  *    flags for disk
80  */
81
82           if (mode[0] == 0)
83           {
84               if (mode[1] == 0)
85                   flags = FAM_READ;
86               else
87                   flags = FAM_READ | FAM_WRITE;
88
89           } else if (mode[0] == 1) {
90
91               if (mode[1] == 0)
92                   flags = FAM_WRITE;
93               else
94                   flags = FAM_WRITE | FAM_READ;
95
96           } else if (mode[0] == 2) {
97
98               if (mode[1] == 0)
99                   flags = FAM_WRITE | FAM_APPEND;
100               else
101                   flags = FAM_WRITE | FAM_READ | FAM_APPEND;
102           }
103       }
104
105 /*
106  *    open the file
107  */
108
109       pttext = fchtak(ftext,*lgtx);
110       if (pttext == 0) return;
111
112       if (perm == 0)   perm = FAP_READ | FAP_WRITE | FAP_PREAD;
113
114       if ( (mode[0] == 1) &
115            ((*medium == 0) || (*medium == 2))
116          ) {
117               if ( (fildes = create (pttext, flags, perm)) < 0 )
118                   fildes = creat (pttext, flags);
119
120       } else {
121           fildes = open (pttext, flags);
122           if ((mode[0] == 2) &
123               (fildes < 0) ) fildes = create (pttext, flags, perm);
124       }
125
126       if (fildes < 0)  goto errm;
127
128       *lundes = fildes;
129       *stat   = 0;
130       goto done;
131
132 errm: *stat = errno;
133       perror (" error in CFOPEN");
134
135 done: free(pttext);
136       return;
137 }
138 /*> END <----------------------------------------------------------*/