]> arthur.barton.de Git - netatalk.git/blob - libatalk/compat/flock.c
implemented config.h
[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 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 static int      _flock_dummy;
11
12 # if defined( sun ) && defined( __svr4__ )
13
14 #include <sys/types.h>
15 #include <fcntl.h>
16 #include <errno.h>
17
18 #include </usr/ucbinclude/sys/file.h>
19
20 int flock( fd, operation )
21     int         fd;
22     int         operation;
23 {
24     flock_t     l;
25     int         rc, op;
26
27     if ( operation & LOCK_NB ) {
28         op = F_SETLK;
29     } else {
30         op = F_SETLKW;
31     }
32
33     if ( operation & LOCK_EX ) {
34         l.l_type = F_WRLCK;
35     }
36
37     if ( operation & LOCK_SH ) {
38         l.l_type = F_RDLCK;
39     }
40
41     if ( operation & LOCK_UN ) {
42         l.l_type = F_UNLCK;
43     }
44
45     l.l_whence = 0;
46     l.l_start = 0;
47     l.l_len = 0;
48
49     if (( rc = fcntl( fd, F_SETLK, &l )) < 0 ) {
50         if ( errno == EAGAIN || errno == EACCES ) {
51             errno = EWOULDBLOCK;
52         }
53     }
54     return( rc );
55 }
56 # endif sun __svr4__