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 #pragma ident "@(#) libf/fio/readc.c 92.3 06/21/99 10:37:55" 00039 00040 /* 00041 * read characters 00042 */ 00043 00044 #include <errno.h> 00045 #include <foreign.h> 00046 #include <liberrno.h> 00047 #include "fio.h" 00048 00049 #define BLANK (long) ' ' 00050 00051 #define ERET(err) { \ 00052 chars = 0; \ 00053 errn = err; \ 00054 goto done; \ 00055 } 00056 00057 static void __READC(); 00058 00059 /* 00060 * Read characters, full record mode 00061 */ 00062 00063 void 00064 READC( 00065 _f_int *unump, 00066 _f_int *uda, 00067 _f_int *charsp, 00068 _f_int *status ) 00069 { 00070 __READC(FULL, unump, uda, charsp, status); 00071 00072 return; 00073 } 00074 00075 /* 00076 * Read characters, partial record mode 00077 */ 00078 00079 void 00080 READCP( 00081 _f_int *unump, 00082 _f_int *uda, 00083 _f_int *charsp, 00084 _f_int *status ) 00085 { 00086 __READC(PARTIAL, unump, uda, charsp, status); 00087 00088 return; 00089 } 00090 /* 00091 * Read characters, full or partial record mode; 00092 * 00093 * The READ/READP interface does not advance past logical endfile 00094 * records. 00095 */ 00096 static void 00097 __READC( 00098 int fulp, 00099 _f_int *unump, 00100 _f_int *uda, 00101 _f_int *charsp, 00102 _f_int *status) 00103 { 00104 register int ret; 00105 register int errn; 00106 long rstat; 00107 long chars; 00108 unum_t unum; 00109 unit *cup; 00110 struct fiostate cfs; 00111 00112 chars = *charsp; 00113 unum = *unump; 00114 errn = 0; 00115 00116 STMT_BEGIN(unum, 0, T_RSF, NULL, &cfs, cup); 00117 /* 00118 * If not connected, do an implicit open. 00119 */ 00120 if (cup == NULL) { 00121 int ostat; 00122 00123 cup = _imp_open(&cfs, SEQ, FMT, unum, 1, &ostat); 00124 00125 if (cup == NULL) 00126 ERET(ostat); 00127 } 00128 00129 if (!cup->ok_rd_seq_fmt) { 00130 errn = _get_mismatch_error(1, T_RSF, cup, &cfs); 00131 ERET(errn); 00132 } 00133 00134 cup->uwrt = 0; 00135 00136 ret = _frch(cup, (long *) uda, chars, fulp, &rstat ); 00137 00138 if ( ret == IOERR ) { 00139 if (errno == FETAPUTE) { 00140 /* This should be fixed, so that chars */ 00141 /* returns the amount of data read */ 00142 errn = 4; 00143 } 00144 else if (errno > 5) { 00145 chars = 0; 00146 errn = errno; 00147 } 00148 else{ 00149 chars = 0; 00150 00151 /* Map system errnos 1-4 to library */ 00152 /* errnos. Otherwise, we would lose them. */ 00153 switch (errno) { 00154 case 1: 00155 errn = FEKLUDG1; 00156 break; 00157 case 2: 00158 errn = FEKLUDG2; 00159 break; 00160 case 3: 00161 errn = FEKLUDG3; 00162 break; 00163 case 4: 00164 errn = FEKLUDG4; 00165 break; 00166 } 00167 } 00168 goto done; 00169 } 00170 00171 if (ret < chars) 00172 (void) _memwset(&uda[ret], BLANK, chars - ret); 00173 00174 if ( rstat == EOR ) { 00175 cup->uend = BEFORE_ENDFILE; 00176 errn = 0; /* EOR */ 00177 if ( ret == 0 ) 00178 errn = 1; /* NULL record */ 00179 chars = ret; /* number of characters read */ 00180 } 00181 else if ( rstat == CNT ) { 00182 cup->uend = BEFORE_ENDFILE; 00183 errn = -1; /* CHARACTERS REMAIN in record */ 00184 chars = ret; /* number of characters read */ 00185 } 00186 else if (rstat == EOD) { 00187 errn = 3; /* EOD */ 00188 chars = 0; /* number of characters read */ 00189 } 00190 else { 00191 cup->uend = PHYSICAL_ENDFILE; 00192 errn = 2; /* EOF */ 00193 chars = 0; /* number of characters read */ 00194 } 00195 00196 done: 00197 00198 *charsp = chars; 00199 *status = errn; 00200 00201 STMT_END(cup, TF_READ, NULL, &cfs); 00202 00203 return; 00204 }