Index: trunk/lock.c
===================================================================
--- trunk/lock.c	(revision 393)
+++ trunk/lock.c	(revision 928)
@@ -9,5 +9,13 @@
 #		define INVALID_HANDLE_VALUE -1
 #	endif
-#	define CloseHandle(h) close(h)
+#else
+#	define close(h) CloseHandle(h)
+#	define open(filename, mode, permission) CreateFile(filename, \
+		GENERIC_READ | GENERIC_WRITE, \
+		FILE_SHARE_READ | FILE_SHARE_WRITE, \
+		NULL, \
+		OPEN_ALWAYS, \
+		FILE_ATTRIBUTE_NORMAL, \
+		NULL)
 #endif
 #include "lock.h"
@@ -50,7 +58,6 @@
 #	include <sys/types.h>
 #	include <sys/stat.h>
-#	ifndef errno
-#		define errno GetLastError()
-#	endif
+#	undef errno
+#	define errno GetLastError()
 #	define getuid() 0
 #	define LCK_WR LOCKFILE_EXCLUSIVE_LOCK
@@ -100,5 +107,5 @@
 	}
 
-	fd = (HANDLE) open(pathname, O_RDWR|O_CREAT, 0666);
+	fd = open(pathname, O_RDWR|O_CREAT, 0666);
 
 	if (fd != INVALID_HANDLE_VALUE) {
@@ -114,5 +121,5 @@
 	}
 	else {
-		fprintf(stderr, "xc_fcntl_create: open(%s, O_RDWR|O_CREAT, 0666) failed:", pathname);
+		zend_error(E_ERROR, "xc_fcntl_create: open(%s, O_RDWR|O_CREAT, 0666) failed:", pathname);
 		lck = NULL;
 	}
@@ -127,5 +134,5 @@
 void xc_fcntl_destroy(xc_lock_t *lck) /* {{{ */
 {   
-	CloseHandle(lck->fd);
+	close(lck->fd);
 #ifdef __CYGWIN__
 	unlink(lck->pathname);
@@ -138,5 +145,5 @@
 {   
 	if (dolock(lck, LCK_WR) < 0) {
-		fprintf(stderr, "xc_fcntl_lock failed errno:%d", errno);
+		zend_error(E_ERROR, "xc_fcntl_lock failed errno:%d", errno);
 	}
 }
@@ -145,5 +152,5 @@
 {   
 	if (dolock(lck, LCK_RD) < 0) {
-		fprintf(stderr, "xc_fcntl_lock failed errno:%d", errno);
+		zend_error(E_ERROR, "xc_fcntl_lock failed errno:%d", errno);
 	}
 }
@@ -152,5 +159,5 @@
 {   
 	if (dolock(lck, LCK_UN) < 0) {
-		fprintf(stderr, "xc_fcntl_unlock failed errno:%d", errno);
+		zend_error(E_ERROR, "xc_fcntl_unlock failed errno:%d", errno);
 	}
 }
