home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libcnews / time.c < prev    next >
C/C++ Source or Header  |  1990-03-05  |  659b  |  31 lines

  1. /*
  2.  * time utilities
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/timeb.h>
  8. #include "libc.h"
  9. #include "news.h"
  10.  
  11. /*
  12.  * Write a timestamp of the form "Jun 12 12:34:56.789" on fp.
  13.  * N.B.: no trailing newline is written.
  14.  */
  15. void
  16. timestamp(fp, timep)
  17. FILE *fp;
  18. time_t *timep;    /* if non-null, return time() here for later use */
  19. {
  20.     struct timeb ftnow;
  21.     char ms[STRLEN("123") + SIZENUL];
  22.  
  23.     ftime(&ftnow);
  24.     if (timep != NULL)
  25.         *timep = ftnow.time;
  26.     /* .15 excludes yyyy\n\0; + 4 omits day-of-week */
  27.     (void) fprintf(fp, "%.15s.", ctime(&ftnow.time) + 4);
  28.     (void) ltoza(ms, (long)ftnow.millitm, 3);    /* 3 digits of output */
  29.     (void) fputs(ms, fp);
  30. }
  31.