]> git.ipfire.org Git - thirdparty/glibc.git/blame - login/getutid_r.c
Tue May 28 13:11:19 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[thirdparty/glibc.git] / login / getutid_r.c
CommitLineData
b8fe19fa
RM
1/* Copyright (C) 1996 Free Software Foundation, Inc.
2This file is part of the GNU C Library.
3Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
4
5The GNU C Library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public License as
7published by the Free Software Foundation; either version 2 of the
8License, or (at your option) any later version.
9
10The GNU C Library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with the GNU C Library; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18Boston, MA 02111-1307, USA. */
19
20#include <errno.h>
21#include <unistd.h>
22#include <utmp.h>
23
24
25/* For implementing this function we don't use the getutent_r function
26 because we can avoid the reposition on every new entry this way. */
27int
28getutid_r (const struct utmp *id, struct utmp **utmp,
29 struct utmp_data *utmp_data)
30{
31 /* Open utmp file if not already done. */
32 if (utmp_data->ut_fd == -1)
33 {
34 setutent_r (utmp_data);
35 if (utmp_data->ut_fd == -1)
36 return -1;
37 }
38
39 /* Position file correctly. */
40 if (lseek (utmp_data->ut_fd, utmp_data->loc_utmp, SEEK_SET) == -1)
41 return -1;
42
43 do
44 {
45 /* Read the next entry. */
46 if (read (utmp_data->ut_fd, &utmp_data->ubuf, sizeof (struct utmp))
47 != sizeof (struct utmp))
48 {
49 errno = ESRCH;
50 return -1;
51 }
52
53 /* Update position pointer. */
54 utmp_data->loc_utmp += sizeof (struct utmp);
55 }
56 while (id->ut_type != utmp_data->ubuf.ut_type);
57
58 *utmp = &utmp_data->ubuf;
59
60 return 0;
61}