4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-15 19:09:58 +08:00
Jeff Johnston 199359f062 2000-08-23 Werner Almesberger <Werner.Almesberger@epfl.ch>
* libc/stdlib/abort.c: changed description: uses "raise" instead of
        "getpid" and "kill"; added: uses "write" and "_exit".
        Also included unistd.h for "_exit" prototype.
        * libc/stdlib/system.c: included unistd.h for "execve" prototype,
        reent.h for "_fork_r" and "_wait_r" prototypes.
        (do_system): changed  extern char *environ[] to POSIX-friendly
        extern char **environ.
        * libc/stdlib/wctomb_r.c: included string.h for "strlen" and "strcmp"
        prototypes.
        * libc/stdlib/remove.c: included reent.h for "_unlink_r" prototype.
        * libc/reent/execr.c: included sys/wait.h for "wait" prototype.
        * libc/reent/fstatr.c: included sys/stat.h for "fstat" prototype.
        * libc/reent/openr.c: included fcntl.h for "open" prototype.
        * libc/reent/signalr.c: included signal.h for "kill" prototype,
        unistd.h for "getpid" prototype.
        * libc/reent/statr.c: included sys/stat.h for "stat" prototype.
        * libc/reent/timer.c: included sys/time.h for "gettimeofday" prototype.
        * libc/unix/getut.c (utmpname): removed local, incorrect "strdup"
        prototype.  Also included stdlib.h for "abort", string.h for
        "strdup" and "strncmp" prototypes.
        * libc/unix/getlogin.c: included string.h for "strncmp", "memset", and
        "strncpy", unistd.h for "read" and "close" prototypes.
        * libc/posix/execvp.c: included string.h for "strchr", "strlen", and
        "strcat" prototypes.
2000-08-24 18:51:09 +00:00

87 lines
1.5 KiB
C

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