Back to index

openldap  2.4.31
Functions
lock.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include <ac/time.h>
#include <ac/unistd.h>
#include "slap.h"
#include <lutil.h>

Go to the source code of this file.

Functions

FILE * lock_fopen (const char *fname, const char *type, FILE **lfp)
int lock_fclose (FILE *fp, FILE *lfp)

Function Documentation

int lock_fclose ( FILE *  fp,
FILE *  lfp 
)

Definition at line 75 of file lock.c.

{
       int rc = fclose( fp );
       /* unlock */
       ldap_unlockf( fileno(lfp) );
       fclose( lfp );

       return( rc );
}
FILE* lock_fopen ( const char *  fname,
const char *  type,
FILE **  lfp 
)

Definition at line 44 of file lock.c.

{
       FILE   *fp;
       char   buf[MAXPATHLEN];

       /* open the lock file */
       snprintf( buf, sizeof buf, "%s.lock", fname );

       if ( (*lfp = fopen( buf, "w" )) == NULL ) {
              Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", buf, 0, 0 );

              return( NULL );
       }

       /* acquire the lock */
       ldap_lockf( fileno(*lfp) );

       /* open the log file */
       if ( (fp = fopen( fname, type )) == NULL ) {
              Debug( LDAP_DEBUG_ANY, "could not open \"%s\"\n", fname, 0, 0 );

              ldap_unlockf( fileno(*lfp) );
              fclose( *lfp );
              *lfp = NULL;
              return( NULL );
       }

       return( fp );
}