1 /* lock.c - routines to open and apply an advisory lock to a file */
10 #include <ac/unistd.h>
12 #ifdef HAVE_SYS_FILE_H
15 #include <sys/param.h>
19 lock_fopen( char *fname, char *type, FILE **lfp )
24 /* open the lock file */
26 strcat( buf, ".lock" );
27 if ( (*lfp = fopen( buf, "w" )) == NULL ) {
28 Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", buf, 0, 0 );
32 /* acquire the lock */
33 while ( ldap_lockf( fileno(*lfp) ) != 0 ) {
37 /* open the log file */
38 if ( (fp = fopen( fname, type )) == NULL ) {
39 Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", fname, 0, 0 );
40 ldap_unlockf( fileno(*lfp) );
50 lock_fclose( FILE *fp, FILE *lfp )
53 ldap_unlockf( fileno(lfp) );
56 return( fclose( fp ) );