*** empty log message ***
authorJohn Kohl <jtkohl@mit.edu>
Thu, 18 Jan 1990 11:37:59 +0000 (11:37 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Thu, 18 Jan 1990 11:37:59 +0000 (11:37 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@116 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/lock_file.c [new file with mode: 0644]
src/lib/krb5/os/unlck_file.c [new file with mode: 0644]

diff --git a/src/lib/krb5/os/lock_file.c b/src/lib/krb5/os/lock_file.c
new file mode 100644 (file)
index 0000000..ce1862f
--- /dev/null
@@ -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;
+}
diff --git a/src/lib/krb5/os/unlck_file.c b/src/lib/krb5/os/unlck_file.c
new file mode 100644 (file)
index 0000000..eb581c2
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * $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_unlock_file_c [] =
+"$Id$";
+#endif lint
+
+#include <krb5/copyright.h>
+
+#include <krb5/config.h>
+#include <krb5/base-defs.h>
+#include <krb5/libos.h>
+
+#include <stdio.h>
+
+krb5_error_code
+krb5_unlock_file(filep)
+FILE *filep;
+{
+    return krb5_lock_file(filep, KRB5_LOCKMODE_UNLOCK);
+}