aboutsummaryrefslogtreecommitdiff
path: root/login
diff options
context:
space:
mode:
Diffstat (limited to 'login')
-rw-r--r--login/programs/utmpdump.c48
-rw-r--r--login/tst-utmp.c19
2 files changed, 56 insertions, 11 deletions
diff --git a/login/programs/utmpdump.c b/login/programs/utmpdump.c
index bb650a4ec8..6d19225d07 100644
--- a/login/programs/utmpdump.c
+++ b/login/programs/utmpdump.c
@@ -1,5 +1,5 @@
/* utmpdump - dump utmp-like files.
- Copyright (C) 1997 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
@@ -29,15 +29,47 @@
static void
print_entry (struct utmp *up)
{
-#if _HAVE_UT_TV - 0
- printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s] [%ld]\n",
- up->ut_type, up->ut_pid, up->ut_id, up->ut_user,
- up->ut_line, 4 + ctime (&up->ut_tv.tv_sec), up->ut_tv.tv_usec);
+ (printf) (
+ /* The format string. */
+#if _HAVE_UT_TYPE
+ "[%d] "
+#endif
+#if _HAVE_UT_PID
+ "[%05d] "
+#endif
+#if _HAVE_UT_ID
+ "[%-4.4s] "
+#endif
+ "[%-8.8s] [%-12.12s]"
+#if _HAVE_UT_HOST
+ " [%-16.16s]"
+#endif
+ " [%-15.15s]"
+#if _HAVE_UT_TV
+ " [%ld]"
+#endif
+ "\n"
+ /* The arguments. */
+#if _HAVE_UT_TYPE
+ , up->ut_type
+#endif
+#if _HAVE_UT_PID
+ , up->ut_pid
+#endif
+#if _HAVE_UT_ID
+ , up->ut_id
+#endif
+ , up->ut_user, up->ut_line
+#if _HAVE_UT_HOST
+ , up->ut_host
+#endif
+#if _HAVE_UT_TV
+ , 4 + ctime (&up->ut_tv.tv_sec)
+ , up->ut_tv.tv_usec
#else
- printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s]\n",
- up->ut_type, up->ut_pid, up->ut_id, up->ut_user,
- up->ut_line, 4 + ctime (&up->ut_time));
+ , 4 + ctime (&up->ut_time)
#endif
+ );
}
int
diff --git a/login/tst-utmp.c b/login/tst-utmp.c
index 4b922e6386..e008bcb320 100644
--- a/login/tst-utmp.c
+++ b/login/tst-utmp.c
@@ -1,5 +1,5 @@
/* Tests for UTMP functions.
- Copyright (C) 1998, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001-2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
@@ -40,6 +40,8 @@
#endif
+#if _HAVE_UT_TYPE || defined UTMPX
+
/* Prototype for our test function. */
static int do_test (int argc, char *argv[]);
@@ -165,7 +167,7 @@ simulate_login (const char *line, const char *user)
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
@@ -199,7 +201,7 @@ simulate_logout (const char *line)
if (strcmp (line, entry[n].ut_line) == 0)
{
entry[n].ut_type = DEAD_PROCESS;
- entry[n].ut_user[0] = '\0';
+ 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
@@ -389,3 +391,14 @@ do_test (int argc, char *argv[])
return result;
}
+
+#else
+
+/* No field 'ut_type' in struct utmp. */
+int
+main ()
+{
+ return 0;
+}
+
+#endif