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/rewind.c 92.1 06/21/99 10:37:55"
00039
00040 #include <errno.h>
00041 #include <foreign.h>
00042 #include <liberrno.h>
00043 #include "fio.h"
00044
00045
00046
00047
00048
00049 #ifdef _UNICOS
00050 #pragma _CRI duplicate _REWF as $REWF
00051 #endif
00052
00053 int
00054 _REWF(
00055 _f_int *unump,
00056 _f_int *iostat,
00057 int errf)
00058 {
00059 register int errn;
00060 register unum_t unum;
00061 unit *cup;
00062 struct ffsw fst;
00063 struct fiostate cfs;
00064
00065 errn = 0;
00066 unum = *unump;
00067
00068 STMT_BEGIN(unum, 0, T_REWIND, NULL, &cfs, cup);
00069
00070 if (!GOOD_UNUM(unum)) {
00071 errn = FEIVUNIT;
00072 goto rewind_done;
00073 }
00074
00075
00076
00077
00078 if (cup == NULL)
00079 goto rewind_done;
00080
00081 if (cup->useq == 0) {
00082 errn = FERWNDIV;
00083 goto rewind_done;
00084 }
00085
00086
00087
00088
00089 WAITIO(cup, {errn = cup->uffsw.sw_error;});
00090
00091 if (errn != 0)
00092 goto rewind_done;
00093
00094 if (cup->pnonadv) {
00095 if (cup->uwrt) {
00096
00097 errn = _nonadv_endrec(&cfs, cup);
00098
00099 if (errn != 0)
00100 goto rewind_done;
00101 }
00102 cup->pnonadv = 0;
00103 }
00104
00105 cup->uend = BEFORE_ENDFILE;
00106 cup->ulastyp = DT_NONE;
00107 cup->urecpos = 0;
00108
00109 if ( cup->uwrt ) {
00110 if (cup->utrunc) {
00111
00112
00113
00114
00115 errn = _unit_trunc(cup);
00116
00117 if (errn != 0)
00118 goto rewind_done;
00119 }
00120 cup->uwrt = 0;
00121 }
00122
00123
00124
00125
00126 switch (cup->ufs) {
00127
00128 case FS_FDC:
00129 errn = XRCALL(cup->ufp.fdc, seekrtn) cup->ufp.fdc, 0, 0, &fst);
00130 if (errn < 0)
00131 errn = fst.sw_error;
00132 break;
00133
00134 case FS_TEXT:
00135 case STD:
00136
00137
00138
00139 if (!cup->useek) {
00140 errn = FENORWPI;
00141 goto rewind_done;
00142 }
00143
00144 errn = fseek(cup->ufp.std, 0, 0);
00145
00146 if (errn != 0)
00147 errn = errno;
00148 break;
00149
00150 case FS_BIN:
00151 cup->uwaddr = 1;
00152 break;
00153
00154 case FS_AUX:
00155 errn = FEMIXAUX;
00156
00157 break;
00158
00159 default:
00160 errn = FEINTFST;
00161 break;
00162 }
00163
00164 rewind_done:
00165 if (iostat != NULL)
00166 *iostat = errn;
00167 else
00168 if (errn != 0 && (errf == 0))
00169 _ferr(&cfs, errn, unum);
00170
00171
00172 STMT_END(cup, T_REWIND, NULL, &cfs);
00173
00174 errn = (errn != 0) ? IO_ERR : IO_OKAY;
00175
00176 return(CFT77_RETVAL(errn));
00177 }