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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [unix/] [getlogin.c] - Blame information for rev 258

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

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

powered by: WebSVN 2.1.0

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