2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2008 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: George Schlossnagle <george@omniti.com> |
16 | Edin Kadribasic <edink@php.net> |
17 +----------------------------------------------------------------------+
19 This software was contributed to PHP by Community Connect Inc. in 2002
20 and revised in 2005 by Yahoo! Inc. to add support for PHP 5.1.
21 Future revisions and derivatives of this source code must acknowledge
22 Community Connect Inc. as the original contributor of this module by
23 leaving this note intact in the source code.
25 All other licensing and usage conditions are those of the PHP Group.
29 /* $Id: apc_fcntl_win32.c,v 3.6.2.1 2008/05/11 18:57:00 rasmus Exp $ */
31 #include "apc_fcntl.h"
34 #include <win32/flock.h>
37 #include <sys/types.h>
40 int apc_fcntl_create(const char* pathname)
42 char *lock_file = emalloc(MAXPATHLEN);
47 tmplen = GetTempPath(MAXPATHLEN, lock_file);
53 snprintf(lock_file + tmplen, MAXPATHLEN - tmplen - 1, "apc.lock.%d", i++);
55 fd = CreateFile(lock_file,
56 GENERIC_READ | GENERIC_WRITE,
57 FILE_SHARE_READ | FILE_SHARE_WRITE,
60 FILE_ATTRIBUTE_NORMAL,
64 if (fd == INVALID_HANDLE_VALUE) {
65 apc_eprint("apc_fcntl_create: could not open %s", lock_file);
74 void apc_fcntl_destroy(int fd)
76 CloseHandle((HANDLE)fd);
79 void apc_fcntl_lock(int fd)
81 OVERLAPPED offset = {0, 0, 0, 0, NULL};
83 if (!LockFileEx((HANDLE)fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &offset)) {
84 apc_eprint("apc_fcntl_lock failed errno:%d", GetLastError());
88 void apc_fcntl_rdlock(int fd)
90 OVERLAPPED offset = {0, 0, 0, 0, NULL};
92 if (!LockFileEx((HANDLE)fd, 0, 0, 1, 0, &offset)) {
93 apc_eprint("apc_fcntl_rdlock failed errno:%d", GetLastError());
97 void apc_fcntl_unlock(int fd)
99 OVERLAPPED offset = {0, 0, 0, 0, NULL};
101 if (!UnlockFileEx((HANDLE)fd, 0, 1, 0, &offset)) {
102 DWORD error_code = GetLastError();
103 /* Ignore already unlocked error */
104 if (error_code != ERROR_NOT_LOCKED) {
105 apc_eprint("apc_fcntl_unlock failed errno:%d", error_code);
115 * vim600: expandtab sw=4 ts=4 sts=4 fdm=marker
116 * vim<600: expandtab sw=4 ts=4 sts=4