1 /* lock.c - routines to open and apply an advisory lock to a file */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
15 #include <ac/unistd.h>
17 #ifdef HAVE_SYS_FILE_H
24 lock_fopen( const char *fname, const char *type, FILE **lfp )
29 /* open the lock file */
30 strcpy(slap_strcopy( buf, fname ), ".lock" );
31 if ( (*lfp = fopen( buf, "w" )) == NULL ) {
33 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
34 "lock_fopen: could not open lock file \"%s\".\n", buf ));
36 Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", buf, 0, 0 );
42 /* acquire the lock */
43 ldap_lockf( fileno(*lfp) );
45 /* open the log file */
46 if ( (fp = fopen( fname, type )) == NULL ) {
48 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
49 "lock_fopen: could not open log file \"%s\".\n", buf ));
51 Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", fname, 0, 0 );
54 ldap_unlockf( fileno(*lfp) );
64 lock_fclose( FILE *fp, FILE *lfp )
67 ldap_unlockf( fileno(lfp) );
70 return( fclose( fp ) );