Connect the msvcrt file byte locking up to ntdll.
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 4dbeb86..1ea9961 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -32,6 +32,7 @@
#include "msvcrt/direct.h"
#include "msvcrt/fcntl.h"
#include "msvcrt/io.h"
+#include "msvcrt/sys/locking.h"
#include "msvcrt/stdio.h"
#include "msvcrt/stdlib.h"
#include "msvcrt/string.h"
@@ -508,6 +509,60 @@
}
/*********************************************************************
+ * _locking (MSVCRT.@)
+ *
+ * This is untested; the underlying LockFile doesn't work yet.
+ */
+int _locking(int fd, int mode, LONG nbytes)
+{
+ BOOL ret;
+ DWORD cur_locn;
+ HANDLE hand = msvcrt_fdtoh(fd);
+
+ TRACE(":fd (%d) handle (%d)\n",fd,hand);
+ if (hand == INVALID_HANDLE_VALUE)
+ return -1;
+
+ if (mode < 0 || mode > 4)
+ {
+ SET_THREAD_VAR(errno,MSVCRT_EINVAL);
+ return -1;
+ }
+
+ TRACE(":fd (%d) by 0x%08lx mode %s\n",
+ fd,nbytes,(mode==_LK_UNLCK)?"_LK_UNLCK":
+ (mode==_LK_LOCK)?"_LK_LOCK":
+ (mode==_LK_NBLCK)?"_LK_NBLCK":
+ (mode==_LK_RLCK)?"_LK_RLCK":
+ (mode==_LK_NBRLCK)?"_LK_NBRLCK":
+ "UNKNOWN");
+
+ if ((cur_locn = SetFilePointer(hand, 0L, NULL, SEEK_CUR)) == 0xffffffff)
+ {
+ FIXME ("Seek failed\n");
+ SET_THREAD_VAR(errno,MSVCRT_EINVAL); /* FIXME */
+ return -1;
+ }
+ if (mode == _LK_LOCK || mode == _LK_RLCK)
+ {
+ int nretry = 10;
+ ret = 1; /* just to satisfy gcc */
+ while (nretry--)
+ {
+ ret = LockFile(hand, cur_locn, 0L, nbytes, 0L);
+ if (ret) break;
+ sleep (1);
+ }
+ }
+ else if (mode == _LK_UNLCK)
+ ret = UnlockFile(hand, cur_locn, 0L, nbytes, 0L);
+ else
+ ret = LockFile(hand, cur_locn, 0L, nbytes, 0L);
+ /* FIXME - what about error settings? */
+ return ret ? 0 : -1;
+}
+
+/*********************************************************************
* rewind (MSVCRT.@)
*/
void MSVCRT_rewind(MSVCRT_FILE* file)
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 471298a..17d31c8 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -326,7 +326,7 @@
@ cdecl _loaddll(str) _loaddll
@ cdecl _local_unwind2(ptr long) _local_unwind2
@ cdecl _lock(long) _lock
-@ stub _locking #(long long long)
+@ cdecl _locking(long long long) _locking
@ cdecl _logb( double ) _logb
@ stub _longjmpex
@ cdecl _lrotl(long long) _lrotl
diff --git a/include/Makefile.in b/include/Makefile.in
index 62ec68e..4a117d6 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -78,6 +78,7 @@
msvcrt/stdio.h \
msvcrt/stdlib.h \
msvcrt/string.h \
+ msvcrt/sys/locking.h \
msvcrt/sys/stat.h \
msvcrt/sys/timeb.h \
msvcrt/sys/types.h \
diff --git a/include/msvcrt/sys/locking.h b/include/msvcrt/sys/locking.h
new file mode 100644
index 0000000..43c7ed4
--- /dev/null
+++ b/include/msvcrt/sys/locking.h
@@ -0,0 +1,30 @@
+/*
+ * _locking constants
+ *
+ * Copyright 2002 Bill Medland
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __WINE_SYS_LOCKING_H__
+#define __WINE_SYS_LOCKING_H__
+#define __WINE_USE_MSVCRT
+
+#define _LK_UNLCK 0
+#define _LK_LOCK 1
+#define _LK_NBLCK 2
+#define _LK_RLCK 3
+#define _LK_NBRLCK 4
+
+#endif /* __WINE_SYS_LOCKING_H__ : Do not place anything after this #endif */