summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-06-20 06:56:52 +0000
committerJim Meyering <jim@meyering.net>2004-06-20 06:56:52 +0000
commit0171abddcd6b2ccb644772d371bb1a97b87f21b0 (patch)
tree7e4e543043dd7a0886212bd1c900d233548d556a /src
parentf2d779e87c20bc37c3e60194c3a5c1f0f3f7c1f4 (diff)
downloadcoreutils-0171abddcd6b2ccb644772d371bb1a97b87f21b0.tar.xz
Don't dump core if ctime returns NULL; this is possible on
hosts with 64-bit time_t and 32-bit int. Include "inttostr.h". (time_string): New function, copied from who.c. (print_entry): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/pinky.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/pinky.c b/src/pinky.c
index 485f325ac..f3c157b2b 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -26,6 +26,7 @@
#include "system.h"
#include "error.h"
+#include "inttostr.h"
#include "readutmp.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -160,6 +161,33 @@ idle_string (time_t when)
return (const char *) idle_hhmm;
}
+/* Return a standard time string, "mon dd hh:mm"
+ FIXME: handle localization */
+static const char *
+time_string (const STRUCT_UTMP *utmp_ent)
+{
+ /* Don't take the address of UT_TIME_MEMBER directly.
+ Ulrich Drepper wrote:
+ ``... GNU libc (and perhaps other libcs as well) have extended
+ utmp file formats which do not use a simple time_t ut_time field.
+ In glibc, ut_time is a macro which selects for backward compatibility
+ the tv_sec member of a struct timeval value.'' */
+ time_t tm = UT_TIME_MEMBER (utmp_ent);
+
+ char *ptr = ctime (&tm);
+ if (ptr)
+ {
+ ptr += 4;
+ ptr[12] = '\0';
+ }
+ else
+ {
+ static char buf[INT_BUFSIZE_BOUND (intmax_t)];
+ ptr = (TYPE_SIGNED (time_t) ? imaxtostr (tm, buf) : umaxtostr (tm, buf));
+ }
+ return ptr;
+}
+
/* Display a line of information about UTMP_ENT. */
static void
@@ -173,7 +201,6 @@ print_entry (const STRUCT_UTMP *utmp_ent)
#define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
- time_t tm;
/* Copy ut_line into LINE, prepending `/dev/' if ut_line is not
already an absolute pathname. Some system may put the full,
@@ -238,14 +265,7 @@ print_entry (const STRUCT_UTMP *utmp_ent)
printf (" %-6s", "???");
}
- /* Don't take the address of UT_TIME_MEMBER directly.
- Ulrich Drepper wrote:
- ``... GNU libc (and perhaps other libcs as well) have extended
- utmp file formats which do not use a simple time_t ut_time field.
- In glibc, ut_time is a macro which selects for backward compatibility
- the tv_sec member of a struct timeval value.'' */
- tm = UT_TIME_MEMBER (utmp_ent);
- printf (" %-12.12s", ctime (&tm) + 4);
+ printf (" %s", time_string (utmp_ent));
#ifdef HAVE_UT_HOST
if (include_where && utmp_ent->ut_host[0])