pututline.c revision 29964
1/* pututline.c: A replacement for the pututline() function 2 3%%% copyright-cmetz-96 4This software is Copyright 1996-1997 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 Modified by cmetz for OPIE 2.31. If the OS won't tell us where 12 _PATH_UTMP is, use Autoconf-discovered values. 13 Created by cmetz for OPIE 2.3. 14*/ 15 16#include "opie_cfg.h" 17#include <stdio.h> 18#include <utmp.h> 19#include "opie.h" 20 21#ifndef _PATH_UTMP 22#define _PATH_UTMP PATH_UTMP_AC 23#endif /* _PATH_UTMP */ 24 25void pututline FUNCTION((utmp), struct utmp *utmp) 26{ 27 FILE *f; 28 struct utmp u; 29 int i; 30 31 if (!(f = __opieopen(_PATH_UTMP, 1, 0644))) 32 return; 33 34#if HAVE_TTYSLOT 35 if (i = ttyslot()) { 36 if (fseek(f, i * sizeof(struct utmp), SEEK_SET) < 0) 37 goto ret; 38 fwrite(utmp, sizeof(struct utmp), 1, f); 39 goto ret; 40 } 41#endif /* HAVE_TTYSLOT */ 42 43 while(fread(&u, sizeof(struct utmp), 1, f) == sizeof(struct utmp)) { 44 if (!strncmp(utmp->ut_line, u.ut_line, sizeof(u.ut_line) - 1)) { 45 if ((i = ftell(f)) < 0) 46 goto ret; 47 if (fseek(f, i - sizeof(struct utmp), SEEK_SET) < 0) 48 goto ret; 49 fwrite(utmp, sizeof(struct utmp), 1, f); 50 goto ret; 51 } 52 } 53 54 fclose(f); 55 56 if (!(f = __opieopen(_PATH_UTMP, 2, 0644))) 57 return; 58 fwrite(utmp, sizeof(struct utmp), 1, f); 59 60ret: 61 fclose(f); 62} 63