cls.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 #pragma ident "@(#) libf/fio/cls.c 92.2 06/18/99 18:41:40"
00039
00040 #include <stdio.h>
00041 #include <cray/nassert.h>
00042 #include "fio.h"
00043 #include "f90io.h"
00044 #include "fmt.h"
00045 #ifdef _CRAYMPP
00046 #include <stdarg.h>
00047 #endif
00048
00049
00050
00051
00052
00053
00054
00055 #ifdef _UNICOS
00056 #pragma _CRI duplicate _CLS as $CLS
00057 #endif
00058 #ifdef _CRAYMPP
00059 _CLS (
00060 _f_int *unump,
00061 _f_int *iostat,
00062 int *err,
00063 ...
00064 )
00065 #else
00066 _CLS (
00067 _f_int *unump,
00068 _f_int *iostat,
00069 int *err,
00070 _fcd status
00071 )
00072 #endif
00073 {
00074 #ifdef _CRAYMPP
00075 va_list args;
00076 _fcd status;
00077 #endif
00078 register int csta;
00079 register int errn;
00080 int errflag;
00081 long fstrlen;
00082 char *fstr;
00083 plock_t *lockp;
00084 register unum_t unum;
00085 unit *cup;
00086 struct fiostate cfs;
00087 static char keep[] = "KEEP";
00088 static char delete[] = "DELETE";
00089
00090 int _string_cmp();
00091
00092 OPENLOCK();
00093
00094 unum = *unump;
00095
00096 STMT_BEGIN(unum, 0, T_CLOSE, NULL, &cfs, cup);
00097
00098 errflag = (iostat != NULL ? _UIOSTF : 0) |
00099 ( err != NULL ? _UERRF : 0);
00100 errn = 0;
00101 csta = CLST_UNSPEC;
00102
00103
00104
00105 #ifdef _CRAYMPP
00106 va_start(args, err);
00107 status = va_arg(args, _fcd);
00108 va_end(args);
00109 #endif
00110 fstr = _fcdtocp(status);
00111 fstrlen = _fcdlen (status);
00112
00113 if (fstr != NULL) {
00114 if (_string_cmp( keep, fstr, fstrlen))
00115 csta = CLST_KEEP;
00116 else if(_string_cmp(delete, fstr, fstrlen))
00117 csta = CLST_DELETE;
00118 else
00119 errn = FECLSTAT;
00120 }
00121
00122
00123
00124 if (!GOOD_UNUM(unum) || RSVD_UNUM(unum) || cup == NULL) goto done;
00125
00126 cup->uflag = errflag;
00127
00128 if (csta == CLST_KEEP && cup->uscrtch)
00129 errn = FECLSTIV;
00130
00131 lockp = &cup->uiolock;
00132
00133 if (errn == 0)
00134 errn = _unit_close(cup, csta, &cfs);
00135
00136
00137
00138
00139
00140
00141 MEM_UNLOCK(lockp);
00142
00143 done:
00144 OPENUNLOCK();
00145
00146 if (iostat != NULL)
00147 *iostat = errn;
00148
00149 if ((errn != 0) && (errflag == 0))
00150 _ferr(&cfs, errn);
00151
00152 STMT_END((unit *)NULL, T_CLOSE, NULL, &cfs);
00153
00154 errn = (errn != 0) ? IO_ERR : IO_OKAY;
00155
00156 return(CFT77_RETVAL(errn));
00157 }
00158
00159
00160
00161
00162 int
00163 _CLOSE(struct close_spec_list *c)
00164 {
00165 assert ( c->version == 0 );
00166
00167 return(_CLS(c->unit, c->iostat, (int *)c->err, c->status));
00168 }