122347Spst/* pututline.c: A replacement for the pututline() function 222347Spst 329964Sache%%% copyright-cmetz-96 492906SmarkmThis software is Copyright 1996-2001 by Craig Metz, All Rights Reserved. 592906SmarkmThe Inner Net License Version 3 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 1159118Skris Modified by cmetz for OPIE 2.32. Fixed check for fread() return 1259118Skris value. 1329964Sache Modified by cmetz for OPIE 2.31. If the OS won't tell us where 1429964Sache _PATH_UTMP is, use Autoconf-discovered values. 1522347Spst Created by cmetz for OPIE 2.3. 1622347Spst*/ 1722347Spst 1822347Spst#include "opie_cfg.h" 1922347Spst#include <stdio.h> 2022347Spst#include <utmp.h> 2122347Spst#include "opie.h" 2222347Spst 2329964Sache#ifndef _PATH_UTMP 2429964Sache#define _PATH_UTMP PATH_UTMP_AC 2529964Sache#endif /* _PATH_UTMP */ 2629964Sache 2722347Spstvoid pututline FUNCTION((utmp), struct utmp *utmp) 2822347Spst{ 2922347Spst FILE *f; 3022347Spst struct utmp u; 3122347Spst int i; 3222347Spst 3322347Spst if (!(f = __opieopen(_PATH_UTMP, 1, 0644))) 3422347Spst return; 3522347Spst 3622347Spst#if HAVE_TTYSLOT 3722347Spst if (i = ttyslot()) { 3822347Spst if (fseek(f, i * sizeof(struct utmp), SEEK_SET) < 0) 3922347Spst goto ret; 4022347Spst fwrite(utmp, sizeof(struct utmp), 1, f); 4122347Spst goto ret; 4222347Spst } 4322347Spst#endif /* HAVE_TTYSLOT */ 4422347Spst 4559118Skris while(fread(&u, sizeof(struct utmp), 1, f) == 1) { 4622347Spst if (!strncmp(utmp->ut_line, u.ut_line, sizeof(u.ut_line) - 1)) { 4722347Spst if ((i = ftell(f)) < 0) 4822347Spst goto ret; 4922347Spst if (fseek(f, i - sizeof(struct utmp), SEEK_SET) < 0) 5022347Spst goto ret; 5122347Spst fwrite(utmp, sizeof(struct utmp), 1, f); 5222347Spst goto ret; 5322347Spst } 5422347Spst } 5522347Spst 5622347Spst fclose(f); 5722347Spst 5822347Spst if (!(f = __opieopen(_PATH_UTMP, 2, 0644))) 5922347Spst return; 6022347Spst fwrite(utmp, sizeof(struct utmp), 1, f); 6122347Spst 6222347Spstret: 6322347Spst fclose(f); 6422347Spst} 65