time.c 440 B

1234567891011121314151617181920212223242526
  1. #include <time.h>
  2. #include <stdio.h>
  3. int main(void) {
  4. struct timespec tm = {0, 0};
  5. int cgt = clock_gettime(CLOCK_REALTIME, &tm);
  6. if (cgt == -1) {
  7. perror("clock_gettime");
  8. return 1;
  9. }
  10. time_t t = time(NULL);
  11. if (t == (time_t)-1) {
  12. perror("time");
  13. return 1;
  14. }
  15. clock_t c = clock();
  16. if (c == (clock_t)-1) {
  17. perror("clock");
  18. return 1;
  19. }
  20. return 0;
  21. }