/* Tests for UTMP functions.
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001-2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
#include <errno.h>
#include <error.h>
#endif
+#if _HAVE_UT_TYPE || defined UTMPX
+
/* Prototype for our test function. */
static int do_test (int argc, char *argv[]);
error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
}
-
struct utmp entry[] =
{
- { ut_type: BOOT_TIME, ut_pid: 1, ut_tv: { tv_sec: 1000 } },
- { ut_type: RUN_LVL, ut_pid: 1, ut_tv: { tv_sec: 2000 } },
- { ut_type: INIT_PROCESS, ut_pid: 5, ut_id: "si", ut_tv: { tv_sec: 3000 } },
- { ut_type: LOGIN_PROCESS, ut_pid: 23, ut_line: "tty1", ut_id: "1",
- ut_user: "LOGIN", ut_session: 23, ut_tv: { tv_sec: 4000 } },
- { ut_type: USER_PROCESS, ut_pid: 24, ut_line: "tty2", ut_id: "2",
- ut_user: "albert", ut_session: 24, ut_tv: { tv_sec: 8000 } },
- { ut_type: USER_PROCESS, ut_pid: 196, ut_line: "ttyp0", ut_id: "p0",
- ut_user: "niels", ut_session: 196, ut_tv: { tv_sec: 10000 } },
- { ut_type: DEAD_PROCESS, ut_line: "ttyp1", ut_id: "p1",
- ut_tv: { tv_sec: 16000 } },
- { ut_type: EMPTY },
- { ut_type: EMPTY }
+#if _HAVE_UT_TV || defined UTMPX
+#define UT(a) .ut_tv = { .tv_sec = (a)}
+#else
+#define UT(a) .ut_time = (a)
+#endif
+
+ { .ut_type = BOOT_TIME, .ut_pid = 1, UT(1000) },
+ { .ut_type = RUN_LVL, .ut_pid = 1, UT(2000) },
+ { .ut_type = INIT_PROCESS, .ut_pid = 5, .ut_id = "si", UT(3000) },
+ { .ut_type = LOGIN_PROCESS, .ut_pid = 23, .ut_line = "tty1", .ut_id = "1",
+ .ut_user = "LOGIN", UT(4000) },
+ { .ut_type = USER_PROCESS, .ut_pid = 24, .ut_line = "tty2", .ut_id = "2",
+ .ut_user = "albert", UT(8000) },
+ { .ut_type = USER_PROCESS, .ut_pid = 196, .ut_line = "ttyp0", .ut_id = "p0",
+ .ut_user = "niels", UT(10000) },
+ { .ut_type = DEAD_PROCESS, .ut_line = "ttyp1", .ut_id = "p1", UT(16000) },
+ { .ut_type = EMPTY },
+ { .ut_type = EMPTY }
};
int num_entries = sizeof entry / sizeof (struct utmp);
if (entry[n].ut_pid == DEAD_PROCESS)
entry[n].ut_pid = (entry_pid += 27);
entry[n].ut_type = USER_PROCESS;
- strcpy (entry[n].ut_user, user);
+ strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
+#if _HAVE_UT_TV - 0 || defined UTMPX
entry[n].ut_tv.tv_sec = (entry_time += 1000);
-
+#else
+ entry[n].ut_time = (entry_time += 1000);
+#endif
setutent ();
if (pututline (&entry[n]) == NULL)
if (strcmp (line, entry[n].ut_line) == 0)
{
entry[n].ut_type = DEAD_PROCESS;
- entry[n].ut_user[0] = '\0';
- entry[n].ut_tv.tv_sec = (entry_time += 1000);
-
+ strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
+#if _HAVE_UT_TV - 0 || defined UTMPX
+ entry[n].ut_tv.tv_sec = (entry_time += 1000);
+#else
+ entry[n].ut_time = (entry_time += 1000);
+#endif
setutent ();
if (pututline (&entry[n]) == NULL)
return result;
}
+
+#else
+
+/* No field 'ut_type' in struct utmp. */
+int
+main ()
+{
+ return 0;
+}
+
+#endif