Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

reddit_stat.c

By: a guest on May 16th, 2013  |  syntax: None  |  size: 1.03 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <sys/stat.h>
  6.  
  7. int main (int argc, char** argv)
  8. {
  9.    int i;
  10.    struct stat stat_data;
  11.    int num_iterations;
  12.    int print;
  13.    int use_filetime;
  14.    int use_time;
  15.    char const* filename;
  16.  
  17.    if (argc != 5)
  18.      {
  19.       fprintf (stderr, "Usage: %s num_iterations print|noprint filetime|time|nothing filename\n", argv[0]);
  20.       return EXIT_FAILURE;
  21.      }
  22.  
  23.    num_iterations= atoi (argv[1]);
  24.    print= argv[2][0] == 'p';
  25.    use_filetime= argv[3][0] == 'f';
  26.    use_time= argv[3][0] == 't';
  27.    filename= argv[4];
  28.  
  29.    for (i=0; i<num_iterations; ++i)
  30.      {
  31.       if (use_filetime)
  32.         {
  33.          stat (filename, &stat_data);
  34.         }
  35.       else if (use_time)
  36.         {
  37.          time (&(stat_data.st_mtime));
  38.         }
  39.       else
  40.         {
  41.          stat_data.st_mtime= 100;
  42.         }
  43.  
  44.       if (print)
  45.         {
  46.          printf ("%u\n", (unsigned int)stat_data.st_mtime);
  47.         }
  48.      }
  49.  
  50.    return EXIT_SUCCESS;
  51. }