/contrib/ntp/libntp/uglydate.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 48 lines · 37 code · 4 blank · 7 comment · 4 complexity · 564b9f7ec75b94af0e33e7a078bcb177 MD5 · raw file

  1. /*
  2. * uglydate - convert a time stamp to something barely readable
  3. * The string returned is 37 characters long.
  4. */
  5. #include <stdio.h>
  6. #include "ntp_fp.h"
  7. #include "ntp_unixtime.h"
  8. #include "lib_strbuf.h"
  9. #include "ntp_stdlib.h"
  10. char *
  11. uglydate(
  12. l_fp *ts
  13. )
  14. {
  15. char *bp;
  16. char *timep;
  17. struct tm *tm;
  18. time_t sec;
  19. long msec;
  20. int year;
  21. timep = ulfptoa(ts, 6); /* returns max 17 characters */
  22. LIB_GETBUF(bp);
  23. sec = ts->l_ui - JAN_1970;
  24. msec = ts->l_uf / 4294967; /* fract / (2**32/1000) */
  25. tm = gmtime(&sec);
  26. if (ts->l_ui == 0) {
  27. /*
  28. * Probably not a real good thing to do. Oh, well.
  29. */
  30. year = 0;
  31. tm->tm_yday = 0;
  32. tm->tm_hour = 0;
  33. tm->tm_min = 0;
  34. tm->tm_sec = 0;
  35. } else {
  36. year = tm->tm_year;
  37. while (year >= 100)
  38. year -= 100;
  39. }
  40. (void) sprintf(bp, "%17s %02d:%03d:%02d:%02d:%02d.%03ld",
  41. timep, year, tm->tm_yday, tm->tm_hour, tm->tm_min,
  42. tm->tm_sec, msec);
  43. return bp;
  44. }