2 $Id: locking.c,v 1.1 2009-10-02 09:32:41 franklahm Exp $
3 Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
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.
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.
22 * Purpose: lock a file with fctnl
26 * fd (r) File descriptor
27 * cmd (r) cmd to fcntl, only F_SETLK is usable here
28 * type (r) F_RDLCK, F_WRLCK, F_UNLCK
29 * offset (r) byte offset relative to l_whence
30 * whence (r) SEEK_SET, SEEK_CUR, SEEK_END
31 * len (r) no. of bytes (0 means to EOF)
33 * Returns: fcntl return value
37 * Function called by macros {read|write|un]_lock to ease locking.
39 int lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len)
44 lock.l_start = offset;
45 lock.l_whence = whence;
48 return (fcntl(fd, cmd, &lock));