Coverage Report

Created: 2023-05-19 06:16

/src/ntp-dev/libntp/humandate.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * humandate.c - convert an NTP (or the current) time to something readable
3
 */
4
#include <config.h>
5
#include <stdio.h>
6
7
#include "ntp_fp.h"
8
#include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */
9
#include "lib_strbuf.h"
10
#include "ntp_stdlib.h"
11
12
13
/* This is used in msyslog.c; we don't want to clutter up the log with
14
   the year and day of the week, etc.; just the minimal date and time.  */
15
16
const char *
17
humanlogtime(void)
18
0
{
19
0
  char *    bp;
20
0
  time_t    cursec;
21
0
  struct tm * tm;
22
  
23
0
  cursec = time(NULL);
24
0
  tm = localtime(&cursec);
25
0
  if (!tm)
26
0
    return "-- --- --:--:--";
27
28
0
  LIB_GETBUF(bp);
29
  
30
0
  snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d",
31
0
     tm->tm_mday, months[tm->tm_mon],
32
0
     tm->tm_hour, tm->tm_min, tm->tm_sec);
33
    
34
0
  return bp;
35
0
}
36
37
38
/*
39
 * humantime() -- like humanlogtime() but without date, and with the
40
 *      time to display given as an argument.
41
 */
42
const char *
43
humantime(
44
  time_t cursec
45
  )
46
0
{
47
0
  char *    bp;
48
0
  struct tm * tm;
49
  
50
0
  tm = localtime(&cursec);
51
0
  if (!tm)
52
0
    return "--:--:--";
53
54
0
  LIB_GETBUF(bp);
55
  
56
0
  snprintf(bp, LIB_BUFLENGTH, "%02d:%02d:%02d",
57
0
     tm->tm_hour, tm->tm_min, tm->tm_sec);
58
    
59
0
  return bp;
60
0
}