Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
writec.c
Go to the documentation of this file.
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/writec.c   92.3    06/21/99 10:37:55"
00039 
00040 /*
00041  *      write characters
00042  */
00043 
00044 #include <errno.h>
00045 #include <foreign.h>
00046 #include <liberrno.h>
00047 #include "fio.h"
00048 
00049 #define STATUS 4        /* argument number for optional status parameter */
00050  
00051 static void __WRITEC();
00052 
00053 /*
00054  *      write characters, full record mode
00055  */
00056 void
00057 WRITEC(
00058         _f_int  *unump,
00059         _f_int  *uda,
00060         _f_int  *charsp,
00061         _f_int  *status)
00062 {
00063         _f_int  *statp;
00064 
00065         statp   = (_numargs() < STATUS) ? NULL : status;
00066 
00067         __WRITEC(FULL, unump, uda, charsp, statp);
00068 
00069         return;
00070 }
00071 
00072 /*
00073  *      write characters, partial record mode
00074  */
00075 void
00076 WRITECP(
00077         _f_int  *unump,
00078         _f_int  *uda,
00079         _f_int  *charsp,
00080         _f_int  *status)
00081 {
00082         _f_int  *statp;
00083 
00084         statp   = (_numargs() < STATUS) ? NULL : status;
00085 
00086         __WRITEC(PARTIAL, unump, uda, charsp, statp);
00087 
00088         return;
00089 }
00090 
00091 /*
00092  *   Write characters, full or partial record mode
00093  */
00094 static void
00095 __WRITEC(
00096         int     fulp,
00097         _f_int  *unump,
00098         _f_int  *uda,
00099         _f_int  *charsp,
00100         _f_int  *status)
00101 {
00102         register int    ret;
00103         register int    errn;
00104         long            chars;
00105         unum_t          unum;
00106         unit            *cup;
00107         struct fiostate cfs;
00108 
00109         chars   = *charsp;
00110         unum    = *unump;
00111         errn    = 0;
00112 
00113         STMT_BEGIN(unum, 0, T_WSF, NULL, &cfs, cup);
00114 /*
00115  *      If not connected, do an implicit open.  
00116  */
00117         if (cup == NULL) {
00118                 int     ostat;
00119 
00120                 cup     = _imp_open(&cfs, SEQ, FMT, unum, (status != NULL),
00121                                 &ostat);
00122 
00123                 if (cup == NULL) {
00124                         errn    = ostat;
00125                         goto done;
00126                 }
00127         }
00128 
00129         if (!cup->ok_wr_seq_fmt) {
00130                 errn    = _get_mismatch_error(1, T_WSF, cup, &cfs);
00131                 goto done;
00132         }
00133 
00134         cup->uwrt       = 1;
00135 
00136         if (cup->uend) {
00137                 /*
00138                  * If positioned after an endfile, and the file does not
00139                  * support multiple endfiles, a write is invalid.
00140                  */
00141                 if (!cup->umultfil && !cup->uspcproc) {
00142                         errn    = FEWRAFEN;
00143                         goto done;
00144                 }
00145                 /*
00146                  * If a logical endfile record had just been read,
00147                  * replace it with a physical endfile record before
00148                  * starting the current data record.
00149                  */
00150                 if ((cup->uend == LOGICAL_ENDFILE) && !(cup->uspcproc)) {
00151                         if (XRCALL(cup->ufp.fdc, weofrtn)cup->ufp.fdc,
00152                                 &cup->uffsw) < 0) {
00153                                 errn    = cup->uffsw.sw_error;
00154                                 goto done;
00155                         }
00156                 }
00157                 cup->uend       = BEFORE_ENDFILE;
00158         }
00159 
00160         ret     = _fwch(cup, (long *) uda, chars, fulp);
00161 
00162         if ( ret == IOERR ) {
00163                 errn    = errno;
00164                 goto done;
00165         }
00166 
00167         if (status != NULL)
00168                 *status = 0;
00169 
00170 done:
00171         if (errn != 0) {
00172                 if (status == NULL)
00173                         _ferr(&cfs, errn);      
00174                 else
00175                         *status = errn;
00176         }
00177 
00178         STMT_END(cup, TF_WRITE, NULL, &cfs);
00179 
00180         return;
00181 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines