File: utmp_io.c

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (27 lines) | stat: -rw-r--r-- 568 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "lib.h"

/* type:  F_RDLCK or F_WRLCK */
struct utmp *utmp_io(int fd, struct utmp *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;
}