/contrib/ntp/libntp/tvtoa.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 39 lines · 29 code · 7 blank · 3 comment · 3 complexity · 98469bd5b404519973f8bb81950b075c MD5 · raw file

  1. /*
  2. * tvtoa - return an asciized representation of a struct timeval
  3. */
  4. #include "lib_strbuf.h"
  5. #if defined(VMS)
  6. # include "ntp_fp.h"
  7. #endif /* VMS */
  8. #include "ntp_stdlib.h"
  9. #include "ntp_unixtime.h"
  10. #include <stdio.h>
  11. char *
  12. tvtoa(
  13. const struct timeval *tv
  14. )
  15. {
  16. register char *buf;
  17. register u_long sec;
  18. register u_long usec;
  19. register int isneg;
  20. if (tv->tv_sec < 0 || tv->tv_usec < 0) {
  21. sec = -tv->tv_sec;
  22. usec = -tv->tv_usec;
  23. isneg = 1;
  24. } else {
  25. sec = tv->tv_sec;
  26. usec = tv->tv_usec;
  27. isneg = 0;
  28. }
  29. LIB_GETBUF(buf);
  30. (void) sprintf(buf, "%s%lu.%06lu", (isneg?"-":""), sec, usec);
  31. return buf;
  32. }