Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
backspace.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/backspace.c        92.1    06/18/99 15:49:57"
00039 
00040 #include <errno.h>
00041 #include <foreign.h>
00042 #include <liberrno.h>
00043 #include "fio.h"
00044 
00045 /*
00046  *      _BACK   Fortran backspace
00047  */
00048 
00049 #if     _CRAY 
00050 #pragma _CRI duplicate _BACK as $BACK   /* For cf77 */
00051 #endif
00052 
00053 int
00054 _BACK(
00055         _f_int  *unump,                 /* Fortran unit number */
00056         _f_int  *iostat,                /* IOSTAT= variable address, or NULL */
00057         int     errf)                   /* 1 if ERR= specifier is present */
00058 {
00059         register int    errn;           /* nonzero when error is encountered */
00060         register unum_t unum;
00061         unit            *cup;
00062         struct fiostate cfs;
00063 
00064         errn    = 0; 
00065         unum    = *unump; 
00066 
00067         STMT_BEGIN(unum, 0, T_BACKSPACE, NULL, &cfs, cup); /* lock the unit */
00068 
00069         if (!GOOD_UNUM(unum)) {
00070                 errn    = FEIVUNIT;     /* Invalid unit number */
00071                 goto backspace_done;
00072         }
00073 
00074 /*
00075  *      BACKSPACE on unopened unit is OK, and does nothing.  For opened units,
00076  *      call the low level backspace routine.
00077  */
00078         if (cup == NULL) 
00079                 goto backspace_done;
00080 
00081         if (cup->pnonadv) {             /* There is a current record */
00082                 if (cup->uwrt) {
00083 
00084                         errn    = _nonadv_endrec(&cfs, cup);
00085 
00086                         if (errn != 0)
00087                                 goto backspace_done;
00088                 }
00089                 cup->pnonadv    = 0;    /* Flag no current record */
00090         }
00091 
00092         errn    = _unit_bksp(cup);
00093 
00094 backspace_done:
00095         if (iostat != NULL)
00096                 *iostat = errn;
00097         else
00098                 if (errn != 0 && (errf == 0))
00099                         _ferr(&cfs, errn, unum);        /* Pass unum to _ferr
00100                                                  * in case of FEIVUNIT error */
00101 
00102         STMT_END(cup, T_BACKSPACE, NULL, &cfs); /* unlock the unit */
00103 
00104         errn    = (errn != 0) ? IO_ERR : IO_OKAY;/* 1 if error; 0 if no error */
00105 
00106         return(CFT77_RETVAL(errn));
00107 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines