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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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