/*--------------------------------------------------------------------------*/ int GetSwapStatus(int Id) { int fd1; fd1 = (Id != -1) ? Min(Max(Id,0),GetMaximumFileOpenedInScilab()-1) : GetCurrentFileId() ; if ( fd1 != -1 ) return(ScilabFileList[fd1].ftswap); return(0); }
/*--------------------------------------------------------------------------*/ void C2F(mclose) (int *fd, double *res) { int fd1 = -1; *res = 0.0; switch ( *fd ) { case ALL_FILES_DESCRIPTOR : /* closing all opened files */ for ( fd1 = 0; fd1 < GetMaximumFileOpenedInScilab(); fd1++) { FILE* stream = GetFileOpenedInScilab(fd1) ; if ( stream ) { int res1 = 1; res1 = fclose( stream ); // this function previously called ferror on a just before fclosed FILE* that could lead to crash at exit, depending on libc implementation. if (res1 != 0) { *res = 1; } C2F(delfile)(&fd1); /* bug 3897 */ /* initialize file ID */ SetCurrentFileId(-1); } } break; default : { fd1 = (*fd == -1 ) ? GetCurrentFileId() : Min(Max(*fd, 0), GetMaximumFileOpenedInScilab() - 1); if ( fd1 != -1 ) { if ( GetFileOpenedInScilab(fd1) ) { int prevId = -1; if (fclose(GetFileOpenedInScilab(fd1))) { *res = (double)ferror(GetFileOpenedInScilab(fd1)); } C2F(delfile)(&fd1); /* bug 3897 */ /* set as current file previous opened file if exists */ prevId = GetPreviousFileId(); if ( GetFileOpenedInScilab(prevId) ) { SetCurrentFileId(prevId); } } else { *res = 0.0; if (getWarningMode()) { sciprint(_("%s: Cannot close file whose descriptor is %d: File is not active.\n"), "mclose", fd1); } } } else { *res = -1.0; if (getWarningMode()) { sciprint(_("%s: Cannot close file whose descriptor is %d: No file to close.\n"), "mclose", fd1); } } } } }