]> git.sur5r.net Git - openldap/blob - libraries/liblutil/lockf.c
13226bbf590471e6ef9fea5dd1ca97b75e2d8c29
[openldap] / libraries / liblutil / lockf.c
1 /*
2  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted only
6  * as authorized by the OpenLDAP Public License.  A copy of this
7  * license is available at http://www.OpenLDAP.org/license.html or
8  * in file LICENSE in the top-level directory of the distribution.
9  */
10 /* Simple file locking method for systems without */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15 #include <ac/unistd.h>
16
17 #ifdef NEED_SIMPLE_LOCKING
18
19 int lutil_lockf ( FILE *fp ) {
20         struct flock file_lock;
21         memset( &file_lock, 0, sizeof( file_lock ) );
22         file_lock.l_type = F_WRLCK;
23         file_lock.l_whence = SEEK_SET;
24         file_lock.l_start = 0;
25         file_lock.l_len = 0;
26         return( fcntl( fileno(fp), F_SETLKW, &file_lock ) );
27 }
28
29 int lutil_unlockf ( FILE *fp ) {
30         struct flock file_lock;
31         memset( &file_lock, 0, sizeof( file_lock ) );
32         file_lock.l_type = F_UNLCK;
33         file_lock.l_whence = SEEK_SET;
34         file_lock.l_start = 0;
35         file_lock.l_len = 0;
36         return ( fcntl( fileno(fp), F_SETLK, &file_lock ) );
37 }
38
39 #endif /* NEED_SIMPLE_LOCKING */