File: utmplines.c

package info (click to toggle)
idled 1.16-9
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 356 kB
  • ctags: 391
  • sloc: ansic: 2,886; yacc: 319; makefile: 150; lex: 69; sh: 37
file content (56 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (3)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Written By Mike Crider on September 18, 1994
 * Prints out the number of lines in the utmp file.
 * Use a number greater than the output number for the
 * MAXUSERS definition in idled.h.
 *
 * Cleaned for distribution on October 3, 1995
 */

/* Choose a system type */
/* #define SYSV */
/* #define BSD */

#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include "idled.h"

#if !defined(SYSV) && !defined(BSD)
#  define SYSV
#endif

/* Maybe this should always be included? */
#ifdef SYSV
#  include <fcntl.h>
#endif SYSV

int main()
{
#ifdef HAVE_UTMPX
   int fd, numlines;
   struct utmpx uent;

   fd = open(UTMP_FILE,O_RDONLY,0);

   numlines = 0;
   while (read(fd,&uent,sizeof(struct utmpx)) > 0)
      numlines++;
   
#else
   int fd, numlines;
   struct utmp uent;

   fd = open(UTMP_FILE,O_RDONLY,0);

   numlines = 0;
   while (read(fd,&uent,sizeof(struct utmp)) > 0)
      numlines++;
   
#endif

   close(fd);

   printf("Number of lines in utmp file: %d\n",numlines);

   return 0;
}