diff options
author | Guido van Rossum <guido@python.org> | 1996-06-11 15:11:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-06-11 15:11:34 (GMT) |
commit | 3c0b79ca0f0b162f5bf1c38ddee9d5672fb2d009 (patch) | |
tree | dca127ef4dd855b34ec0ef61baaf7dd447fb3eaf /Modules/fcntlmodule.c | |
parent | 8c1529dc299a3663fc49f9a6b4fb64d4c2a452d5 (diff) | |
download | cpython-3c0b79ca0f0b162f5bf1c38ddee9d5672fb2d009.zip cpython-3c0b79ca0f0b162f5bf1c38ddee9d5672fb2d009.tar.gz cpython-3c0b79ca0f0b162f5bf1c38ddee9d5672fb2d009.tar.bz2 |
A fcntl implementation for systems (like Solaris) without flock() call.
By Sjoerd.
Diffstat (limited to 'Modules/fcntlmodule.c')
-rw-r--r-- | Modules/fcntlmodule.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index d2efd60..c547ed0 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -27,6 +27,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "allobjects.h" #include "modsupport.h" +#include <fcntl.h> + /* fcntl(fd, opt, [arg]) */ @@ -144,7 +146,32 @@ fcntl_flock(self, args) return NULL; BGN_SAVE +#ifdef HAVE_FLOCK ret = flock(fd, code); +#else + +#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_whence = l.l_start = l.l_len = 0; + ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); + } +#endif /* HAVE_FLOCK */ END_SAVE if (ret < 0) { err_errno(IOError); |