Changeset 11 for trunk/lock.c


Ignore:
Timestamp:
2006-05-24T09:52:48+02:00 (9 years ago)
Author:
moo
Message:

make it build on windows vc compiler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lock.c

    r1 r11  
    66#ifndef ZEND_WIN32
    77typedef int HANDLE;
     8#   define CloseHandle(h) close(h)
    89#endif
    910#include "lock.h"
     
    1819#   include <fcntl.h>
    1920#   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
    2025static inline int dolock(xc_lock_t *lck, int type) /* {{{ */
    2126{
     
    3540}
    3641/* }}} */
    37 #define LCK_WR F_WRLCK
    38 #define LCK_RD F_RDLCK
    39 #define LCK_UN F_UNLCK
    40 #define LCK_NB 0
    4142#else
    4243
     
    4647#   include <sys/types.h>
    4748#   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
    4957static inline int dolock(xc_lock_t *lck, int type) /* {{{ */
    5058{
     
    5260
    5361    if (type == LCK_UN) {
    54         return UnlockFileEx((HANDLE)fd, 0, 1, 0, &offset);
     62        return UnlockFileEx((HANDLE)lck->fd, 0, 1, 0, &offset);
    5563    }
    5664    else {
    57         return LockFileEx((HANDLE)fd, type, 0, 1, 0, &offset);
     65        return LockFileEx((HANDLE)lck->fd, type, 0, 1, 0, &offset);
    5866    }
    5967}
    6068/* }}} */
    61 #define LCK_WR LOCKFILE_EXCLUSIVE_LOCK
    62 #define LCK_RD 0
    63 #define LCK_UN 0
    64 #define LCK_NB LOCKFILE_FAIL_IMMEDIATELY
    6569#endif
    6670
     
    6872{
    6973    HANDLE fd;
    70     char myname[sizeof("/tmp/.xcache.lock") - 1 + 20];
     74    char myname[sizeof("/tmp/.xcache.lock") - 1 + 100];
    7175
    7276    if (pathname == NULL) {
    7377        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());
    7579        pathname = myname;
    7680    }
    7781
    78     fd = open(pathname, O_RDWR|O_CREAT, 0666);
     82    fd = (HANDLE) open(pathname, O_RDWR|O_CREAT, 0666);
    7983
    8084    if (fd > 0) {
     
    99103void xc_fcntl_destroy(xc_lock_t *lck) /* {{{ */
    100104{   
    101     close(lck->fd);
     105    CloseHandle(lck->fd);
    102106#ifdef __CYGWIN__
    103107    unlink(lck->pathname);
Note: See TracChangeset for help on using the changeset viewer.