LCOV - code coverage report
Current view: top level - src - times.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 6 39 15.4 %
Date: 2018-12-11 11:12:16 Functions: 1 4 25.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "times.h"
       3             : 
       4             : static const char *format_datestr(const struct tm *ctm)
       5             : {
       6             :         static char buf[32]="";
       7         118 :         strftime(buf, sizeof(buf), DEFAULT_TIMESTAMP_FORMAT, ctm);
       8             :         return buf;
       9             : }
      10             : 
      11         119 : const char *getdatestr(const time_t t)
      12             : {
      13         119 :         const struct tm *ctm=NULL;
      14             : 
      15         119 :         if(!t
      16         118 :           || !(ctm=localtime(&t)))
      17             :                 return "never";
      18         118 :         return format_datestr(ctm);
      19             : }
      20             : 
      21           0 : const char *gettimenow(void)
      22             : {
      23           0 :         time_t t=0;
      24           0 :         time(&t);
      25           0 :         return getdatestr(t);
      26             : }
      27             : 
      28           0 : const char *time_taken(time_t d)
      29             : {
      30             :         static char str[32]="";
      31           0 :         int seconds=0;
      32           0 :         int minutes=0;
      33           0 :         int hours=0;
      34           0 :         int days=0;
      35           0 :         char ss[4]="";
      36           0 :         char ms[4]="";
      37           0 :         char hs[4]="";
      38           0 :         char ds[4]="";
      39           0 :         seconds=d % 60;
      40           0 :         minutes=(d/60) % 60;
      41           0 :         hours=(d/60/60) % 24;
      42           0 :         days=(d/60/60/24);
      43           0 :         if(days)
      44             :         {
      45           0 :                 snprintf(ds, sizeof(ds), "%02d:", days);
      46           0 :                 snprintf(hs, sizeof(hs), "%02d:", hours);
      47             :         }
      48           0 :         else if(hours)
      49             :         {
      50           0 :                 snprintf(hs, sizeof(hs), "%02d:", hours);
      51             :         }
      52           0 :         snprintf(ms, sizeof(ms), "%02d:", minutes);
      53           0 :         snprintf(ss, sizeof(ss), "%02d", seconds);
      54           0 :         snprintf(str, sizeof(str), "%s%s%s%s", ds, hs, ms, ss);
      55           0 :         return str;
      56             : }
      57             : 
      58           0 : char *encode_time(time_t utime, char *buf)
      59             : {
      60             :         const struct tm *tm;
      61           0 :         int n=0;
      62           0 :         time_t time=utime;
      63             : 
      64             : #ifdef HAVE_WIN32
      65             :         /* Avoid a seg fault in Microsoft's CRT localtime_r(),
      66             :          *  which incorrectly references a NULL returned from gmtime() if
      67             :          *  time is negative before or after the timezone adjustment. */
      68             :         struct tm *gtm;
      69             : 
      70             :         if(!(gtm=gmtime(&time))) return buf;
      71             : 
      72             :         if(gtm->tm_year==1970 && gtm->tm_mon==1 && gtm->tm_mday<3) return buf;
      73             : #endif
      74             : 
      75           0 :         if((tm=localtime(&time)))
      76           0 :                 n=sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d",
      77           0 :                         tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
      78             :                         tm->tm_hour, tm->tm_min, tm->tm_sec);
      79           0 :         return buf+n;
      80             : }

Generated by: LCOV version 1.13