1 /* lock.c - routines to open and apply an advisory lock to a file */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
12 #include <ac/socket.h>
14 #include <ac/unistd.h>
16 #ifdef HAVE_SYS_FILE_H
19 #ifdef HAVE_SYS_PARAM_H
20 #include <sys/param.h>
25 lock_fopen( const char *fname, const char *type, FILE **lfp )
30 /* open the lock file */
32 strcat( buf, ".lock" );
33 if ( (*lfp = fopen( buf, "w" )) == NULL ) {
34 Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", buf, 0, 0 );
38 /* acquire the lock */
39 ldap_lockf( fileno(*lfp) );
41 /* open the log file */
42 if ( (fp = fopen( fname, type )) == NULL ) {
43 Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", fname, 0, 0 );
44 ldap_unlockf( fileno(*lfp) );
54 lock_fclose( FILE *fp, FILE *lfp )
57 ldap_unlockf( fileno(lfp) );
60 return( fclose( fp ) );