Changeset bcf71ac in tol for tol/bbasic/sys.cpp
- Timestamp:
- May 28, 2010, 11:47:00 AM (16 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- af1369e
- Parents:
- d74c90b
- File:
-
- 1 edited
-
tol/bbasic/sys.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/bbasic/sys.cpp
rd74c90b rbcf71ac 995 995 //-------------------------------------------------------------------- 996 996 //Opens a file and locks it 997 //If cannot do it then sleeps and retries again until time is out 998 FILE* FOpenAndLock( 997 static 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 1014 FILE* BSys::FOpenAndLock( 999 1015 const char *filename, 1000 1016 const char *mode, … … 1004 1020 { 1005 1021 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 } 1006 1049 return(fil); 1007 1050 } 1008 1051 1009 1052 //-------------------------------------------------------------------- 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 1054 bool 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.
