aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/utmp_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/utmp_io.c')
-rw-r--r--riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/utmp_io.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/utmp_io.c b/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/utmp_io.c
new file mode 100644
index 0000000..9470909
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/utmp_io.c
@@ -0,0 +1,27 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "lib.h"
+
+/* type: F_RDLCK or F_WRLCK */
+struct utmp_type *utmp_io(int fd, struct utmp_type *ut, int type) /*EXTRACT_INCL*/ {
+ struct flock fl;
+ int len;
+
+ fl.l_whence = SEEK_CUR;
+ fl.l_start = 0;
+ fl.l_len = UTMP_SIZE;
+ fl.l_pid = 0;
+ fl.l_type = type;
+
+ if (fcntl(fd, F_SETLKW, &fl)) return 0;
+ len = const_io((type==F_WRLCK) ? (int(*)())write : (int(*)())read,
+ fd, ut, UTMP_SIZE);
+
+ fl.l_start = -UTMP_SIZE;
+ fl.l_type = F_UNLCK;
+
+ fcntl(fd, F_SETLK, &fl);
+
+ return (len) ? 0 : ut;
+}