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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [unix/] [getlogin.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
#include <sys/types.h>
2
#include <utmp.h>
3
#include <fcntl.h>
4
#include <_syslist.h>
5
 
6
char *
7
getlogin ()
8
{
9
  int utmp_fd;
10
  struct utmp utmp_buf;
11
  static char buf[10];
12
  extern char *ttyname ();
13
  char *tty;
14
 
15
  if (((tty = ttyname (0)) == 0)
16
      || ((tty = ttyname (1)) == 0)
17
      || ((tty = ttyname (2)) == 0))
18
    return 0;
19
 
20
  if ((utmp_fd = _open (UTMP_FILE, O_RDONLY)) == -1)
21
    return 0;
22
 
23
  if (!strncmp (tty, "/dev/", 5))
24
    tty += 5;
25
 
26
  while (_read (utmp_fd, &utmp_buf, sizeof (utmp_buf)) == sizeof (utmp_buf))
27
    {
28
      if (!strncmp (tty, utmp_buf.ut_line, sizeof (utmp_buf.ut_line))
29
          && utmp_buf.ut_type == USER_PROCESS)
30
        {
31
          _close (utmp_fd);
32
          memset (buf, 0, sizeof (buf));
33
          strncpy (buf, utmp_buf.ut_user, sizeof (utmp_buf.ut_user));
34
          return buf;
35
        }
36
    }
37
 
38
  _close (utmp_fd);
39
  return 0;
40
}

powered by: WebSVN 2.1.0

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