]> git.sur5r.net Git - openldap/commitdiff
Update locking codes.
authorKurt Zeilenga <kurt@openldap.org>
Fri, 26 Mar 1999 17:43:23 +0000 (17:43 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 26 Mar 1999 17:43:23 +0000 (17:43 +0000)
include/ac/unistd.h
include/lutil_lockf.h
libraries/liblutil/lockf.c

index b4baba4fe6a77797a5878750b6cf9cde39bb29f8..0162d49ca468876490e72aaa79858fd01be10da1 100644 (file)
@@ -52,27 +52,42 @@ extern char* getpass LDAP_P((const char *getpass));
        extern char *mktemp(char *);
 #endif
 
-/* use _POSIX_VERSION for POSIX.1 code */
-
 /* Setup file locking macros */
-#if defined (HAVE_LOCKF) && defined (F_LOCK) && defined (F_ULOCK)
-#      define ldap_lockf(x) lockf(fileno(x),F_LOCK, 0)
-#      define ldap_unlockf(x) lockf(fileno(x),F_ULOCK, 0)
-#elif defined (HAVE_FCNTL_H) && defined (F_WRLCK) && defined (F_UNLCK)
-#      ifndef  NEED_FCNTL_LOCKING
-#              define NEED_FCNTL_LOCKING
+#if !defined( ldap_lockf ) && HAVE_LOCKF && defined( F_LOCK )
+#      define ldap_lockf(x)    lockf(fileno(x), F_LOCK, 0)
+#      define ldap_unlockf(x)  lockf(fileno(x), F_ULOCK, 0)
+#endif
+
+#if !defined( ldap_lockf ) && HAVE_FCNTL
+#      ifdef HAVE_FCNTL_H
+#              include <fcntl.h>
 #      endif
-#      include <lutil_lockf.h>
-#      define ldap_lockf(x) lutil_ldap_lockf(x)
-#      define ldap_unlockf(x) lutil_ldap_unlockf(x)
-#elif defined (HAVE_FLOCK) && defined (LOCK_EX) && defined (LOCK_UN)
+
+#      ifdef F_WRLCK
+#              ifndef  NEED_FCNTL_LOCKING
+#                      define NEED_FCNTL_LOCKING
+#              endif
+#              include <lutil_lockf.h>
+#              define ldap_lockf(x)    lutil_lockf(x)
+#              define ldap_unlockf(x)  lutil_unlockf(x)
+#      endif
+#endif
+
+#if !defined( ldap_lockf ) && HAVE_FLOCK
 #      if HAVE_SYS_FILE_H
 #              include <sys/file.h>
 #      endif
-#      define ldap_lockf(x) flock(fileno(x),LOCK_EX)
-#      define ldap_unlockf(x) flock(fileno(x),LOCK_UN)
-#else
-#error no_suitable_locking_found
+#      ifdef LOCK_EX
+#              define ldap_lockf(x)    flock(fileno(x), LOCK_EX)
+#              define ldap_unlockf(x)  flock(fileno(x), LOCK_UN)
+#      endif
+#endif
+
+#if !defined( ldap_lockf )
+       /* use some simplistic locking method */
+#      include <lutil_lockf.h>
+#      define ldap_lockf(x)    lutil_lockf(x)
+#      define ldap_unlockf(x)  lutil_unlockf(x)
 #endif
 
 #endif /* _AC_UNISTD_H */
index 9a791d8c3abcc53e2ccb7612a7ce0becfc83698a..166cbe1a409bd53dc607db44dad5aad590c8ecc6 100644 (file)
@@ -7,26 +7,18 @@
  * license is available at http://www.OpenLDAP.org/license.html or
  * in file LICENSE in the top-level directory of the distribution.
  */
+
 /* File locking methods */
+/* only available if fcntl() locking is required */
 
 #ifndef _LUTIL_LOCKF_H_
 #define _LUTIL_LOCKF_H_
 
-#include <stdio.h>
-#include <ldap_cdefs.h>
-#include <ac/bytes.h>
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-#ifdef NEED_FCNTL_LOCKING
 LDAP_BEGIN_DECL
 
-LDAP_F int lutil_ldap_lockf LDAP_P(( FILE *fs ));
-LDAP_F int lutil_ldap_unlockf LDAP_P(( FILE *fs ));
+LDAP_F int lutil_lockf LDAP_P(( FILE *fs ));
+LDAP_F int lutil_unlockf LDAP_P(( FILE *fs ));
 
 LDAP_END_DECL
-#endif /* NEED_FCNTL_LOCKING */
 
 #endif /* _LUTIL_LOCKF_H_ */
index 7f0d569f816bc9d0eae6e46f6cc97032a8739d85..7307720dd68744af161365b245c2762fb73e092b 100644 (file)
 #include <stdio.h>
 #include <ac/unistd.h>
 
-#if defined(NEED_FCNTL_LOCKING) && defined(HAVE_FCNTL_H)
+#if defined(NEED_FCNTL_LOCKING)
 
-#include <fcntl.h>
-
-int lutil_ldap_lockf ( FILE *fs ) {
+int lutil_lockf ( FILE *fp ) {
        struct flock file_lock;
        memset( &file_lock, 0, sizeof( file_lock ) );
        file_lock.l_type = F_WRLCK;
        file_lock.l_whence = SEEK_SET;
        file_lock.l_start = 0;
        file_lock.l_len = 0;
-       return( fcntl( fileno( fs ), F_SETLKW, &file_lock ) );
+       return( fcntl( fileno(fp), F_SETLKW, &file_lock ) );
 }
 
-int lutil_ldap_unlockf ( FILE *fs ) {
+int lutil_unlockf ( FILE *fp ) {
        struct flock file_lock;
        memset( &file_lock, 0, sizeof( file_lock ) );
        file_lock.l_type = F_UNLCK;
        file_lock.l_whence = SEEK_SET;
        file_lock.l_start = 0;
        file_lock.l_len = 0;
-       return ( fcntl( fileno( fs ), F_SETLK, &file_lock ) );
+       return ( fcntl( fileno(fp), F_SETLK, &file_lock ) );
 }
 
 #endif /* !HAVE_FILE_LOCKING */