O_EXLOCK & O_SHLOCK are BSDisms. Replaced them with POSIX fcntl(F_SETLKW).

git-svn-id: https://svn.macports.org/repository/macports/branches/wbb4-versionfoobage-1/base@7613 d073be05-634f-4543-b044-5fe20cf6d1d6
This commit is contained in:
Paul Guyot
2004-06-30 05:13:03 +00:00
parent 7ade788fa0
commit 7ff2610091
+26 -4
View File
@@ -1,6 +1,6 @@
/*
* filemap.c
* $Id: filemap.c,v 1.1.2.4 2004/06/04 17:31:56 pguyot Exp $
* $Id: filemap.c,v 1.1.2.5 2004/06/30 05:13:03 pguyot Exp $
*
* Copyright (c) 2004 Paul Guyot, Darwinports Team.
* All rights reserved.
@@ -1504,15 +1504,27 @@ FilemapOpenCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[])
Tcl_Obj* theObject;
SFilemapObject* theFilemapObject;
int theFD;
struct flock theLock;
char isReadOnly = 0;
SNode* theRoot = NULL;
thePath = Tcl_GetString(objv[3]);
/* open the file */
theFD = open(thePath, O_RDWR | O_CREAT | O_EXLOCK, 0664);
if (theFD < 0)
theFD = open(thePath, O_RDWR | O_CREAT, 0664);
if (theFD >= 0)
{
/* Get a R/W lock on it (wait if required) */
theLock.l_type = F_WRLCK;
theLock.l_whence = SEEK_SET;
theLock.l_start = 0;
theLock.l_len = 0;
if (fcntl(theFD, F_SETLKW, &theLock) == -1)
{
theErr = errno;
break;
}
} else {
theErr = errno;
if (theErr == EACCES)
{
@@ -1520,12 +1532,22 @@ FilemapOpenCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[])
/* try again without R/W */
isReadOnly = 1;
theFD = open(thePath, O_RDONLY | O_SHLOCK, 0);
theFD = open(thePath, O_RDONLY, 0);
if (theFD < 0)
{
theErr = errno;
break;
}
theLock.l_type = F_RDLCK;
theLock.l_whence = SEEK_SET;
theLock.l_start = 0;
theLock.l_len = 0;
if (fcntl(theFD, F_SETLKW, &theLock) == -1)
{
theErr = errno;
break;
}
} else {
break;
}