]> arthur.barton.de Git - netatalk.git/blob - libatalk/compat/flock.c
45ec45da14bc30dd33629c2c3670f3aef4e5aa32
[netatalk.git] / libatalk / compat / flock.c
1 /*
2  * Copyright (c) 1996 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 static int      _flock_dummy;
7
8 # if defined( sun ) && defined( __svr4__ )
9
10 #include <sys/types.h>
11 #include <fcntl.h>
12 #include <errno.h>
13
14 #include </usr/ucbinclude/sys/file.h>
15
16 int flock( fd, operation )
17     int         fd;
18     int         operation;
19 {
20     flock_t     l;
21     int         rc, op;
22
23     if ( operation & LOCK_NB ) {
24         op = F_SETLK;
25     } else {
26         op = F_SETLKW;
27     }
28
29     if ( operation & LOCK_EX ) {
30         l.l_type = F_WRLCK;
31     }
32
33     if ( operation & LOCK_SH ) {
34         l.l_type = F_RDLCK;
35     }
36
37     if ( operation & LOCK_UN ) {
38         l.l_type = F_UNLCK;
39     }
40
41     l.l_whence = 0;
42     l.l_start = 0;
43     l.l_len = 0;
44
45     if (( rc = fcntl( fd, F_SETLK, &l )) < 0 ) {
46         if ( errno == EAGAIN || errno == EACCES ) {
47             errno = EWOULDBLOCK;
48         }
49     }
50     return( rc );
51 }
52 # endif sun __svr4__