Changeset 11 for trunk/lock.c
- Timestamp:
- 2006-05-24T09:52:48+02:00 (7 years ago)
- File:
-
- 1 edited
-
trunk/lock.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lock.c
r1 r11 6 6 #ifndef ZEND_WIN32 7 7 typedef int HANDLE; 8 # define CloseHandle(h) close(h) 8 9 #endif 9 10 #include "lock.h" … … 18 19 # include <fcntl.h> 19 20 # include <errno.h> 21 # define LCK_WR F_WRLCK 22 # define LCK_RD F_RDLCK 23 # define LCK_UN F_UNLCK 24 # define LCK_NB 0 20 25 static inline int dolock(xc_lock_t *lck, int type) /* {{{ */ 21 26 { … … 35 40 } 36 41 /* }}} */ 37 #define LCK_WR F_WRLCK38 #define LCK_RD F_RDLCK39 #define LCK_UN F_UNLCK40 #define LCK_NB 041 42 #else 42 43 … … 46 47 # include <sys/types.h> 47 48 # include <sys/stat.h> 48 # define errno GetLastError() 49 # ifndef errno 50 # define errno GetLastError() 51 # endif 52 # define getuid() 0 53 # define LCK_WR LOCKFILE_EXCLUSIVE_LOCK 54 # define LCK_RD 0 55 # define LCK_UN 0 56 # define LCK_NB LOCKFILE_FAIL_IMMEDIATELY 49 57 static inline int dolock(xc_lock_t *lck, int type) /* {{{ */ 50 58 { … … 52 60 53 61 if (type == LCK_UN) { 54 return UnlockFileEx((HANDLE) fd, 0, 1, 0, &offset);62 return UnlockFileEx((HANDLE)lck->fd, 0, 1, 0, &offset); 55 63 } 56 64 else { 57 return LockFileEx((HANDLE) fd, type, 0, 1, 0, &offset);65 return LockFileEx((HANDLE)lck->fd, type, 0, 1, 0, &offset); 58 66 } 59 67 } 60 68 /* }}} */ 61 #define LCK_WR LOCKFILE_EXCLUSIVE_LOCK62 #define LCK_RD 063 #define LCK_UN 064 #define LCK_NB LOCKFILE_FAIL_IMMEDIATELY65 69 #endif 66 70 … … 68 72 { 69 73 HANDLE fd; 70 char myname[sizeof("/tmp/.xcache.lock") - 1 + 20];74 char myname[sizeof("/tmp/.xcache.lock") - 1 + 100]; 71 75 72 76 if (pathname == NULL) { 73 77 static int i = 0; 74 snprintf(myname, sizeof(myname) - 1, "/tmp/.xcache.%d.%d. lock", (int) getuid(), i ++);78 snprintf(myname, sizeof(myname) - 1, "/tmp/.xcache.%d.%d.%d.lock", (int) getuid(), i ++, rand()); 75 79 pathname = myname; 76 80 } 77 81 78 fd = open(pathname, O_RDWR|O_CREAT, 0666);82 fd = (HANDLE) open(pathname, O_RDWR|O_CREAT, 0666); 79 83 80 84 if (fd > 0) { … … 99 103 void xc_fcntl_destroy(xc_lock_t *lck) /* {{{ */ 100 104 { 101 close(lck->fd);105 CloseHandle(lck->fd); 102 106 #ifdef __CYGWIN__ 103 107 unlink(lck->pathname);
Note: See TracChangeset
for help on using the changeset viewer.

