Show
Ignore:
Timestamp:
04.12.2008 12:38:05 (11 years ago)
Author:
mdewsnip
Message:

Added "my_locking" function from old Windows port of GDBM.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/common-src/packages/gdbm/gdbm-1.8.3/global.c

    r18019 r18062  
    4545/* The dbm error number is placed in the variable GDBM_ERRNO. */ 
    4646gdbm_error gdbm_errno = GDBM_NO_ERROR; 
     47 
     48#ifdef MSDOS 
     49 
     50#include <io.h> 
     51#include <windows.h> 
     52 
     53/* a simple locking function for windows that uses file descriptors */ 
     54int my_locking(int fh, int lmode, long lockoffset, long nbytes) { 
     55    int result = -1; 
     56    int trys = 10; 
     57 
     58    lseek (fh, lockoffset, L_SET); 
     59 
     60    while (trys > 0 && result != 0) { 
     61        if (lmode == MY_UNLOCK) { 
     62            if (UnlockFile((HANDLE)_get_osfhandle(fh),lockoffset,0,nbytes,0)) 
     63                result = 0; 
     64 
     65        } else if (lmode == MY_READLOCK) { 
     66/*          if (LockFileEx((HANDLE)_get_osfhandle(fh),0,0,nbytes,0,0))*/ 
     67            if (LockFile((HANDLE)_get_osfhandle(fh),lockoffset,0,nbytes,0)) 
     68                result = 0; 
     69 
     70        } else if (lmode == MY_WRITELOCK) { 
     71            if (LockFile((HANDLE)_get_osfhandle(fh),lockoffset,0,nbytes,0)) 
     72                result = 0; 
     73        } 
     74 
     75        Sleep(100L); 
     76        trys--; 
     77    } 
     78 
     79    return result; 
     80} 
     81 
     82#endif