mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
do not depend on flock
This commit is contained in:
parent
9e863cf561
commit
c71af67adc
1 changed files with 6 additions and 1 deletions
|
@ -12,6 +12,7 @@ p9open(char *name, int mode)
|
||||||
{
|
{
|
||||||
int cexec, rclose;
|
int cexec, rclose;
|
||||||
int fd, umode, lock, rdwr;
|
int fd, umode, lock, rdwr;
|
||||||
|
struct flock fl;
|
||||||
|
|
||||||
rdwr = mode&3;
|
rdwr = mode&3;
|
||||||
umode = rdwr;
|
umode = rdwr;
|
||||||
|
@ -34,7 +35,11 @@ p9open(char *name, int mode)
|
||||||
fd = open(name, umode);
|
fd = open(name, umode);
|
||||||
if(fd >= 0){
|
if(fd >= 0){
|
||||||
if(lock){
|
if(lock){
|
||||||
if(flock(fd, (rdwr==OREAD) ? LOCK_SH : LOCK_EX) < 0){
|
fl.l_type = (rdwr==OREAD) ? F_RDLCK : F_WRLCK;
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
fl.l_start = 0;
|
||||||
|
fl.l_len = 0;
|
||||||
|
if(fcntl(fd, F_SETLK, &fl) < 0){
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue