write: make timestamp to be obviously just a clock time
By looking the code one will had hard time knowing that a slice of ctime() from characters 11 to 16 is HH:MM time format. Use of strftime("%H:%M") makes this a lot less mysterious. In same go make \007 hex printouts to be \a that is the same thing: alarm. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
c1d0a95eea
commit
a079439266
|
@ -239,9 +239,10 @@ static void write_line(char *s)
|
||||||
*/
|
*/
|
||||||
static void do_write(const struct write_control *ctl)
|
static void do_write(const struct write_control *ctl)
|
||||||
{
|
{
|
||||||
char *login, *pwuid, *time_stamp;
|
char *login, *pwuid, timestamp[6];
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
struct tm *tm;
|
||||||
char path[PATH_MAX], *host, line[512];
|
char path[PATH_MAX], *host, line[512];
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
|
|
||||||
|
@ -265,21 +266,21 @@ static void do_write(const struct write_control *ctl)
|
||||||
sigaction(SIGINT, &sigact, NULL);
|
sigaction(SIGINT, &sigact, NULL);
|
||||||
sigaction(SIGHUP, &sigact, NULL);
|
sigaction(SIGHUP, &sigact, NULL);
|
||||||
|
|
||||||
/* print greeting */
|
|
||||||
host = xgethostname();
|
host = xgethostname();
|
||||||
if (!host)
|
if (!host)
|
||||||
host = xstrdup("???");
|
host = xstrdup("???");
|
||||||
|
|
||||||
now = time((time_t *)NULL);
|
now = time((time_t *)NULL);
|
||||||
time_stamp = ctime(&now);
|
tm = localtime(&now);
|
||||||
time_stamp[16] = '\0';
|
strftime(timestamp, sizeof(timestamp), "%H:%M", tm);
|
||||||
printf("\r\n\007\007\007");
|
/* print greeting */
|
||||||
|
printf("\r\n\a\a\a");
|
||||||
if (strcmp(login, pwuid))
|
if (strcmp(login, pwuid))
|
||||||
printf(_("Message from %s@%s (as %s) on %s at %s ..."),
|
printf(_("Message from %s@%s (as %s) on %s at %s ..."),
|
||||||
login, host, pwuid, ctl->src_tty, time_stamp + 11);
|
login, host, pwuid, ctl->src_tty, timestamp);
|
||||||
else
|
else
|
||||||
printf(_("Message from %s@%s on %s at %s ..."),
|
printf(_("Message from %s@%s on %s at %s ..."),
|
||||||
login, host, ctl->src_tty, time_stamp + 11);
|
login, host, ctl->src_tty, timestamp);
|
||||||
free(host);
|
free(host);
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue