endfile.c
Go to the documentation of this file.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/endfile.c 92.2 06/18/99 18:41:40"
00039
00040 #include <errno.h>
00041 #include <foreign.h>
00042 #include <unistd.h>
00043 #ifdef _ABSOFT
00044 #include "ac_sysdep.h"
00045 #else
00046 #include <sys/unistd.h>
00047 #endif
00048 #include "fio.h"
00049
00050
00051
00052
00053 #ifdef _UNICOS
00054 #pragma _CRI duplicate _EOFW as $EOFW
00055 #endif
00056
00057 int
00058 _EOFW(
00059 _f_int *unump,
00060 _f_int *iostat,
00061 int errf)
00062 {
00063 register unum_t unum;
00064 register int errn;
00065 unit *cup;
00066 struct ffsw fst;
00067 struct fiostate cfs;
00068
00069 #if defined(_ABSOFT) && (defined(TARGET_MAC_OS) || defined(TARGET_NT))
00070 mrwe_check();
00071 #endif
00072
00073 errn = 0;
00074 unum = *unump;
00075
00076 STMT_BEGIN(unum, 0, T_ENDFILE, NULL, &cfs, cup);
00077
00078 if (!GOOD_UNUM(unum)) {
00079 errn = FEIVUNIT;
00080 goto endfile_done;
00081 }
00082
00083
00084
00085
00086 if (cup == NULL)
00087 goto endfile_done;
00088
00089 if (cup->pnonadv) {
00090 if (cup->uwrt) {
00091 errn = _nonadv_endrec(&cfs, cup);
00092 if (errn != 0)
00093 goto endfile_done;
00094 }
00095 cup->pnonadv = 0;
00096 }
00097
00098 cup->urecpos = 0;
00099
00100 if ((cup->uaction & OS_WRITE) == 0) {
00101 errn = FENOWRIT;
00102 goto endfile_done;
00103 }
00104
00105 if (cup->useq == 0) {
00106 errn = FEENDFIV;
00107 goto endfile_done;
00108 }
00109
00110 cup->uwrt = 1;
00111
00112 if (cup->uend && !cup->umultfil && !cup->uspcproc) {
00113 errn = FEENAFEN;
00114 goto endfile_done;
00115 }
00116
00117 switch (cup->ufs) {
00118
00119 case FS_FDC:
00120
00121
00122
00123
00124
00125 if (cup->umultfil) {
00126
00127
00128
00129
00130
00131 if ((cup->uend == LOGICAL_ENDFILE) && !(cup->uspcproc)){
00132 if (XRCALL(cup->ufp.fdc, weofrtn)cup->ufp.fdc,
00133 &fst) < 0) {
00134 errn = fst.sw_error;
00135 goto endfile_done;
00136 }
00137 cup->uend = PHYSICAL_ENDFILE;
00138 }
00139
00140 if (XRCALL(cup->ufp.fdc, weofrtn)cup->ufp.fdc,
00141 &fst) < 0) {
00142 errn = fst.sw_error;
00143 goto endfile_done;
00144 }
00145
00146 cup->uend = PHYSICAL_ENDFILE;
00147 }
00148 else {
00149 if (XRCALL(cup->ufp.fdc, weodrtn)cup->ufp.fdc, &fst) < 0)
00150 errn = fst.sw_error;
00151
00152 cup->uend = LOGICAL_ENDFILE;
00153 }
00154 break;
00155
00156 case FS_TEXT:
00157 case STD:
00158 cup->uend = LOGICAL_ENDFILE;
00159 break;
00160
00161 default:
00162 errn = FEINTFST;
00163 }
00164
00165 endfile_done:
00166 if (iostat != NULL)
00167 *iostat = errn;
00168 else
00169 if (errn != 0 && (errf == 0))
00170 _ferr(&cfs, errn, unum);
00171
00172
00173 STMT_END(cup, T_ENDFILE, NULL, &cfs);
00174
00175 errn = (errn != 0) ? IO_ERR : IO_OKAY;
00176
00177 return(CFT77_RETVAL(errn));
00178 }