Logo Search packages:      
Sourcecode: libnl version File versions  Download package

char* nl_msec2str ( uint64_t  msec,
char *  buf,
size_t  len 
)

Convert milliseconds to a character string

  • msec number of milliseconds
  • buf destination buffer
  • len buffer length
Converts milliseconds to a character string split up in days, hours, minutes, seconds, and milliseconds and stores it in the specified destination buffer.

Returns:
The destination buffer.

Definition at line 392 of file utils.c.

{
      int i, split[5];
      char *units[] = {"d", "h", "m", "s", "msec"};

#define _SPLIT(idx, unit) if ((split[idx] = msec / unit) > 0) msec %= unit
      _SPLIT(0, 86400000);    /* days */
      _SPLIT(1, 3600000);     /* hours */
      _SPLIT(2, 60000); /* minutes */
      _SPLIT(3, 1000);  /* seconds */
#undef  _SPLIT
      split[4] = msec;

      memset(buf, 0, len);

      for (i = 0; i < ARRAY_SIZE(split); i++) {
            if (split[i] > 0) {
                  char t[64];
                  snprintf(t, sizeof(t), "%s%d%s",
                         strlen(buf) ? " " : "", split[i], units[i]);
                  strncat(buf, t, len - strlen(buf) - 1);
            }
      }

      return buf;
}


Generated by  Doxygen 1.6.0   Back to index