]> arthur.barton.de Git - netatalk.git/blob - libatalk/util/locking.c
Fix incompatible func args warnings
[netatalk.git] / libatalk / util / locking.c
1 /*
2    $Id: locking.c,v 1.3 2009-10-22 12:35:39 franklahm Exp $
3    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9  
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 */
15
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif /* HAVE_CONFIG_H */
19
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <atalk/util.h>
23
24 /*
25  * Function: lock_reg
26  *
27  * Purpose: lock a file with fctnl
28  *
29  * Arguments:
30  *
31  * fd         (r) File descriptor
32  * cmd        (r) cmd to fcntl, only F_SETLK is usable here
33  * type       (r) F_RDLCK, F_WRLCK, F_UNLCK
34  * offset     (r) byte offset relative to l_whence
35  * whence     (r) SEEK_SET, SEEK_CUR, SEEK_END
36  * len        (r) no. of bytes (0 means to EOF)
37  *
38  * Returns: fcntl return value
39  *
40  * Effects:
41  *
42  * Function called by macros {read|write|un]_lock to ease locking.
43  */
44 int lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len)
45 {
46     struct flock lock;
47
48     lock.l_type = type;
49     lock.l_start = offset;
50     lock.l_whence = whence;
51     lock.l_len = len;
52
53     return (fcntl(fd, cmd, &lock));
54 }