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 #pragma ident "@(#) libf/fio/wu90.c 92.3 08/02/99 10:38:48"
00039
00040 #include <stdio.h>
00041 #include "fio.h"
00042 #include "f90io.h"
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 int
00078 _FWU(ControlListType *cilist, iolist_header *iolist, void *stck)
00079 {
00080 register int errf;
00081 register int errn;
00082 register int iost;
00083 register int retval;
00084 register recn_t errarg;
00085 register unum_t unum;
00086 unit *cup;
00087 FIOSPTR css;
00088
00089
00090
00091
00092
00093
00094 assert ( cilist->stksize >= sizeof(struct fiostate)/sizeof(long) );
00095
00096
00097
00098 assert ( cilist->uflag == CI_UNITNUM );
00099 assert ( cilist->eorflag == 0 );
00100 assert ( cilist->endflag == 0 );
00101
00102
00103 css = stck;
00104 errn = 0;
00105 errarg = 0;
00106 retval = IO_OKAY;
00107
00108 if (iolist->iolfirst == 0) {
00109 cup = css->f_cu;
00110 goto data_transfer;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119 errf = (cilist->errflag || cilist->iostatflg);
00120 unum = *cilist->unit.wa;
00121 iost = cilist->dflag ? T_WDU : T_WSU;
00122
00123 STMT_BEGIN(unum, 0, iost, NULL, css, cup);
00124
00125 if (cup == NULL) {
00126 int stat;
00127
00128 cup = _imp_open(css, (cilist->dflag ? DIR : SEQ), UNF,
00129 unum, errf, &stat);
00130
00131
00132
00133
00134
00135 if (cup == NULL) {
00136 errn = stat;
00137 goto handle_exception;
00138 }
00139 }
00140
00141 cup->f_lastiolist = NULL;
00142
00143
00144
00145
00146
00147 cup->uflag = (cilist->errflag ? _UIOSTF : 0) |
00148 (cilist->iostat_spec != NULL ? _UERRF : 0);
00149
00150 cup->uwrt = 1;
00151 cup->ulastyp = DVTYPE_TYPELESS;
00152
00153 if (cilist->dflag) {
00154
00155 if (!cup->ok_wr_dir_unf)
00156 errn = _get_mismatch_error(errf, iost, cup, css);
00157 else {
00158 recn_t recn;
00159
00160 recn = (recn_t) *cilist->rec_spec;
00161 errarg = recn;
00162 errn = _unit_seek(cup, recn, iost);
00163 }
00164
00165 if (cup->udalast > cup->udamax)
00166 cup->udamax = cup->udalast;
00167
00168 cup->uend = BEFORE_ENDFILE;
00169 }
00170 else {
00171
00172 if (!cup->ok_wr_seq_unf) {
00173 errn = _get_mismatch_error(errf, iost, cup, css);
00174 goto handle_exception;
00175 }
00176
00177 if (cup->uend != BEFORE_ENDFILE) {
00178 struct ffsw fst;
00179
00180
00181
00182
00183 if (!cup->umultfil && !cup->uspcproc) {
00184 errn = FEWRAFEN;
00185 goto handle_exception;
00186 }
00187
00188
00189
00190
00191
00192 if ((cup->uend == LOGICAL_ENDFILE) && !(cup->uspcproc)) {
00193 if (XRCALL(cup->ufp.fdc, weofrtn)cup->ufp.fdc, &fst) < 0)
00194 errn = fst.sw_error;
00195 }
00196
00197 cup->uend = BEFORE_ENDFILE;
00198 }
00199 }
00200
00201 if (errn != 0)
00202 goto handle_exception;
00203
00204
00205
00206
00207
00208
00209 data_transfer:
00210
00211 cup->f_lastwritten = 0;
00212 if (iolist->iollast && !cilist->dflag && cup->ublkd) {
00213 cup->f_lastiolist = (long *)iolist + iolist->ioetsize;
00214 }
00215 errn = _xfer_iolist(css, cup, iolist, _wrunf);
00216
00217 if (errn != 0)
00218 goto handle_exception;
00219
00220 if (! iolist->iollast)
00221 return(IO_OKAY);
00222
00223
00224
00225
00226
00227
00228
00229 finalization:
00230
00231 if (cup != NULL) {
00232 cup->ulrecl = cup->urecpos;
00233 cup->urecpos = 0;
00234 cup->f_lastiolist = NULL;
00235 }
00236
00237 if (errn != 0)
00238 goto out_a_here;
00239
00240 if (!cilist->dflag) {
00241 if (cup->ublkd && cup->f_lastwritten == 0) {
00242 register int ret;
00243 int dummy;
00244
00245
00246
00247 ret = _fwwd(cup, &dummy, &__tip_null, FULL,
00248 (int *) NULL, (long *) NULL, &dummy);
00249
00250 if (ret == IOERR)
00251 errn = errno;
00252 }
00253 }
00254 else {
00255 register long bleft;
00256
00257 bleft = cup->urecl - (cup->ulrecl >> 3);
00258
00259 if (bleft > 0 && cup->udalast == cup->udamax) {
00260 ssize_t ret;
00261 long zero = 0;
00262 long *zbuf;
00263 struct ffsw fst;
00264
00265
00266
00267
00268
00269
00270
00271
00272 zbuf = &zero;
00273
00274 if (bleft > sizeof(long)) {
00275
00276 zbuf = (long *) malloc(bleft);
00277
00278 if (zbuf == NULL) {
00279 errn = FENOMEMY;
00280 goto handle_exception;
00281 }
00282 else
00283 (void) memset((void *) zbuf, 0, (size_t)bleft);
00284 }
00285
00286 switch (cup->ufs) {
00287
00288 case FS_FDC:
00289 ret = XRCALL(cup->ufp.fdc, writertn)
00290 cup->ufp.fdc, WPTR2BP(zbuf),
00291 bleft, &fst, FULL, (int *)&zero);
00292
00293 if (ret != bleft)
00294 errn = fst.sw_error;
00295
00296 break;
00297
00298 case STD:
00299 ret = fwrite((void *) zbuf, 1, bleft,
00300 cup->ufp.std);
00301
00302 if (ret != bleft)
00303 errn = errno;
00304
00305 break;
00306
00307 default:
00308 errn = FEINTUNK;
00309 break;
00310
00311 }
00312
00313
00314
00315 if (zbuf != &zero)
00316 free(zbuf);
00317 }
00318 }
00319
00320 if (errn != 0)
00321 goto handle_exception;
00322
00323 out_a_here:
00324
00325
00326
00327 if (cilist->iostat_spec != NULL)
00328 *(cilist->iostat_spec) = errn;
00329
00330 STMT_END(cup, TF_WRITE, NULL, css);
00331
00332
00333
00334 return (retval);
00335
00336
00337
00338
00339
00340
00341 handle_exception:
00342
00343 retval = IO_ERR;
00344
00345 if (! cilist->errflag && ! cilist->iostatflg)
00346 _ferr(css, errn, errarg);
00347
00348 if (cup == NULL)
00349 goto out_a_here;
00350
00351 goto finalization;
00352 }