pututline.c revision 22347
1/* pututline.c: A replacement for the pututline() function
2
3%%% copyright-cmetz
4This software is Copyright 1996 by Craig Metz, All Rights Reserved.
5The Inner Net License Version 2 applies to this software.
6You should have received a copy of the license with this software. If
7you didn't get a copy, you may request one from <license@inner.net>.
8
9        History:
10
11	Created by cmetz for OPIE 2.3.
12*/
13
14#include "opie_cfg.h"
15#include <stdio.h>
16#include <utmp.h>
17#include "opie.h"
18
19void pututline FUNCTION((utmp), struct utmp *utmp)
20{
21  FILE *f;
22  struct utmp u;
23  int i;
24
25  if (!(f = __opieopen(_PATH_UTMP, 1, 0644)))
26    return;
27
28#if HAVE_TTYSLOT
29  if (i = ttyslot()) {
30    if (fseek(f, i * sizeof(struct utmp), SEEK_SET) < 0)
31      goto ret;
32    fwrite(utmp, sizeof(struct utmp), 1, f);
33    goto ret;
34  }
35#endif /* HAVE_TTYSLOT */
36
37  while(fread(&u, sizeof(struct utmp), 1, f) == sizeof(struct utmp)) {
38    if (!strncmp(utmp->ut_line, u.ut_line, sizeof(u.ut_line) - 1)) {
39      if ((i = ftell(f)) < 0)
40        goto ret;
41      if (fseek(f, i - sizeof(struct utmp), SEEK_SET) < 0)
42        goto ret;
43      fwrite(utmp, sizeof(struct utmp), 1, f);
44      goto ret;
45    }
46  }
47
48  fclose(f);
49
50  if (!(f = __opieopen(_PATH_UTMP, 2, 0644)))
51    return;
52  fwrite(utmp, sizeof(struct utmp), 1, f);
53
54ret:
55  fclose(f);
56}
57