]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MINICERN/packlib/kernlib/kerngen/ccgencf/cfopei.c
This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / MINICERN / packlib / kernlib / kerngen / ccgencf / cfopei.c
1 /*
2  * $Id$
3  *
4  * $Log$
5  * Revision 1.4  1997/09/02 14:26:46  mclareni
6  * WINNT correction
7  *
8  * Revision 1.3  1997/02/04 17:35:11  mclareni
9  * Merge Winnt and 97a versions
10  *
11  * Revision 1.2  1997/01/15 16:25:32  cernlib
12  * fix from F.Hemmer to return rfio return code
13  *
14  * Revision 1.1.1.1.2.1  1997/01/21 11:30:10  mclareni
15  * All mods for Winnt 96a on winnt branch
16  *
17  * Revision 1.1.1.1  1996/02/15 17:49:36  mclareni
18  * Kernlib
19  *
20  */
21 #include "kerngen/pilot.h"
22 #include "kerngen/fortranc.h"
23
24 #if defined(CERNLIB_QMOS9)
25 #include "os9gs/cfopei.c"
26 #else
27 /*>    ROUTINE CFOPEI
28   CERN PROGLIB# Z310    CFOPEI          .VERSION KERNFOR  4.38  931108
29   ORIG. 12/01/91, JZ
30       CALL CFOPEN (LUNDES, MEDIUM, NWREC, MODE, NBUF, TEXT, ISTAT)
31       open a file :
32       *LUNDES  file descriptor
33        MEDIUM  = 0,1,2,3 : primary disk/tape, secondary disk/tape
34        NWREC   record length in number of words
35        MODE    string selecting IO mode
36                = 'r ', 'w ', 'a ', 'r+ ', ...
37        NBUF    number of buffers to be allocated, (not used)
38        TEXT    name of the file
39       *ISTAT   status, =zero if success
40 */
41 #include "kerngen/cf_open.h"
42 #include <errno.h>
43 #include "kerngen/cf_xaft.h"
44 #include "kerngen/fortchar.h"
45 #include "kerngen/wordsizc.h"
46       int cfopen_perm = 0;
47 #if defined(CERNLIB_QX_SC)
48 void type_of_call cfopei_(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
49 #endif
50 #if defined(CERNLIB_QXNO_SC)
51 void type_of_call cfopei(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
52 #endif
53 #if defined(CERNLIB_QXCAPT)
54 # ifndef CERNLIB_MSSTDCALL
55     void type_of_call CFOPEI(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
56 # else
57     void type_of_call CFOPEI(lundes,medium,nwrec,mode,nbuf,ftext,len_ftext,stat,lgtx)
58     int len_ftext;
59 # endif
60 #endif
61 #if defined(CERNLIB_QMCRY)
62       _fcd  ftext;
63 #endif
64 #if !defined(CERNLIB_QMCRY)
65       char *ftext;
66 #endif
67       int  *lundes, *medium, *nwrec, *nbuf, *stat, *lgtx;
68       int  *mode;
69 {
70       char *pttext, *fchtak();
71       int  flags;
72       int  fildes;
73       int  perm;
74
75       *lundes = 0;
76       *stat   = -1;
77
78       perm = cfopen_perm;
79       cfopen_perm = 0;
80
81 /*        construct flags :
82             mode[0] =    0 r    1 w    2 a
83             mode[1] =    1 +
84 */
85 /*        flags for disk     */
86
87       if (*medium == 1)            goto fltp;
88       if (*medium == 3)            goto fltp;
89
90       if (mode[0] == 0)
91         {if (mode[1] == 0)
92           flags = O_RDONLY;
93         else
94           flags = O_RDWR;}
95
96       else if (mode[0] == 1)
97         {if (mode[1] == 0)
98           flags = O_WRONLY | O_CREAT | O_TRUNC;
99         else
100           flags = O_RDWR | O_CREAT | O_TRUNC;}
101
102       else if (mode[0] == 2)
103         {if (mode[1] == 0)
104           flags = O_WRONLY | O_CREAT | O_APPEND;
105         else
106           flags = O_RDWR | O_CREAT | O_APPEND;}
107       goto act;
108
109 /*        flags for tape     */
110
111 fltp: if (mode[0] == 0)
112         {if (mode[1] == 0)
113           flags = O_RDONLY;
114         else
115           flags = O_RDWR;}
116
117       else if (mode[0] == 1)
118         {if (mode[1] == 0)
119           flags = O_WRONLY;
120         else
121           flags = O_RDWR;}
122
123       else if (mode[0] == 2)       return;
124
125 /*        open the file      */
126
127 act:  pttext = fchtak(ftext,*lgtx);
128       if (pttext == 0)             return;
129
130       if (perm == 0)   perm = 0644;
131
132 #if defined(CERNLIB_QMDOS) || defined(CERNLIB_WINNT)
133       fildes = open (pttext, flags | O_BINARY, perm);
134 #else
135       fildes = open (pttext, flags, perm);
136 #endif
137       if (fildes < 0)              goto errm;
138       *lundes = fildes;
139       *stat   = 0;
140       goto done;
141
142 #if defined(CERNLIB_PROJSHIFT)
143 errm: *stat = (serrno ? serrno : (rfio_errno ? rfio_errno : errno));
144 #else
145 errm: *stat = errno;
146 #endif
147       perror (" error in CFOPEN");
148
149 done: free(pttext);
150       return;
151 }
152 /*> END <----------------------------------------------------------*/
153 #endif