Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001, Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 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 /* LITTLE_ENDIAN */ 00058 00059 #ifndef FILE_FLAG 00060 #define FILE_FLAG(__f) (__f)->_flag 00061 #endif 00062 00063 #endif /* LITTLE_ENDIAN */ 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 * FLUSH return statuses. 00086 */ 00087 00088 #define FLUSH_OK 0 /* successful flush */ 00089 #define NOT_SUPPORTED (-1) /* this unit does not support FLUSH */ 00090 00091 /* 00092 * FLUSH This routine writes to the underlying file any buffered 00093 * data for a Fortran file. FLUSH does not alter the file 00094 * position or state of the unit in any other way. 00095 * 00096 * FLUSH is an intrinsic, and the Fortran compiler will always pass 00097 * a NULL argument for the istat argument if it is not provided on 00098 * the CALL to FLUSH. 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, /* Fortran unit number */ 00109 _f_int *istat /* Optional error status parameter */ 00110 ) 00111 { 00112 register short statp; /* 1 if istat parameter passed */ 00113 int *rstat; /* Pointer to return status word */ 00114 int errn; /* Error status */ 00115 register unum_t unum; /* unit number */ 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; /* Assume FLUSH works */ 00130 00131 STMT_BEGIN(unum, 0, T_FLUSH, NULL, &cfs, cup); /* lock the unit */ 00132 00133 if (cup == NULL) { 00134 if (!GOOD_UNUM(unum)) 00135 errn = FEIVUNIT; 00136 else { 00137 /* 00138 * Ignore FLUSH on unopened reserved unit. 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) { /* If file opened for direct access */ 00150 *rstat = NOT_SUPPORTED; 00151 goto flush_done; 00152 } 00153 00154 if ( ! cup->uwrt) /* If not writing, do nothing */ 00155 goto flush_done; 00156 00157 switch (cup->ufs) { 00158 struct ffsw fstat; /* ffflush() status */ 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 } /* switch */ 00177 00178 flush_done: 00179 STMT_END(cup, T_FLUSH, NULL, &cfs); /* unlock the unit */ 00180 00181 return; 00182 } 00183 00184 #if defined(_LITTLE_ENDIAN) 00185 void 00186 flush_( _f_int *unump) 00187 { 00188 _f_int istt; /* Optional error status is present */ 00189 __flush_f90(unump, &istt); 00190 return; 00191 } 00192 #endif 00193 00194 #if defined(__mips) || defined(_LITTLE_ENDIAN) 00195 /* istat receives: 00196 * 0 - on normal return, 00197 * -1 - if flush is not supported for this unit, 00198 * +n - a positive error number if an error is encountered. 00199 * If istat is not provided, any error results in program abort. 00200 */ 00201 void 00202 flush_stat_8_( 00203 _f_int8 *unump, /* Fortran unit number */ 00204 _f_int8 *istat) /* Optional error status present */ 00205 { 00206 _f_int unum; /* Fortran unit number */ 00207 _f_int istt; /* Optional error status is present*/ 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, /* Fortran unit number */ 00219 _f_int *istat) /* Optional error status present */ 00220 { 00221 __flush_f90(unump, istat); 00222 00223 return; 00224 } 00225 00226 void 00227 flush_stat_4_8_( 00228 _f_int *unump, /* Fortran unit number */ 00229 _f_int8 *istat) /* Optional error status present */ 00230 { 00231 _f_int istt; /* Optional error status is present*/ 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, /* Fortran unit number */ 00241 _f_int *istat) /* Optional error status present */ 00242 { 00243 _f_int unum; /* Fortran unit number */ 00244 00245 unum = *unump; 00246 __flush_f90(&unum, istat); 00247 return; 00248 } 00249 00250 void 00251 flush_f90_4_( _f_int *unump) /* Fortran unit number */ 00252 { 00253 _f_int istat; /* status word */ 00254 00255 __flush_f90(unump, &istat); 00256 return; 00257 } 00258 00259 void 00260 flush_f90_8_( _f_int8 *unump) /* Fortran unit number */ 00261 { 00262 _f_int istat; /* status word */ 00263 _f_int unum; /* Fortran unit number */ 00264 00265 unum = *unump; 00266 __flush_f90(&unum, &istat); 00267 return; 00268 } 00269 00270 #endif /* __mips or _LITTLE_ENDIAN */