pututline.c revision 22347
122347Spst/* pututline.c: A replacement for the pututline() function
222347Spst
322347Spst%%% copyright-cmetz
422347SpstThis software is Copyright 1996 by Craig Metz, All Rights Reserved.
522347SpstThe Inner Net License Version 2 applies to this software.
622347SpstYou should have received a copy of the license with this software. If
722347Spstyou didn't get a copy, you may request one from <license@inner.net>.
822347Spst
922347Spst        History:
1022347Spst
1122347Spst	Created by cmetz for OPIE 2.3.
1222347Spst*/
1322347Spst
1422347Spst#include "opie_cfg.h"
1522347Spst#include <stdio.h>
1622347Spst#include <utmp.h>
1722347Spst#include "opie.h"
1822347Spst
1922347Spstvoid pututline FUNCTION((utmp), struct utmp *utmp)
2022347Spst{
2122347Spst  FILE *f;
2222347Spst  struct utmp u;
2322347Spst  int i;
2422347Spst
2522347Spst  if (!(f = __opieopen(_PATH_UTMP, 1, 0644)))
2622347Spst    return;
2722347Spst
2822347Spst#if HAVE_TTYSLOT
2922347Spst  if (i = ttyslot()) {
3022347Spst    if (fseek(f, i * sizeof(struct utmp), SEEK_SET) < 0)
3122347Spst      goto ret;
3222347Spst    fwrite(utmp, sizeof(struct utmp), 1, f);
3322347Spst    goto ret;
3422347Spst  }
3522347Spst#endif /* HAVE_TTYSLOT */
3622347Spst
3722347Spst  while(fread(&u, sizeof(struct utmp), 1, f) == sizeof(struct utmp)) {
3822347Spst    if (!strncmp(utmp->ut_line, u.ut_line, sizeof(u.ut_line) - 1)) {
3922347Spst      if ((i = ftell(f)) < 0)
4022347Spst        goto ret;
4122347Spst      if (fseek(f, i - sizeof(struct utmp), SEEK_SET) < 0)
4222347Spst        goto ret;
4322347Spst      fwrite(utmp, sizeof(struct utmp), 1, f);
4422347Spst      goto ret;
4522347Spst    }
4622347Spst  }
4722347Spst
4822347Spst  fclose(f);
4922347Spst
5022347Spst  if (!(f = __opieopen(_PATH_UTMP, 2, 0644)))
5122347Spst    return;
5222347Spst  fwrite(utmp, sizeof(struct utmp), 1, f);
5322347Spst
5422347Spstret:
5522347Spst  fclose(f);
5622347Spst}
57