2 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
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.
10 /* File locking methods */
15 #include <ac/unistd.h>
17 #if defined(NEED_FCNTL_LOCKING)
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;
26 return( fcntl( fileno(fp), F_SETLKW, &file_lock ) );
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;
36 return ( fcntl( fileno(fp), F_SETLK, &file_lock ) );
39 #endif /* !HAVE_FILE_LOCKING */