]>
Commit | Line | Data |
---|---|---|
fe4da5cc | 1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * $Log$ | |
5 | * Revision 1.1.1.1 1996/02/15 17:49:40 mclareni | |
6 | * Kernlib | |
7 | * | |
8 | */ | |
9 | /*> ROUTINE CIOPEI | |
10 | CERN PROGLIB# Z311 CIOPEI .VERSION KERNOS9 1.01 940801 | |
11 | ORIG. 12/10/91, JZ | |
12 | CALL CIOPEN (LUNDES, MODE, TEXT, ISTAT) | |
13 | open a file : | |
14 | *LUNDES file descriptor | |
15 | MODE string selecting IO mode | |
16 | = 'r ', 'w ', 'a ', 'r+ ', ... | |
17 | TEXT name of the file | |
18 | *ISTAT status, =zero if success | |
19 | */ | |
20 | #include "kerngen/cf#open.h" | |
21 | #include <modes.h> | |
22 | #include <errno.h> | |
23 | #include "kerngen/cf#xaft.h" | |
24 | #include "kerngen/fortchar.h" | |
25 | int ciopen_perm = 0; | |
26 | ||
27 | void ciopei_(lundes,mode,ftext,stat,lgtx) | |
28 | char *ftext; | |
29 | int *lundes, *stat, *lgtx; | |
30 | int *mode; | |
31 | { | |
32 | char *pttext, *fchtak(); | |
33 | int flags; | |
34 | int fildes; | |
35 | int perm; | |
36 | ||
37 | *lundes = 0; | |
38 | *stat = -1; | |
39 | ||
40 | perm = ciopen_perm; | |
41 | ciopen_perm = 0; | |
42 | ||
43 | /* construct flags : | |
44 | mode[0] = 0 r 1 w 2 a | |
45 | mode[1] = 1 + | |
46 | */ | |
47 | /* flags for disk */ | |
48 | ||
49 | ||
50 | if (mode[0] == 0) | |
51 | { | |
52 | if (mode[1] == 0) | |
53 | flags = FAM_READ; | |
54 | else | |
55 | flags = FAM_READ | FAM_WRITE; | |
56 | ||
57 | } else if (mode[0] == 1) { | |
58 | ||
59 | if (mode[1] == 0) | |
60 | flags = FAM_WRITE; | |
61 | else | |
62 | flags = FAM_WRITE | FAM_READ; | |
63 | ||
64 | } else if (mode[0] == 2) { | |
65 | ||
66 | if (mode[1] == 0) | |
67 | flags = FAM_WRITE | FAM_APPEND; | |
68 | else | |
69 | flags = FAM_WRITE | FAM_READ | FAM_APPEND; | |
70 | } | |
71 | ||
72 | ||
73 | /* open the file */ | |
74 | ||
75 | pttext = fchtak(ftext,*lgtx); | |
76 | if (pttext == 0) return; | |
77 | ||
78 | if (perm == 0) perm = FAP_READ | FAP_WRITE | FAP_PREAD; | |
79 | ||
80 | if (mode[0] == 1) { | |
81 | if ( (fildes = create (pttext, flags, perm)) < 0 ) | |
82 | fildes = creat (pttext, flags); | |
83 | } else { | |
84 | fildes = open (pttext, flags); | |
85 | if ((mode[0] == 2) & | |
86 | (fildes < 0) ) fildes = create (pttext, flags, perm); | |
87 | } | |
88 | ||
89 | ||
90 | if (fildes < 0) goto errm; | |
91 | *lundes = fildes; | |
92 | *stat = 0; | |
93 | goto done; | |
94 | ||
95 | errm: *stat = errno; | |
96 | /* perror (" error in CIOPEN"); */ | |
97 | ||
98 | done: free(pttext); | |
99 | return; | |
100 | } | |
101 | /*> END <----------------------------------------------------------*/ |