]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MINICERN/packlib/kernlib/kerngen/ccgenci/ciopei.c
Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / MINICERN / packlib / kernlib / kerngen / ccgenci / ciopei.c
1 /*
2  * $Id$
3  *
4  * $Log$
5  * Revision 1.4  1997/09/02 14:26:53  mclareni
6  * WINNT correction
7  *
8  * Revision 1.3  1997/02/04 17:35:18  mclareni
9  * Merge Winnt and 97a versions
10  *
11  * Revision 1.2  1997/01/15 16:25:45  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:17  mclareni
15  * All mods for Winnt 96a on winnt branch
16  *
17  * Revision 1.1.1.1  1996/02/15 17:49:39  mclareni
18  * Kernlib
19  *
20  */
21 #include "kerngen/pilot.h"
22 #include "kerngen/fortranc.h"
23
24 #if defined(CERNLIB_QMOS9)
25 #include "os9gs/ciopei.c"
26 #else
27 /*>    ROUTINE CIOPEI
28   CERN PROGLIB# Z311    CIOPEI          .VERSION KERNFOR  4.39  940228
29   ORIG. 12/10/91, JZ
30       CALL CIOPEN (LUNDES, MODE, TEXT, ISTAT)
31       open a file :
32       *LUNDES  file descriptor
33        MODE    string selecting IO mode
34                = 'r ', 'w ', 'a ', 'r+ ', ...
35        TEXT    name of the file
36       *ISTAT   status, =zero if success
37 */
38 #include "kerngen/cf_open.h"
39 #ifndef WIN32
40 #  include <errno.h>
41 #else
42 #  include <stdlib.h>
43 #endif
44 #include "kerngen/cf_xaft.h"
45 #include "kerngen/fortchar.h"
46       int ciopen_perm = 0;
47 #if defined(CERNLIB_QX_SC)
48 void type_of_call ciopei_(lundes,mode,ftext,stat,lgtx)
49 #endif
50 #if defined(CERNLIB_QXNO_SC)
51 void type_of_call ciopei(lundes,mode,ftext,stat,lgtx)
52 #endif
53 #if defined(CERNLIB_QXCAPT)
54 #  ifdef CERNLIB_MSSTDCALL
55    void type_of_call CIOPEI(lundes,mode,ftext,lftext,stat,lgtx)
56    int lftext;
57 #  else
58    void type_of_call CIOPEI(lundes,mode,ftext,stat,lgtx)
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, *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 = ciopen_perm;
79       ciopen_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
88       if (mode[0] == 0)
89         {if (mode[1] == 0)
90           flags = O_RDONLY;
91         else
92           flags = O_RDWR;}
93
94       else if (mode[0] == 1)
95         {if (mode[1] == 0)
96           flags = O_WRONLY | O_CREAT | O_TRUNC;
97         else
98           flags = O_RDWR | O_CREAT | O_TRUNC;}
99
100       else if (mode[0] == 2)
101         {if (mode[1] == 0)
102           flags = O_WRONLY | O_CREAT | O_APPEND;
103         else
104           flags = O_RDWR | O_CREAT | O_APPEND;}
105
106 /*        open the file      */
107
108       pttext = fchtak(ftext,*lgtx);
109       if (pttext == 0)             return;
110
111       if (perm == 0)   perm = 0644;
112
113 #if defined(CERNLIB_QMDOS) || defined(CERNLIB_WINNT)
114       fildes = open (pttext, flags | O_BINARY, perm);
115 #else
116       fildes = open (pttext, flags, perm);
117 #endif
118       if (fildes < 0)              goto errm;
119       *lundes = fildes;
120       *stat   = 0;
121       goto done;
122
123 #if defined(CERNLIB_PROJSHIFT)
124 errm: *stat = (serrno ? serrno : (rfio_errno ? rfio_errno : errno));
125 #else
126 errm: *stat = errno;
127 #endif
128 /*    perror (" error in CIOPEN");  */
129
130 done: free(pttext);
131       return;
132 }
133 /*> END <----------------------------------------------------------*/
134 #endif