OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [unix/] [getut.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
#ifndef _NO_GETUT
#ifndef _NO_GETUT
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
#include <utmp.h>
#include <utmp.h>
#include <_syslist.h>
#include <_syslist.h>
#include <_ansi.h>
#include <_ansi.h>
 
 
static int utmp_fd = -2;
static int utmp_fd = -2;
static char *utmp_file = UTMP_FILE;
static char *utmp_file = UTMP_FILE;
 
 
static struct utmp utmp_data;
static struct utmp utmp_data;
 
 
void
void
setutent ()
setutent ()
{
{
  if (utmp_fd == -2)
  if (utmp_fd == -2)
    {
    {
      utmp_fd = open (utmp_file, O_RDONLY);
      utmp_fd = open (utmp_file, O_RDONLY);
    }
    }
  lseek (utmp_fd, 0, SEEK_SET);
  lseek (utmp_fd, 0, SEEK_SET);
}
}
 
 
void
void
endutent ()
endutent ()
{
{
  close (utmp_fd);
  close (utmp_fd);
  utmp_fd = -2;
  utmp_fd = -2;
}
}
 
 
void
void
utmpname (_CONST char *file)
utmpname (_CONST char *file)
{
{
  utmp_file = strdup (file);
  utmp_file = strdup (file);
}
}
 
 
struct utmp *
struct utmp *
getutent ()
getutent ()
{
{
  if (utmp_fd == -2)
  if (utmp_fd == -2)
    setutent ();
    setutent ();
  if (read (utmp_fd, &utmp_data, sizeof (utmp_data)) < sizeof (utmp_data))
  if (read (utmp_fd, &utmp_data, sizeof (utmp_data)) < sizeof (utmp_data))
    return 0;
    return 0;
  return &utmp_data;
  return &utmp_data;
}
}
 
 
struct utmp *
struct utmp *
getutid (struct utmp *id)
getutid (struct utmp *id)
{
{
  while (read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
  while (read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
    {
    {
      switch (id->ut_type)
      switch (id->ut_type)
        {
        {
        case RUN_LVL:
        case RUN_LVL:
        case BOOT_TIME:
        case BOOT_TIME:
        case OLD_TIME:
        case OLD_TIME:
        case NEW_TIME:
        case NEW_TIME:
          if (id->ut_type == utmp_data.ut_type)
          if (id->ut_type == utmp_data.ut_type)
            return &utmp_data;
            return &utmp_data;
        case INIT_PROCESS:
        case INIT_PROCESS:
        case LOGIN_PROCESS:
        case LOGIN_PROCESS:
        case USER_PROCESS:
        case USER_PROCESS:
        case DEAD_PROCESS:
        case DEAD_PROCESS:
          if (id->ut_id == utmp_data.ut_id)
          if (id->ut_id == utmp_data.ut_id)
            return &utmp_data;
            return &utmp_data;
        default:
        default:
          abort ();
          abort ();
        }
        }
    }
    }
  return 0;
  return 0;
}
}
 
 
struct utmp *
struct utmp *
getutline (struct utmp *line)
getutline (struct utmp *line)
{
{
  while (read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
  while (read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
    {
    {
      if ((utmp_data.ut_type == LOGIN_PROCESS ||
      if ((utmp_data.ut_type == LOGIN_PROCESS ||
           utmp_data.ut_type == USER_PROCESS) &&
           utmp_data.ut_type == USER_PROCESS) &&
          !strncmp (utmp_data.ut_line, line->ut_line,
          !strncmp (utmp_data.ut_line, line->ut_line,
                    sizeof (utmp_data.ut_line)))
                    sizeof (utmp_data.ut_line)))
        return &utmp_data;
        return &utmp_data;
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
#endif /* !_NO_GETUT  */
#endif /* !_NO_GETUT  */
 
 

powered by: WebSVN 2.1.0

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