1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/*
* $Id: xyclose.c 3172 2010-02-15 08:51:54Z baud $
*/
/*
* Copyright (C) 1990-2010 by CERN/IT/PDP/DM
* All rights reserved
*/
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: xyclose.c,v $ $Revision: 3172 $ $Date: 2010-02-15 09:51:54 +0100 (Mon, 15 Feb 2010) $ CERN/IT/PDP/DM Frederic Hemmer";
#endif /* not lint */
/* xyclose.c Remote File I/O - Close a Fortran Logical Unit */
/*
* C bindings :
*
* rfio_xyclose(int lun, char *chopt, int *irc)
*
* FORTRAN bindings :
*
* XYCLOS(INTEGER*4 LUN, CHARACTER*(*) CHOPT, INTEGER*4 IRC)
*/
#define RFIO_KERNEL 1 /* system part of Remote File I/O */
#include "rfio.h" /* remote file I/O definitions */
#include <stdlib.h>
extern int DLL_DECL switch_close();
int DLL_DECL rfio_xyclose(lun, chopt, irc) /* close a remote fortran logical unit */
int lun;
char *chopt;
int *irc;
{
char buf[LONGSIZE]; /* network command/response buffer */
register char *p=buf; /* buffer pointer */
int status; /* Fortran status */
register int i; /* general purpose index */
INIT_TRACE("RFIO_TRACE");
TRACE(1, "rfio" ,"rfio_xyclose(%d, %s, %x)", lun, chopt, irc);
if (ftnlun[lun] == (RFILE *) NULL) { /* Allocated ? */
TRACE(1, "rfio", "rfio_xyclose: %s", "Bad file number");
END_TRACE();
return(EBADF);
}
/*
* Analyze options
*/
TRACE(2, "rfio", "rfio_xyclose: parsing options: [%s]",chopt);
for (i=0;i< (int)strlen(chopt);i++) {
switch (chopt[i]) {
case ' ': break;
default :
*irc = SEBADFOPT;
END_TRACE();
return(SEBADFOPT);
}
}
*irc = 0;
if (!strcmp(ftnlun[lun]->host, "localhost")) { /* Local file ? */
/* Must be a local file */
*irc=switch_close(&lun);
(void) free((char *)ftnlun[lun]); ftnlun[lun]=(RFILE *) NULL;
END_TRACE();
rfio_errno = 0;
return(*irc);
}
marshall_WORD(p, RFIO_MAGIC);
marshall_WORD(p, RQST_XYCLOS);
TRACE(2,"rfio","rfio_xyclose: writing %d bytes",RQSTSIZE) ;
if (netwrite_timeout(ftnlun[lun]->s,buf,RQSTSIZE,RFIO_CTRL_TIMEOUT) != RQSTSIZE) {
TRACE(2, "rfio" ,"rfio_xyclose: write(): ERROR occured (errno=%d)", errno);
free((char *)ftnlun[lun]); ftnlun[lun]=(RFILE *) NULL;
END_TRACE();
if ( serrno )
return ( serrno ) ;
else
return(errno);
}
p = buf;
TRACE(2, "rfio" ,"rfio_xyclose: reading %d bytes", LONGSIZE);
if (netread_timeout(ftnlun[lun]->s, buf, LONGSIZE, RFIO_CTRL_TIMEOUT) != LONGSIZE) {
TRACE(2, "rfio" ,"rfio_xyclose: read(): ERROR occured (errno=%d)", errno);
free((char *)ftnlun[lun]); ftnlun[lun]=(RFILE *) NULL;
END_TRACE();
if ( serrno )
return ( serrno ) ;
else
return( errno );
}
unmarshall_LONG(p, status);
TRACE(1, "rfio", "rfio_xyclose: return %d ",status);
END_TRACE();
(void) close(ftnlun[lun]->s);
free((char *)ftnlun[lun]); ftnlun[lun]=(RFILE *) NULL;
*irc = status;
rfio_errno = status ;
return(status);
}
/*
* Fortran wrapper
*/
#if (defined(hpux) && !defined(PPU)) || (defined(_AIX) && !defined(EXTNAME))
#define xyclos_ xyclos
#endif /* hpux && !PPU || AIX && !EXTNAME */
#if defined(_WIN32)
void _stdcall XYCLOS(flun, fchopt, fchoptl, firc)
#else
void xyclos_(flun, fchopt, firc, fchoptl)
#endif
int *flun, *firc;
char *fchopt;
int fchoptl;
{
char *chopt; /* xyclos options */
int status; /* xyclos return status */
INIT_TRACE("RFIO_TRACE");
if ((chopt = malloc((unsigned) fchoptl+1)) == NULL) {
*firc = -errno;
END_TRACE();
return;
}
strncpy(chopt, fchopt, fchoptl); chopt[fchoptl] = '\0';
TRACE(1, "rfio", "XYCLOS(%d, %s, %x)", *flun, chopt, firc);
status = rfio_xyclose(*flun, chopt, firc);
if (status) *firc = -status; /* system errors have precedence */
TRACE(1, "rfio", "XYCLOS: status: %d, irc: %d",status,*firc);
END_TRACE();
(void) free(chopt);
return;
}
|