home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / TOUCH.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  65 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*----------------------------------------------------------------------*
  4. * Program:     touch                                                    *
  5. * Programmer:  Ray L. McVay                                             *
  6. * Started:     8 Aug 91                                                 *
  7. * Updated:     13 Feb 93 Thad Smith                                     *
  8. * Updated:     15 Feb 93 Bob Stout                                      *
  9. *-----------------------------------------------------------------------*
  10. * Simple touch program to test BC time stamping function.               *
  11. * Public Domain                                                         *
  12. *----------------------------------------------------------------------*/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17. #if defined(__TURBOC__) || defined(__SC__)
  18.  #include <dos.h>
  19.  #include <io.h>
  20. #else
  21.  #include "ftime.h"                 /* Borland work-alike in SNIPPETS   */
  22. #endif
  23.  
  24. void usage(void);
  25.  
  26. main(int argc, char **argv)
  27. {
  28.       time_t    tnow;
  29.       struct tm tmnow;
  30.       struct ftime ft;
  31.       FILE *f;
  32.  
  33.       if (argc < 2)
  34.             usage();
  35.  
  36.       tnow  = time(NULL);
  37.       tmnow = *localtime(&tnow);
  38.  
  39.       ft.ft_year  = tmnow.tm_year - 80;
  40.       ft.ft_month = tmnow.tm_mon + 1;
  41.       ft.ft_day   = tmnow.tm_mday;
  42.       ft.ft_hour  = tmnow.tm_hour;
  43.       ft.ft_min   = tmnow.tm_min;
  44.       ft.ft_tsec  = tmnow.tm_sec/2;
  45.  
  46.       if ((f = fopen(argv[1], "r+b")) != NULL)
  47.             setftime(fileno(f), &ft);
  48.       else if ((f = fopen(argv[1], "w")) != NULL)
  49.             setftime(fileno(f), &ft);
  50.       else  perror("Can't open file");
  51.  
  52.       if (f)
  53.             fclose(f);
  54.  
  55.       return EXIT_SUCCESS;
  56. }
  57.  
  58. void usage(void)
  59. {
  60.       puts("Usage: TOUCH filename\n");
  61.       puts("  The timestamp of filename will be set to the current time.");
  62.       puts("  A zero-length file will be created if the file doesn't exist.");
  63.       exit(EXIT_FAILURE);
  64. }
  65.