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/fseek.c 92.1 06/18/99 19:52:04"
00039
00040
00041
00042
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
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #include "fio.h"
00090
00091 extern int __fseek_f90(int *u, int *off, int *from);
00092 extern _f_int fseekf90_(_f_int *u, _f_int *off, _f_int *from);
00093 extern _f_int __fseek64_f90(_f_int *u, _f_int8 *off, int *from);
00094 extern _f_int8 fseekf90_8_(_f_int8 *u, _f_int8 *off, int8 *from);
00095 extern _f_int fseekf90_4_8_4_(_f_int *u, _f_int8 *off, int *from);
00096
00097 static _f_int __setpos64( unit *cup, _f_int8 ioff, _f_int whence);
00098
00099 int
00100 __fseek_f90(int *u, int *off, int *from)
00101 {
00102 return fseekf90_(u, off, from);
00103 }
00104
00105 _f_int
00106 fseekf90_(_f_int *u, _f_int *off, _f_int *from)
00107 {
00108 unit *cup;
00109 struct fiostate cfs;
00110 _f_int8 ioff;
00111 unum_t unum;
00112 _f_int rtrn;
00113
00114 unum = *u;
00115 ioff = *off;
00116
00117 STMT_BEGIN( unum, 0, T_SETPOS, NULL, &cfs, cup);
00118
00119
00120 if (cup == NULL)
00121 cup = _imp_open(&cfs, SEQ, UNF, unum, 0, NULL);
00122
00123
00124 if (cup->useq == 0)
00125 _ferr(&cfs, FEBIONDA, "SETPOS");
00126
00127
00128 if (__setpos64(cup, ioff, *from) != 0)
00129 rtrn = errno;
00130 else
00131 rtrn = 0;
00132
00133
00134 STMT_END(cup, T_SETPOS, NULL, &cfs);
00135 return rtrn;
00136 }
00137
00138 _f_int
00139 __fseek64_f90(_f_int *u, _f_int8 *off, int *from)
00140 {
00141 return fseekf90_4_8_4_(u, off, from);
00142 }
00143
00144 _f_int
00145 fseekf90_4_8_4_(_f_int *u, _f_int8 *off, int *from)
00146 {
00147 unit *cup;
00148 struct fiostate cfs;
00149 _f_int8 ioff;
00150 unum_t unum;
00151 _f_int rtrn;
00152
00153 unum = *u;
00154 ioff = *off;
00155
00156
00157 STMT_BEGIN( unum, 0, T_SETPOS, NULL, &cfs, cup);
00158
00159
00160 if (cup == NULL)
00161 cup = _imp_open(&cfs, SEQ, UNF, unum, 0, NULL);
00162
00163 if (cup->useq == 0)
00164 _ferr(&cfs, FEBIONDA, "SETPOS");
00165
00166
00167
00168
00169 if (__setpos64(cup, ioff, *from) != 0)
00170 rtrn=errno;
00171 else
00172 rtrn = 0;
00173 STMT_END(cup, T_SETPOS, NULL, &cfs);
00174 return rtrn;
00175 }
00176
00177 _f_int8
00178 fseekf90_8_(_f_int8 *u, _f_int8 *off, int8 *from)
00179 {
00180 unit *cup;
00181 struct fiostate cfs;
00182 _f_int8 ioff;
00183 unum_t unum;
00184 _f_int rtrn;
00185 _f_int whenc;
00186
00187 unum = *u;
00188 ioff = *off;
00189 whenc = *from;
00190
00191
00192 STMT_BEGIN( unum, 0, T_SETPOS, NULL, &cfs, cup);
00193
00194
00195 if (cup == NULL)
00196 cup = _imp_open(&cfs, SEQ, UNF, unum, 0, NULL);
00197
00198 if (cup->useq == 0)
00199 _ferr(&cfs, FEBIONDA, "SETPOS");
00200
00201
00202
00203
00204 if (__setpos64(cup, ioff, *from) != 0)
00205 rtrn=errno;
00206 else
00207 rtrn = 0;
00208 STMT_END(cup, T_SETPOS, NULL, &cfs);
00209 return rtrn;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 _f_int
00219 __setpos64(
00220 unit *cup,
00221 _f_int8 ioff,
00222 _f_int whence)
00223
00224
00225
00226 {
00227 _f_int ret;
00228 _f_int retstat;
00229 struct fdinfo *fio;
00230 int fp_parm[2];
00231
00232 retstat = 0;
00233
00234
00235 WAITIO(cup, return(cup->uffsw.sw_error));
00236
00237 cup->urecpos = 0;
00238 if (cup->uwrt) {
00239 if (cup->utrunc) {
00240 ret = _unit_trunc(cup);
00241 if (ret != 0)
00242 return(ret);
00243 }
00244 cup->uwrt = 0;
00245 }
00246
00247
00248
00249
00250 switch( cup->ufs ) {
00251
00252 case FS_TEXT:
00253 case STD:
00254
00255
00256
00257
00258 if ( cup->ufmt == NO )
00259 ioff <<= 3;
00260
00261 ret = fseek64(cup->ufp.std, ioff, whence);
00262 if (ret != 0)
00263 return(errno);
00264
00265 break;
00266
00267 case FS_FDC:
00268 fio = cup->ufp.fdc;
00269
00270 if ((cup->uflagword & FFC_SEEKA) ||
00271 (whence==2 && (cup->uflagword & FFC_SEEKE))){
00272
00273 if (whence==2) {
00274
00275 ret = XRCALL(fio, seekrtn) fio, ioff, 2,
00276 &cup->uffsw);
00277 if (ret < 0)
00278 return(cup->uffsw.sw_error);
00279
00280
00281 ret <<= 3;
00282 } else {
00283
00284
00285
00286
00287
00288
00289 return(FDC_ERR_NOSUP);
00290 }
00291 }
00292 else {
00293
00294
00295
00296
00297 ret = XRCALL(fio, posrtn)
00298 fio, FP_SETPOS, &ioff, 1, &cup->uffsw);
00299 }
00300
00301 if (ret < 0)
00302 return(cup->uffsw.sw_error);
00303 ret = 0;
00304 break;
00305
00306 case FS_AUX:
00307 return(FEMIXAUX);
00308 default:
00309 return(FEINTFST);
00310 }
00311
00312
00313 if ((ioff==0 && whence==2) ) {
00314 if (cup->ufs != FS_FDC)
00315 cup->uend = LOGICAL_ENDFILE;
00316 else {
00317
00318
00319
00320
00321
00322 if ((cup->uflagword & FFC_WEOF) == 0)
00323 cup->uend = LOGICAL_ENDFILE;
00324 else {
00325
00326 int fbytepos;
00327
00328 switch (fio->class) {
00329
00330 case CLASS_COS:
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 fbytepos = XRCALL(fio, seekrtn) fio, 0,
00341 1, &cup->uffsw);
00342 if (fbytepos > 0)
00343 cup->uend = PHYSICAL_ENDFILE;
00344 else
00345 cup->uend = LOGICAL_ENDFILE;
00346 break;
00347 default:
00348 return(FEBIOSNT);
00349 }
00350 }
00351 }
00352 } else
00353
00354
00355
00356
00357 cup->uend = BEFORE_ENDFILE;
00358 return(OK);
00359 }