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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifdef _BSD
00041 #include <sys/errno.h>
00042 #endif
00043 #include <mutex.h>
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include <cmplrs/fio.h>
00047 #include "fmt.h"
00048 #include "uio.h"
00049 #include "due.h"
00050 #include "err.h"
00051 #include "open.h"
00052 #include "sfe.h"
00053 #include "idxio.h"
00054 #include "due.h"
00055 #include "bcompat.h"
00056
00057 int
00058 e_rsfe (void)
00059 {
00060 return( e_rsfe_mp( &f77curunit ) );
00061 }
00062
00063 int
00064 e_rsfe_mp (unit **fu)
00065 {
00066 int n;
00067 unit *ftnunit = *fu;
00068
00069 if (ftnunit->ufmt == 2)
00070 n = 0;
00071 else
00072 #ifdef _BSD
00073 redo:
00074 #endif
00075 n = en_fio (&ftnunit);
00076 ftnunit->f77fmtbuf = NULL;
00077
00078 #ifdef _BSD
00079 if (ftnunit->ufd && ferror (ftnunit->ufd)) {
00080 if (errno == EWOULDBLOCK) {
00081 clearerr(ftnunit->ufd);
00082 goto redo;
00083 }
00084 errret(ftnunit->f77errlist.cierr, errno, "sfe");
00085 }
00086 #else
00087 if (ftnunit->ufd && ferror (ftnunit->ufd))
00088 errret(ftnunit->f77errlist.cierr, errno, "sfe");
00089 #endif
00090 if (ftnunit->ushared)
00091 fflush(ftnunit->ufd);
00092
00093 ftnunit->lock_unit = 0;
00094 return (n);
00095 }
00096
00097
00098 int c_sfe (cilist64 *a, unit **fu)
00099 {
00100 extern vfmt_struct f77vfmt_com_;
00101 unit *ftnunit;
00102
00103 if ((ftnunit = *fu = map_luno (a->ciunit)) == NULL)
00104 errret(a->cierr, 101, "startio");
00105 while (fu != &f77curunit && test_and_set( &ftnunit->lock_unit, 1L ))
00106 ;
00107 if (ftnunit->uconn <= 0 && fk_open (SEQ, FMT, a->ciunit)) {
00108 ftnunit->uconn = 0;
00109 errret(a->cierr, 114, "sfe")
00110 }
00111 if(!ftnunit->ufmt) errret(a->cierr,102,"sfe")
00112 if (f77vfmt_com_.PFI != NULL) {
00113
00114
00115
00116
00117
00118
00119 ftnunit->vfmt = f77vfmt_com_.PFI;
00120 ftnunit->vfmtfp = f77vfmt_com_.static_link;
00121 } else {
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 ftnunit->vfmt = a->civfmt;
00138 ftnunit->vfmtfp = a->civfmtfp;
00139 }
00140 return (0);
00141 }
00142
00143 int
00144 e_wsfe (void)
00145 {
00146 return( e_wsfe_mp( &f77curunit ) );
00147 }
00148
00149
00150 int
00151 e_wsfe_mp (unit **fu)
00152 {
00153 unit *ftnunit = *fu;
00154 int n;
00155
00156 if (ftnunit->ufmt == 2)
00157 n = e_wsue_mp (fu);
00158 else
00159 n = e_rsfe_mp (fu);
00160 return (n);
00161 }
00162
00163
00164 int
00165 e_xsfe (void)
00166 {
00167 return( e_xsfe_mp( &f77curunit ) );
00168 }
00169
00170 int
00171 e_xsfe_mp (unit **fu)
00172 {
00173 return (e_rsfe_mp (fu));
00174 }
00175
00176 int
00177 e_wsue (void)
00178 {
00179 return( e_wsue_mp( &f77curunit ) );
00180 }
00181
00182
00183 int
00184 e_wsue_mp (unit **fu)
00185 {
00186 ftnll loc;
00187 unit *ftnunit = *fu;
00188 int n;
00189
00190 if (ftnunit->uacc == KEYED) {
00191 n = idxwrite(ftnunit);
00192 ftnunit->lock_unit = 0;
00193 return (n);
00194 } else if (ftnunit->ufmt == 2) {
00195
00196 (void) fwrite ((char *) &ftnunit->f77recend, sizeof (int), 1, ftnunit->ufd);
00197 (void) fwrite (ftnunit->f77fio_buf, ftnunit->f77recend, 1, ftnunit->ufd);
00198 if (fwrite ((char *) &ftnunit->f77recend, sizeof (int), 1, ftnunit->ufd) != 1)
00199 errret(ftnunit->f77errlist.cierr, errno, "system write error");
00200 ftnunit->f77nonl = ftnunit->f77recpos = ftnunit->f77recend = ftnunit->f77cursor = 0;
00201 } else if (ftnunit->url != 1) {
00202
00203
00204 if (ftnunit->uacc == DIRECT) {
00205 return( e_wdue_mp (fu) );
00206 } else if (ftnunit->overflowed) {
00207 if (est_reclen && est_reclen == ftnunit->f77reclen) {
00208 goto no_overflowed;
00209 } else {
00210 if (ftnunit->f77recpos)
00211 fwrite (ftnunit->f77fio_buf, ftnunit->f77recpos, 1, ftnunit->ufd);
00212 {
00213 int f77reclen_32bit = ftnunit->f77reclen;
00214 fwrite ((char *) &f77reclen_32bit, sizeof (int), 1, ftnunit->ufd);
00215 }
00216 if ((loc = FTELL (ftnunit->ufd)) == -1)
00217 errret(ftnunit->f77errlist.cierr, 169, "sue");
00218 (void) FSEEK (ftnunit->ufd, -((ftnll)ftnunit->f77reclen + 8), 1);
00219 {
00220 int f77reclen_32bit = ftnunit->f77reclen;
00221 if (fwrite ((char *) &f77reclen_32bit, sizeof (int), 1, ftnunit->ufd) != 1)
00222 errret(ftnunit->f77errlist.cierr, errno, "system write error");
00223 }
00224 (void) FSEEK (ftnunit->ufd, loc, 0);
00225 }
00226 } else {
00227 *(int *) ftnunit->f77fio_buf = ftnunit->f77reclen;
00228 no_overflowed:
00229 if (!ftnunit->f77recpos) {
00230 int f77reclen_32bit = ftnunit->f77reclen;
00231 if (fwrite (&f77reclen_32bit, sizeof (int), 1, ftnunit->ufd) != 1)
00232 errret(ftnunit->f77errlist.cierr, errno, "system write error");
00233 } else {
00234 int f77reclen_32bit = ftnunit->f77reclen;
00235 memcpy (ftnunit->f77fio_buf + ftnunit->f77recpos, &f77reclen_32bit, 4);
00236 if (fwrite (ftnunit->f77fio_buf, ftnunit->f77recpos + 4, 1, ftnunit->ufd) != 1)
00237 errret(ftnunit->f77errlist.cierr, errno, "system write error");
00238 }
00239 if (ftnunit->ufd && ferror (ftnunit->ufd))
00240 errret(ftnunit->f77errlist.cierr, errno, "sue");
00241 }
00242 }
00243 if (ftnunit->ushared)
00244 fflush(ftnunit->ufd);
00245 ftnunit->lock_unit = 0;
00246 return (0);
00247 }
00248
00249 #if 11
00250 #pragma weak e_rsfe64 = e_rsfe
00251 #pragma weak e_rsfe64_mp = e_rsfe_mp
00252 #pragma weak e_wsfe64 = e_wsfe
00253 #pragma weak e_wsfe64_mp = e_wsfe_mp
00254 #pragma weak e_xsfe64 = e_xsfe
00255 #pragma weak e_xsfe64_mp = e_xsfe_mp
00256 #pragma weak e_wsue64 = e_wsue
00257 #pragma weak e_wsue64_mp = e_wsue_mp
00258
00259 #endif