libdm.c 482 B

12345678910111213141516171819202122232425
  1. #include <time.h>
  2. #include <sys/time.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. int verbose = 0;
  7. void printdate(FILE *fd)
  8. {
  9. struct timespec tp;
  10. char buf[64U] = "!DATE!";
  11. size_t tail;
  12. if (!clock_gettime(CLOCK_REALTIME, &tp)) {
  13. tail = strftime(buf, sizeof buf, "%x %X", localtime(&tp.tv_sec));
  14. if ((tail > 0) && (sizeof buf < tail)) {
  15. snprintf(buf + tail, (sizeof buf) - tail, ".%03ld", (tp.tv_nsec / 1000000));
  16. }
  17. }
  18. fprintf(fd, "%s: ", buf);
  19. }