00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "kerngen/pilot.h"
00030 #include "kerngen/fortranc.h"
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033
00034 #if defined(CERNLIB_QMOS9)
00035 #include "os9gs/cfopei.c"
00036 #else
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include "kerngen/cf_open.h"
00052 #include <errno.h>
00053 #include "kerngen/cf_xaft.h"
00054 #include "kerngen/fortchar.h"
00055 #include "kerngen/wordsizc.h"
00056 int cfopen_perm = 0;
00057 #if defined(CERNLIB_QX_SC)
00058 void type_of_call cfopei_(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
00059 #endif
00060 #if defined(CERNLIB_QXNO_SC)
00061 void type_of_call cfopei(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
00062 #endif
00063 #if defined(CERNLIB_QXCAPT)
00064 # ifndef CERNLIB_MSSTDCALL
00065 void type_of_call CFOPEI(lundes,medium,nwrec,mode,nbuf,ftext,stat,lgtx)
00066 # else
00067 void type_of_call CFOPEI(lundes,medium,nwrec,mode,nbuf,ftext,len_ftext,stat,lgtx)
00068 int len_ftext;
00069 # endif
00070 #endif
00071 #if defined(CERNLIB_QMCRY)
00072 _fcd ftext;
00073 #endif
00074 #if !defined(CERNLIB_QMCRY)
00075 char *ftext;
00076 #endif
00077 int *lundes, *medium, *nwrec, *nbuf, *stat, *lgtx;
00078 int *mode;
00079 {
00080 char *pttext, *fchtak();
00081 int flags;
00082 int fildes;
00083 int perm;
00084
00085 *lundes = 0;
00086 *stat = -1;
00087
00088 perm = cfopen_perm;
00089 cfopen_perm = 0;
00090
00091
00092
00093
00094
00095
00096
00097 if (*medium == 1) goto fltp;
00098 if (*medium == 3) goto fltp;
00099
00100 if (mode[0] == 0)
00101 {if (mode[1] == 0)
00102 flags = O_RDONLY;
00103 else
00104 flags = O_RDWR;}
00105
00106 else if (mode[0] == 1)
00107 {if (mode[1] == 0)
00108 flags = O_WRONLY | O_CREAT | O_TRUNC;
00109 else
00110 flags = O_RDWR | O_CREAT | O_TRUNC;}
00111
00112 else if (mode[0] == 2)
00113 {if (mode[1] == 0)
00114 flags = O_WRONLY | O_CREAT | O_APPEND;
00115 else
00116 flags = O_RDWR | O_CREAT | O_APPEND;}
00117 goto act;
00118
00119
00120
00121 fltp: if (mode[0] == 0)
00122 {if (mode[1] == 0)
00123 flags = O_RDONLY;
00124 else
00125 flags = O_RDWR;}
00126
00127 else if (mode[0] == 1)
00128 {if (mode[1] == 0)
00129 flags = O_WRONLY;
00130 else
00131 flags = O_RDWR;}
00132
00133 else if (mode[0] == 2) return;
00134
00135
00136
00137 act: pttext = fchtak(ftext,*lgtx);
00138 if (pttext == 0) return;
00139
00140 if (perm == 0) perm = 0644;
00141
00142 #if defined(CERNLIB_QMDOS) || defined(CERNLIB_WINNT)
00143 fildes = open (pttext, flags | O_BINARY, perm);
00144 #else
00145 fildes = open (pttext, flags, perm);
00146 #endif
00147 if (fildes < 0) goto errm;
00148 *lundes = fildes;
00149 *stat = 0;
00150 goto done;
00151
00152 #if defined(CERNLIB_PROJSHIFT)
00153 errm: *stat = (serrno ? serrno : (rfio_errno ? rfio_errno : errno));
00154 #else
00155 errm: *stat = errno;
00156 #endif
00157 perror (" error in CFOPEN");
00158
00159 done: free(pttext);
00160 return;
00161 }
00162
00163 #endif