Changeset bcf71ac in tol for tol/bbasic/sys.cpp


Ignore:
Timestamp:
May 28, 2010, 11:47:00 AM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
af1369e
Parents:
d74c90b
Message:

Fixes #546

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2199 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/bbasic/sys.cpp

    rd74c90b rbcf71ac  
    995995//--------------------------------------------------------------------
    996996//Opens a file and locks it
    997 //If cannot do it then sleeps and retries again until time is out
    998 FILE* FOpenAndLock(
     997static FILE* fOpenAndLock(
     998   const char *filename,
     999   const char *mode)
     1000//--------------------------------------------------------------------
     1001{
     1002  FILE* fil=NULL;
     1003  #ifdef _MSC_VER
     1004  fopen_s(&fil, filename, mode);
     1005  #else
     1006  fil = fopen(filename, mode);
     1007  #endif
     1008  return(fil);
     1009}
     1010
     1011//--------------------------------------------------------------------
     1012//Opens a file and locks it
     1013//If doesn't can do it then sleeps and retries again until time is out
     1014FILE* BSys::FOpenAndLock(
    9991015   const char *filename,
    10001016   const char *mode,
    … …  
    10041020{
    10051021  FILE* fil=NULL;
     1022  double sleep = 1.0;
     1023  double sleepCum = 0.0;
     1024  int tryNum = 0;
     1025  bool ok = false;
     1026  do
     1027  {
     1028    #ifdef _MSC_VER
     1029    ok = fopen_s(&fil, filename, mode)==0;
     1030    #else
     1031    fil = fopen(filename, mode);
     1032    ok = fil!=NULL;
     1033    #endif
     1034    if(!ok)
     1035    {
     1036      fil = NULL;
     1037      BSys::SleepMilliSeconds((unsigned int)sleep);
     1038      sleepCum += sleep;
     1039      sleep = floor(1.1*sleep)+(1+timeOutInMilliseconds/100);
     1040      tryNum++;
     1041      Warning(BText("[BSys::FOpenAndLock] Retraying to open locked file ")+filename+" for "+tryNum+"-th time\n");
     1042    }
     1043  } while(!fil && (sleepCum<timeOutInMilliseconds));
     1044  if(!fil && errorMessage && errorMessage[0])
     1045  {
     1046    Error(BText("Cannot open file ")+filename+" in mode "+mode+"\n"+
     1047          errorMessage);
     1048  }
    10061049  return(fil);
    10071050}
    10081051
    10091052//--------------------------------------------------------------------
    1010 //Unlocks a file and close it
    1011 i FUnlockAndClose(FILE* file)
    1012 //--------------------------------------------------------------------
    1013 {
    1014   FILE* fil=NULL;
    1015   return(fil);
    1016 }
     1053//Unlocks a file and closes it
     1054bool BSys::FUnlockAndClose(FILE* file, const char *filename)
     1055//--------------------------------------------------------------------
     1056{
     1057  if(fclose(file))
     1058  {
     1059    Error(BText("Cannot close file ")+filename);
     1060    return(false);
     1061  }
     1062  return(true);
     1063}
Note: See TracChangeset for help on using the changeset viewer.