File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2727#include "allobjects.h"
2828#include "modsupport.h"
2929
30+ #include <fcntl.h>
31+
3032
3133/* fcntl(fd, opt, [arg]) */
3234
@@ -144,7 +146,32 @@ fcntl_flock(self, args)
144146 return NULL ;
145147
146148 BGN_SAVE
149+ #ifdef HAVE_FLOCK
147150 ret = flock (fd , code );
151+ #else
152+
153+ #ifndef LOCK_SH
154+ #define LOCK_SH 1 /* shared lock */
155+ #define LOCK_EX 2 /* exclusive lock */
156+ #define LOCK_NB 4 /* don't block when locking */
157+ #define LOCK_UN 8 /* unlock */
158+ #endif
159+ {
160+ struct flock l ;
161+ if (code == LOCK_UN )
162+ l .l_type = F_UNLCK ;
163+ else if (code & LOCK_SH )
164+ l .l_type = F_RDLCK ;
165+ else if (code & LOCK_EX )
166+ l .l_type = F_WRLCK ;
167+ else {
168+ err_setstr (ValueError , "unrecognized flock argument" );
169+ return NULL ;
170+ }
171+ l .l_whence = l .l_start = l .l_len = 0 ;
172+ ret = fcntl (fd , (code & LOCK_NB ) ? F_SETLK : F_SETLKW , & l );
173+ }
174+ #endif /* HAVE_FLOCK */
148175 END_SAVE
149176 if (ret < 0 ) {
150177 err_errno (IOError );
You can’t perform that action at this time.
0 commit comments