kernel - support dummy reallocblks in devfs
[dragonfly.git] / contrib / opie / libmissing / pututline.c
blob718ecbaadde93f0c9e11e4baf5f90a54a0845130
1 /* pututline.c: A replacement for the pututline() function
3 %%% copyright-cmetz-96
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
9 History:
11 Modified by cmetz for OPIE 2.32. Fixed check for fread() return
12 value.
13 Modified by cmetz for OPIE 2.31. If the OS won't tell us where
14 _PATH_UTMP is, use Autoconf-discovered values.
15 Created by cmetz for OPIE 2.3.
18 #include "opie_cfg.h"
19 #include <stdio.h>
20 #include <utmp.h>
21 #include "opie.h"
23 #ifndef _PATH_UTMP
24 #define _PATH_UTMP PATH_UTMP_AC
25 #endif /* _PATH_UTMP */
27 void pututline FUNCTION((utmp), struct utmp *utmp)
29 FILE *f;
30 struct utmp u;
31 int i;
33 if (!(f = __opieopen(_PATH_UTMP, 1, 0644)))
34 return;
36 #if HAVE_TTYSLOT
37 if (i = ttyslot()) {
38 if (fseek(f, i * sizeof(struct utmp), SEEK_SET) < 0)
39 goto ret;
40 fwrite(utmp, sizeof(struct utmp), 1, f);
41 goto ret;
43 #endif /* HAVE_TTYSLOT */
45 while(fread(&u, sizeof(struct utmp), 1, f) == 1) {
46 if (!strncmp(utmp->ut_line, u.ut_line, sizeof(u.ut_line) - 1)) {
47 if ((i = ftell(f)) < 0)
48 goto ret;
49 if (fseek(f, i - sizeof(struct utmp), SEEK_SET) < 0)
50 goto ret;
51 fwrite(utmp, sizeof(struct utmp), 1, f);
52 goto ret;
56 fclose(f);
58 if (!(f = __opieopen(_PATH_UTMP, 2, 0644)))
59 return;
60 fwrite(utmp, sizeof(struct utmp), 1, f);
62 ret:
63 fclose(f);