time.c 504 B

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