C   126

filetime.c

Guest on 4th September 2021 05:42:58 AM

  1. // A minimal Win32 console app
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. int newer(char *, char*);
  8. int mtime(char *);
  9.  
  10. /* test if file1 is more recent than file2 */
  11. int newer(char *file1, char* file2){
  12.     int mtime(char* file);
  13.     int t1=mtime(file1), t2 = mtime(file2);  
  14.     if (t1< 0 || t2 > 0) return (-1);
  15.     else if (t1 > t2)  return (1);
  16.     else  return(0);
  17. }
  18.  
  19. int mtime(char *file){
  20.     struct stat stb;
  21.     if (stat(file, &stb) < 0)  return (-1);  
  22.           //  prototype: int  stat(char* file, struct stat *buf)
  23.     return (stb.st_mtime);
  24. }
  25.  
  26.  
  27.  
  28. int main(int argc, char *argv[]){
  29.   printf("%s  %ld\n", argv[1], mtime(argv[1]));
  30.   printf("%s  %ld\n", argv[2], mtime(argv[2]));
  31.  
  32.   /*
  33.   if (argc >2) {
  34.    int value = newer(argv[1], argv[2]);
  35.    if (value==1)
  36.     printf("%s  is newer than %s\n ", argv[1], argv[2]);
  37.    if (value == 0)
  38.      printf("%s  is older than %s\n ", argv[1], argv[2]);
  39.   }
  40.   */
  41.   return 0;
  42. }

Raw Paste


Login or Register to edit or fork this paste. It's free.