Quote Originally Posted by wysota View Post
You'll have to search through available documentation of ostream probably. There should be a way to access the buffer which you can then associate with a file descriptor or file handler or whatever.
So far so good.
I have written a sample to lock a file on windows. On linux there are some problems. Please help me to make the below code work on linux too.

Qt Code:
  1. int main ( )
  2. {
  3. FILE *pFile = NULL;
  4. char *fileName = "Logfile.log";
  5.  
  6. // Open the file in write mode
  7. #ifdef win32
  8. fopen_s(&pFile, fileName ,"r");
  9. #else
  10. pFile = fopen( fileName ,"r");
  11.  
  12. if (!pFile)
  13. {
  14. printf("Error opening file %s!\n", fileName);
  15. exit(1);
  16. }
  17.  
  18. // Lock the file.
  19. #ifdef win32
  20. _lock_file(pFile);
  21. #else
  22. //lock file on linux
  23.  
  24. printf("Locking the file %s.\n", fileName);
  25.  
  26. ifstream ifs( pFile ); //This doesnt work on linux why???
  27. char line[255];
  28. ifs.seekg( 0 );
  29. while( !ifs.eof() )
  30. {
  31. ifs.getline( line, sizeof( line ) );
  32. cout<<line;
  33. }
  34. return 0;
  35. }
To copy to clipboard, switch view to plain text mode 

Thanks