flush.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 static char USMID[] = "@(#) libf/fio/flush.c 92.3 11/16/99 15:43:33";
00039
00040 #include <stdio.h>
00041 #include <errno.h>
00042 #include <liberrno.h>
00043 #include "fio.h"
00044 #ifdef _ABSOFT
00045 #include "ac_sysdep.h"
00046 #else
00047
00048 #if defined(_LITTLE_ENDIAN)
00049 #ifndef FILE_FLAG
00050 #define FILE_FLAG(__f) (__f)->_flag
00051 #endif
00052
00053 #ifndef IOWRT
00054 #define IOWRT = _IO_CURRENTLY_PUTTING
00055 #endif
00056
00057 #else
00058
00059 #ifndef FILE_FLAG
00060 #define FILE_FLAG(__f) (__f)->_flag
00061 #endif
00062
00063 #endif
00064
00065 #endif
00066
00067 #define FLUSH_ERROR(_ERROR_) { \
00068 if (statp) \
00069 *rstat = _ERROR_; \
00070 else \
00071 _ferr(&cfs, _ERROR_); \
00072 }
00073
00074 #define FLUSH_ERROR1(_ERROR_, _DATA_) { \
00075 if (statp) { \
00076 *rstat = _ERROR_; \
00077 goto flush_done; \
00078 } \
00079 else \
00080 _ferr(&cfs, _ERROR_, _DATA_);\
00081 }
00082
00083
00084
00085
00086
00087
00088 #define FLUSH_OK 0
00089 #define NOT_SUPPORTED (-1)
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 void
00101 #ifdef _UNICOS
00102 FLUSH(
00103 #elif defined(__mips) || defined(_LITTLE_ENDIAN)
00104 __flush_f90(
00105 #else
00106 flush_(
00107 #endif
00108 _f_int *unump,
00109 _f_int *istat
00110 )
00111 {
00112 register short statp;
00113 int *rstat;
00114 int errn;
00115 register unum_t unum;
00116 unit *cup;
00117 struct fiostate cfs;
00118
00119 unum = *unump;
00120 statp =
00121 #ifdef _UNICOS
00122 (_numargs() >= 2)
00123 #else
00124 (istat != NULL)
00125 #endif
00126 ? 1 : 0;
00127
00128 rstat = statp ? istat : &errn;
00129 *rstat = FLUSH_OK;
00130
00131 STMT_BEGIN(unum, 0, T_FLUSH, NULL, &cfs, cup);
00132
00133 if (cup == NULL) {
00134 if (!GOOD_UNUM(unum))
00135 errn = FEIVUNIT;
00136 else {
00137
00138
00139
00140 if (RSVD_UNUM(unum))
00141 goto flush_done;
00142
00143 errn = FENOTOPN;
00144 }
00145
00146 FLUSH_ERROR1(errn, unum);
00147 }
00148
00149 if (cup->useq == 0) {
00150 *rstat = NOT_SUPPORTED;
00151 goto flush_done;
00152 }
00153
00154 if ( ! cup->uwrt)
00155 goto flush_done;
00156
00157 switch (cup->ufs) {
00158 struct ffsw fstat;
00159
00160 case FS_FDC:
00161 if (__ffflush(cup->ufp.fdc, &fstat) < 0)
00162 FLUSH_ERROR(fstat.sw_error);
00163 break;
00164
00165 case FS_TEXT:
00166 case STD:
00167 #if !defined(_LITTLE_ENDIAN)
00168 if (FILE_FLAG(cup->ufp.std) & _IOWRT)
00169 if (fflush(cup->ufp.std) == EOF)
00170 FLUSH_ERROR(errno);
00171 #endif
00172 break;
00173
00174 default:
00175 *rstat = NOT_SUPPORTED;
00176 }
00177
00178 flush_done:
00179 STMT_END(cup, T_FLUSH, NULL, &cfs);
00180
00181 return;
00182 }
00183
00184 #if defined(_LITTLE_ENDIAN)
00185 void
00186 flush_( _f_int *unump)
00187 {
00188 _f_int istt;
00189 __flush_f90(unump, &istt);
00190 return;
00191 }
00192 #endif
00193
00194 #if defined(__mips) || defined(_LITTLE_ENDIAN)
00195
00196
00197
00198
00199
00200
00201 void
00202 flush_stat_8_(
00203 _f_int8 *unump,
00204 _f_int8 *istat)
00205 {
00206 _f_int unum;
00207 _f_int istt;
00208
00209 unum = *unump;
00210 __flush_f90(&unum, &istt);
00211 *istat = (_f_int8) istt;
00212
00213 return;
00214 }
00215
00216 void
00217 flush_stat_4_(
00218 _f_int *unump,
00219 _f_int *istat)
00220 {
00221 __flush_f90(unump, istat);
00222
00223 return;
00224 }
00225
00226 void
00227 flush_stat_4_8_(
00228 _f_int *unump,
00229 _f_int8 *istat)
00230 {
00231 _f_int istt;
00232
00233 __flush_f90(unump, &istt);
00234 *istat = (_f_int8) istt;
00235 return;
00236 }
00237
00238 void
00239 flush_stat_8_4_(
00240 _f_int8 *unump,
00241 _f_int *istat)
00242 {
00243 _f_int unum;
00244
00245 unum = *unump;
00246 __flush_f90(&unum, istat);
00247 return;
00248 }
00249
00250 void
00251 flush_f90_4_( _f_int *unump)
00252 {
00253 _f_int istat;
00254
00255 __flush_f90(unump, &istat);
00256 return;
00257 }
00258
00259 void
00260 flush_f90_8_( _f_int8 *unump)
00261 {
00262 _f_int istat;
00263 _f_int unum;
00264
00265 unum = *unump;
00266 __flush_f90(&unum, &istat);
00267 return;
00268 }
00269
00270 #endif