Changeset 27597 for main


Ignore:
Timestamp:
2013-06-12T09:32:20+12:00 (11 years ago)
Author:
davidb
Message:

Additional header file included -- to help with finding the Unix mkdir function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/src/gdbmedit/db2txt/db2txt.cpp

    r26650 r27597  
    3131
    3232#else
     33
     34/* header file for mkdir */
     35#include <sys/stat.h>
     36
    3337#include <gdbm.h>
    3438#endif
     
    5761  cerr << "usage: " << program_name << " database-name" << endl << endl;
    5862}
     63
     64
     65#ifdef _MSC32_
     66// Windows implementation
     67HANDLE hFile = CreateFile(_T("c:\\file.txt"), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
     68
     69#else
     70// assume Unix
     71// lock a file on linux
     72// [hs, 2 july 2010]
     73// - modified to create a locl file local to the collection [jmt12]
     74int lock ()
     75{
     76  string file_path ("");
     77  char *collect_dir = getenv ("GSDLCOLLECTDIR");
     78  if (collect_dir != NULL)
     79  {
     80    file_path += collect_dir;
     81  }
     82  file_path += "/tmp";
     83  if ( access( file_path.c_str(), 00 ) != 0 )
     84  {
     85    mkdir(file_path.c_str(), 00777);
     86  }
     87  file_path += "/gdb.lock";
     88  ///out << "txt2dbl::lock(" << file_path << ") => ";
     89  int fd2 = open (file_path.c_str(), O_CREAT|O_RDWR, 00644);
     90  close (fd2);
     91  int fd = open (file_path.c_str(), O_RDWR);
     92  flock lock = {F_WRLCK, SEEK_SET, 0, 0, 0};
     93  fcntl (fd, F_SETLKW, &lock);
     94  ///out << "locked!" << endl;
     95  return fd;
     96}
     97
     98// unlock a file on linux
     99// [hs, 2 july 2010]
     100int unlock ( int fd )
     101{
     102  flock lock1 = {F_UNLCK, SEEK_SET, 0, 0, 0};
     103  fcntl (fd, F_SETLKW, &lock1);
     104  return 0;
     105}
     106#endif
    59107
    60108
Note: See TracChangeset for help on using the changeset viewer.