2004-01-23 Michael Koch <konqueror@gmx.de>
* java/io/FileDescriptor.java (lock): New method. (tryLock): New method. (unlock): New method. * java/io/natFileDescriptorEcos.cc (lock): New method. (tryLock): New method. (unlock): New method. * java/io/natFileDescriptorPosix.cc (lock): New method. (tryLock): New method. (unlock): New method. * java/io/natFileDescriptorWin32.cc (lock): New method. (tryLock): New method. (unlock): New method. From-SVN: r76421
This commit is contained in:
parent
0e707673d2
commit
ca1d829f31
5 changed files with 110 additions and 0 deletions
|
@ -13,6 +13,7 @@ details. */
|
|||
#include "posix.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -420,3 +421,47 @@ java::io::FileDescriptor::available (void)
|
|||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
java::io::FileDescriptor::lock (jlong pos, jint len, jboolean shared)
|
||||
{
|
||||
struct flock lockdata;
|
||||
|
||||
lockdata.l_type = shared ? F_WRLCK : F_RDLCK;
|
||||
lockdata.l_whence = SEEK_SET;
|
||||
lockdata.l_start = pos;
|
||||
lockdata.l_len = len;
|
||||
|
||||
if (::fcntl (fd, F_SETLK, &lockdata) == -1)
|
||||
throw new IOException (JvNewStringLatin1 (strerror (errno)));
|
||||
}
|
||||
|
||||
jboolean
|
||||
java::io::FileDescriptor::tryLock (jlong pos, jint len, jboolean shared)
|
||||
{
|
||||
struct flock lockdata;
|
||||
|
||||
lockdata.l_type = shared ? F_WRLCK : F_RDLCK;
|
||||
lockdata.l_whence = SEEK_SET;
|
||||
lockdata.l_start = pos;
|
||||
lockdata.l_len = len;
|
||||
|
||||
if (::fcntl (fd, F_GETLK, &lockdata) == -1)
|
||||
throw new IOException (JvNewStringLatin1 (strerror (errno)));
|
||||
|
||||
return lockdata.l_type == F_UNLCK;
|
||||
}
|
||||
|
||||
void
|
||||
java::io::FileDescriptor::unlock (jlong pos, jint len)
|
||||
{
|
||||
struct flock lockdata;
|
||||
|
||||
lockdata.l_type = F_UNLCK;
|
||||
lockdata.l_whence = SEEK_SET;
|
||||
lockdata.l_start = pos;
|
||||
lockdata.l_len = len;
|
||||
|
||||
if (::fcntl (fd, F_SETLK, &lockdata) == -1)
|
||||
throw new IOException (JvNewStringLatin1 (strerror (errno)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue