diff options
author | Guido van Rossum <guido@python.org> | 1996-09-11 23:17:20 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-09-11 23:17:20 (GMT) |
commit | c86436439548bf90131c19c33e307bfc604512f9 (patch) | |
tree | 030a8eefeebef6cacfbabfcb7e15165af3330b1b /Modules | |
parent | 6fe01d4ba0a7f5bc4ccc7324a51431243f7cc68e (diff) | |
download | cpython-c86436439548bf90131c19c33e307bfc604512f9.zip cpython-c86436439548bf90131c19c33e307bfc604512f9.tar.gz cpython-c86436439548bf90131c19c33e307bfc604512f9.tar.bz2 |
Added lockf() call
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/fcntlmodule.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index c547ed0..fd7b30c 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -181,7 +181,51 @@ fcntl_flock(self, args) return None; } +/* lockf(fd, operation) */ +static object * +fcntl_lockf(self, args) + object *self; /* Not used */ + object *args; +{ + int fd, code, len = 0, start = 0, whence = 0, ret; + FILE *f; + if (!PyArg_ParseTuple(args, "ii|iii", &fd, &code, &len, + &start, &whence)) + return NULL; + + BGN_SAVE +#ifndef LOCK_SH +#define LOCK_SH 1 /* shared lock */ +#define LOCK_EX 2 /* exclusive lock */ +#define LOCK_NB 4 /* don't block when locking */ +#define LOCK_UN 8 /* unlock */ +#endif + { + struct flock l; + if (code == LOCK_UN) + l.l_type = F_UNLCK; + else if (code & LOCK_SH) + l.l_type = F_RDLCK; + else if (code & LOCK_EX) + l.l_type = F_WRLCK; + else { + err_setstr(ValueError, "unrecognized flock argument"); + return NULL; + } + l.l_len = len; + l.l_start = start; + l.l_whence = whence; + ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); + } + END_SAVE + if (ret < 0) { + err_errno(IOError); + return NULL; + } + INCREF(None); + return None; +} /* List of functions */ @@ -189,6 +233,7 @@ static struct methodlist fcntl_methods[] = { {"fcntl", fcntl_fcntl}, {"ioctl", fcntl_ioctl}, {"flock", fcntl_flock}, + {"lockf", fcntl_lockf, 1}, {NULL, NULL} /* sentinel */ }; |