Update.
[glibc.git] / login / programs / xtmp.c
blobe27e1a8a86d77e9c8d925cfcf9029571c6afb8fe
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <utmp.h>
26 #include "xtmp.h"
28 /* Convert the entry XT to the new utmp format and store it in UT.
29 Fields in UT that were not present in the old utmp format are
30 initialized to zero. */
31 void
32 xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp)
34 memset (utmp, 0, sizeof (struct utmp));
35 #if _HAVE_XT_TYPE - 0
36 utmp->ut_type = xtmp->xt_type;
37 #endif
38 #if _HAVE_XT_PID - 0
39 utmp->ut_pid = xtmp->xt_pid;
40 #endif
41 strncpy (utmp->ut_line, xtmp->xt_line, XT_LINESIZE);
42 #if _HAVE_XT_ID - 0
43 strncpy (utmp->ut_id, xtmp->xt_id, sizeof xtmp->xt_id);
44 #endif
45 #if _HAVE_UT_TV - 0
46 utmp->ut_tv.tv_sec = xtmp->xt_time;
47 #else
48 utmp->ut_time = xtmp->xt_time;
49 #endif
50 strncpy (utmp->ut_user, xtmp->xt_user, XT_NAMESIZE);
51 #if _HAVE_XT_HOST - 0
52 strncpy (utmp->ut_host, xtmp->xt_host, XT_HOSTSIZE);
53 #endif
54 utmp->ut_addr = xtmp->xt_addr;
57 /* Convert the entry UTMP to the old utmp format and store it in XTMP. */
58 void
59 utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp)
61 memset (xtmp, 0, sizeof (struct xtmp));
62 #if _HAVE_XT_TYPE - 0
63 xtmp->xt_type = utmp->ut_type;
64 #endif
65 #if _HAVE_XT_PID - 0
66 xtmp->xt_pid = utmp->ut_pid;
67 #endif
68 strncpy (xtmp->xt_line, utmp->ut_line, XT_LINESIZE);
69 xtmp->xt_line[XT_LINESIZE] = '\0';
70 #if _HAVE_XT_ID - 0
71 strncpy (xtmp->xt_id, utmp->ut_id, sizeof xtmp->xt_id);
72 #endif
73 #if _HAVE_UT_TV - 0
74 xtmp->xt_time = utmp->ut_tv.tv_sec;
75 #else
76 xtmp->xt_time = utmp->ut_time;
77 #endif
78 strncpy (xtmp->xt_user, utmp->ut_user, XT_NAMESIZE);
79 #if _HAVE_XT_HOST - 0
80 strncpy (xtmp->xt_host, utmp->ut_host, XT_HOSTSIZE);
81 xtmp->xt_host[XT_HOSTSIZE] = '\0';
82 #endif
83 xtmp->xt_addr = utmp->ut_addr;
86 /* Compare an old style entry XTMP with a new style entry UTMP. The
87 function returns 1 if the information that is in both old and new
88 style entries is identical. Otherwise this function returns 0.
90 The type of the argument `xtmp' is `struct utmp *', not `struct
91 utmp *'. This is intentional! We convert from and to `struct
92 xtmp' directly when we read and write an old style entry. But
93 since XTMP is converted from an old style entry, we compare only
94 those elements of the structure that are common to both the new and
95 the old style entry. */
96 int
97 compare_entry (const struct utmp *xtmp, const struct utmp *utmp)
99 return
101 #if _HAVE_XT_TYPE - 0
102 xtmp->ut_type == utmp->ut_type
103 #endif
104 #if _HAVE_XT_PID - 0
105 && xtmp->ut_pid == utmp->ut_pid
106 #endif
107 && !strncmp (xtmp->ut_line, utmp->ut_line, XT_LINESIZE - 1)
108 #if _HAVE_XT_ID - 0
109 && !strncmp (xtmp->ut_id, utmp->ut_id, sizeof utmp->ut_id)
110 #endif
111 #if _HAVE_UT_TV - 0
112 && xtmp->ut_tv.tv_sec == utmp->ut_tv.tv_sec
113 #else
114 && xtmp->ut_time == utmp->ut_time
115 #endif
116 && !strncmp (xtmp->ut_user, utmp->ut_user, XT_NAMESIZE)
117 #if _HAVE_XT_HOST - 0
118 && !strncmp (xtmp->ut_host, utmp->ut_host, XT_HOSTSIZE - 1)
119 #endif
120 && xtmp->ut_addr == utmp->ut_addr);