diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:39:52 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 22:39:52 +0300 |
commit | 8a0efa53e44919bcf5ccb1d3353618a82afdf8bc (patch) | |
tree | 68c3dbf3f2c6fd5d49777def9914d77b5cd4589d /newlib/libc/unix/getut.c | |
parent | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (diff) |
import newlib-2000-02-17 snapshot
Diffstat (limited to 'newlib/libc/unix/getut.c')
-rw-r--r-- | newlib/libc/unix/getut.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/newlib/libc/unix/getut.c b/newlib/libc/unix/getut.c new file mode 100644 index 000000000..d716b324c --- /dev/null +++ b/newlib/libc/unix/getut.c @@ -0,0 +1,85 @@ +#include <fcntl.h> +#include <unistd.h> +#include <utmp.h> +#include <_syslist.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 (char *file) +{ + extern char *strdup (char *); + + 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; +} |