
#ifdef _MSC_VER
// Windows implementation
HANDLE hFile = CreateFile(_T("c:\\file.txt"), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

#else

/* header file for mkdir */
#include <sys/stat.h>
#include <sys/types.h>

// assume Unix
// lock a file on linux
// [hs, 2 july 2010]
// - modified to create a locl file local to the collection [jmt12]
int lock ()
{
  string file_path ("");
  char *collect_dir = getenv ("GSDLCOLLECTDIR");
  if (collect_dir != NULL)
  {
    file_path += collect_dir;
  }
  file_path += "/tmp";
  if ( access( file_path.c_str(), 00 ) != 0 )
  {
    mkdir(file_path.c_str(), 00777);
  }
  file_path += "/gdb.lock";
  ///out << "txt2dbl::lock(" << file_path << ") => ";
  int fd2 = open (file_path.c_str(), O_CREAT|O_RDWR, 00644);
  close (fd2);
  int fd = open (file_path.c_str(), O_RDWR);
  flock lock = {F_WRLCK, SEEK_SET, 0, 0, 0};
  fcntl (fd, F_SETLKW, &lock);
  ///out << "locked!" << endl;
  return fd;
}

// unlock a file on linux
// [hs, 2 july 2010]
int unlock ( int fd )
{
  flock lock1 = {F_UNLCK, SEEK_SET, 0, 0, 0};
  fcntl (fd, F_SETLKW, &lock1);
  return 0;
}
#endif
