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/dsetpos.c 92.1 06/18/99 10:21:14"
00039
00040 #include <foreign.h>
00041 #include <errno.h>
00042 #include <liberrno.h>
00043 #include "fio.h"
00044
00045
00046
00047
00048 int
00049 _setpos(
00050 FIOSPTR css,
00051 unit *cup,
00052 int *pa,
00053 int len)
00054 {
00055 int ret;
00056 int pos;
00057 long offset;
00058 int whence;
00059 int retstat;
00060 struct fdinfo *fio;
00061 int fp_parm[2];
00062
00063 retstat = 0;
00064
00065
00066
00067
00068 WAITIO(cup, return(cup->uffsw.sw_error));
00069
00070 cup->urecpos = 0;
00071 if (cup->uwrt) {
00072 if (cup->utrunc) {
00073 ret = _unit_trunc(cup);
00074 if (ret != 0)
00075 return(ret);
00076 }
00077 cup->uwrt = 0;
00078 }
00079
00080
00081
00082
00083 pos = pa[0];
00084 switch( cup->ufs ) {
00085
00086 case FS_TEXT:
00087 case STD:
00088 if ( pos == -1 || pos == -2 ) {
00089 offset = 0;
00090 whence = 2;
00091 }
00092 else {
00093 offset = pos;
00094 whence = 0;
00095 }
00096
00097
00098
00099
00100 if ( cup->ufmt == NO )
00101 offset = _dshiftl(offset, offset, 3);
00102
00103 ret = fseek(cup->ufp.std, offset, whence);
00104 if (ret != 0)
00105 return(errno);
00106
00107 break;
00108
00109 case FS_FDC:
00110 fio = cup->ufp.fdc;
00111
00112 if ((cup->uflagword & FFC_SEEKA) ||
00113 ((pos == -1 || pos == -2) && (cup->uflagword & FFC_SEEKE))){
00114
00115 if ( pos == -1 || pos == -2 ) {
00116
00117 if ( XRCALL(fio, seekrtn) fio, 0, 2,
00118 &cup->uffsw) < 0)
00119 return(cup->uffsw.sw_error);
00120
00121 }
00122 else {
00123 #if defined(__mips) || defined(_LITTLE_ENDIAN)
00124
00125
00126
00127
00128
00129
00130 return(FDC_ERR_NOSUP);
00131 #else
00132
00133
00134
00135
00136
00137 if ( cup->ufmt == YES )
00138 fp_parm[0] = _dshiftl(pos, pos, 3);
00139 else
00140 fp_parm[0] = _dshiftl(pos, pos, 6);
00141
00142
00143
00144
00145 if ( fp_parm[0] < 0 )
00146 return(FEBIOISP);
00147
00148 fp_parm[1] = 0;
00149 ret = XRCALL(fio, posrtn) fio,
00150 FP_BSEEK, fp_parm, 2, &cup->uffsw);
00151
00152 if (ret < 0)
00153 return(cup->uffsw.sw_error);
00154 #endif
00155 }
00156 }
00157 else {
00158
00159
00160
00161
00162 if( XRCALL(fio, posrtn)
00163 fio, FP_SETPOS, pa, len, &cup->uffsw) < 0)
00164 return(cup->uffsw.sw_error);
00165 }
00166
00167 break;
00168
00169 case FS_AUX:
00170 return(FEMIXAUX);
00171 default:
00172 return(FEINTFST);
00173 }
00174
00175
00176
00177 if (pos == -1 && len == 1) {
00178 if (cup->ufs != FS_FDC)
00179 cup->uend = LOGICAL_ENDFILE;
00180 else {
00181
00182
00183
00184
00185
00186 if ((cup->uflagword & FFC_WEOF) == 0)
00187 cup->uend = LOGICAL_ENDFILE;
00188 else {
00189 off_t fbytepos;
00190
00191 switch (fio->class) {
00192 case CLASS_COS:
00193
00194
00195
00196
00197
00198
00199
00200
00201 fbytepos = XRCALL(fio, seekrtn) fio, 0,
00202 1, &cup->uffsw);
00203 if (fbytepos > 0)
00204 cup->uend = PHYSICAL_ENDFILE;
00205 else
00206 cup->uend = LOGICAL_ENDFILE;
00207 break;
00208 default:
00209 return(FEBIOSNT);
00210 }
00211 }
00212 }
00213 }
00214 else
00215
00216
00217
00218
00219 cup->uend = BEFORE_ENDFILE;
00220 return(OK);
00221 }