OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [newlib/] [newlib/] [libc/] [unix/] [getut.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
#include <fcntl.h>
2
#include <unistd.h>
3
#include <utmp.h>
4
#include <_syslist.h>
5
 
6
static int utmp_fd = -2;
7
static char *utmp_file = UTMP_FILE;
8
 
9
static struct utmp utmp_data;
10
 
11
void
12
setutent ()
13
{
14
  if (utmp_fd == -2)
15
    {
16
      utmp_fd = _open (utmp_file, O_RDONLY);
17
    }
18
  _lseek (utmp_fd, 0, SEEK_SET);
19
}
20
 
21
void
22
endutent ()
23
{
24
  _close (utmp_fd);
25
  utmp_fd = -2;
26
}
27
 
28
void
29
utmpname (char *file)
30
{
31
  extern char *strdup (char *);
32
 
33
  utmp_file = strdup (file);
34
}
35
 
36
struct utmp *
37
getutent ()
38
{
39
  if (utmp_fd == -2)
40
    setutent ();
41
  if (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) < sizeof (utmp_data))
42
    return 0;
43
  return &utmp_data;
44
}
45
 
46
struct utmp *
47
getutid (struct utmp *id)
48
{
49
  while (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
50
    {
51
      switch (id->ut_type)
52
        {
53
        case RUN_LVL:
54
        case BOOT_TIME:
55
        case OLD_TIME:
56
        case NEW_TIME:
57
          if (id->ut_type == utmp_data.ut_type)
58
            return &utmp_data;
59
        case INIT_PROCESS:
60
        case LOGIN_PROCESS:
61
        case USER_PROCESS:
62
        case DEAD_PROCESS:
63
          if (id->ut_id == utmp_data.ut_id)
64
            return &utmp_data;
65
        default:
66
          abort ();
67
        }
68
    }
69
  return 0;
70
}
71
 
72
struct utmp *
73
getutline (struct utmp *line)
74
{
75
  while (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
76
    {
77
      if ((utmp_data.ut_type == LOGIN_PROCESS ||
78
           utmp_data.ut_type == USER_PROCESS) &&
79
          !strncmp (utmp_data.ut_line, line->ut_line,
80
                    sizeof (utmp_data.ut_line)))
81
        return &utmp_data;
82
    }
83
 
84
  return 0;
85
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.