Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nadezhda Ivanova
OpenLDAP
Commits
11add79c
Commit
11add79c
authored
Mar 26, 1999
by
Kurt Zeilenga
Browse files
Update locking codes.
parent
918b9f8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/ac/unistd.h
View file @
11add79c
...
...
@@ -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 */
include/lutil_lockf.h
View file @
11add79c
...
...
@@ -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_ */
libraries/liblutil/lockf.c
View file @
11add79c
...
...
@@ -14,28 +14,26 @@
#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
*
f
s
)
{
int
lutil_unlockf
(
FILE
*
f
p
)
{
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 */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment