diff options
author | John Kohl <jtkohl@mit.edu> | 1990-01-18 11:37:59 +0000 |
---|---|---|
committer | John Kohl <jtkohl@mit.edu> | 1990-01-18 11:37:59 +0000 |
commit | e1efe3707f94b3f1ec5ecbb5da338e34ca68b119 (patch) | |
tree | d99df9dc1a2eaf6c3ff7a719dc7be566efb7594d /src/lib/krb5/os/lock_file.c | |
parent | 70f28ff23ab2aac17fa977bda6f23c1751e0aa27 (diff) | |
download | krb5-e1efe3707f94b3f1ec5ecbb5da338e34ca68b119.tar.gz krb5-e1efe3707f94b3f1ec5ecbb5da338e34ca68b119.tar.xz krb5-e1efe3707f94b3f1ec5ecbb5da338e34ca68b119.zip |
*** empty log message ***
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@116 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/os/lock_file.c')
-rw-r--r-- | src/lib/krb5/os/lock_file.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/krb5/os/lock_file.c b/src/lib/krb5/os/lock_file.c new file mode 100644 index 000000000..ce1862f24 --- /dev/null +++ b/src/lib/krb5/os/lock_file.c @@ -0,0 +1,52 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * <krb5/mit-copyright.h>. + * + * libos: krb5_lock_file routine + */ + +#ifndef lint +static char rcsid_lock_file_c [] = +"$Id$"; +#endif lint + +#include <krb5/copyright.h> + +#include <krb5/krb5.h> +#include <krb5/krb5_err.h> +#include <krb5/libos.h> + +#include <stdio.h> +#include <sys/file.h> + +extern int errno; + +krb5_error_code +krb5_lock_file(filep, mode) +FILE *filep; +int mode; +{ + int flock_flag = -1; + + switch (mode & ~KRB5_LOCKMODE_DONTBLOCK) { + case KRB5_LOCKMODE_SHARED: + flock_flag = LOCK_SH; + case KRB5_LOCKMODE_EXCLUSIVE: + flock_flag = LOCK_EX; + case KRB5_LOCKMODE_UNLOCK: + flock_flag = LOCK_UN; + } + if (flock_flag == -1) + return(KRB5_LIBOS_BADLOCKFLAG); + if (mode & KRB5_LOCKMODE_DONTBLOCK) + flock_flag |= LOCK_NB; + + if (flock(fileno(filep), flock_flag) == -1) + return(errno); + return 0; +} |