home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xfss1.exe / XFSS1.C next >
C/C++ Source or Header  |  1995-08-28  |  5KB  |  187 lines

  1. /**************************************************************************
  2. ** File: xfss1.c
  3. **
  4. ** Desc: Example program showing how to set a file date and time using
  5. **       ChangeDirectoryEntry()
  6. **
  7. **
  8. **   DISCLAIMER  
  9. **  
  10. **   Novell, Inc. makes no representations or warranties with respect to
  11. **   any NetWare software, and specifically disclaims any express or
  12. **   implied warranties of merchantability, title, or fitness for a
  13. **   particular purpose.  
  14. **
  15. **   Distribution of any NetWare software is forbidden without the
  16. **   express written consent of Novell, Inc.  Further, Novell reserves
  17. **   the right to discontinue distribution of any NetWare software.
  18. **   
  19. **   Novell is not responsible for lost profits or revenue, loss of use
  20. **   of the software, loss of data, costs of re-creating lost data, the
  21. **   cost of any substitute equipment or program, or claims by any party
  22. **   other than you.  Novell strongly recommends a backup be made before
  23. **   any software is installed.   Technical support for this software
  24. **   may be provided at the discretion of Novell.
  25. **
  26. **
  27. ** QMK386 Options
  28. **
  29. **    none
  30. **
  31. **
  32. ** Programmers:
  33. **
  34. **    Ini   Who                  Firm
  35. **    ---------------------------------------------------------------------
  36. **    DWH   Dirk W. Howard       Novell Developer Support
  37. **
  38. **
  39. ** History:
  40. **
  41. **    When        Who      What
  42. **    ---------------------------------------------------------------------
  43. **    8-28-1995    DWH      First code.
  44. **
  45. */
  46.  
  47. /**************************************************************************
  48. ** Macro definitions & function prototypes
  49. */
  50.  
  51.    /*------------------------------------------------
  52.    ** Include Headers
  53.    */
  54.    #include <stdlib.h>
  55.    #include <stdio.h>
  56.    #include <string.h>
  57.    #include <nwfile.h>
  58.    #include <time.h>
  59.    #include <dos.h>
  60.    #include <nwdir.h>
  61.    #include <direct.h>
  62.    #include <share.h>
  63.    #include <io.h>
  64.    #include <fcntl.h>
  65.    #include <process.h>
  66.  
  67. char FileName[128];
  68.  
  69. struct dirent *dirBuf; struct ModifyStructure mods;
  70. LONG   mbits;
  71. DIR    *dp; time_t currtime;
  72. LONG   sectime;
  73. LONG   *lptr; char   fileDateAndTime[ 40 ]; struct _DOSTime filTim; struct _DOSDate filDat;
  74.  
  75.  
  76. int main( int argc, char *argv[] )
  77. {
  78.    int result;
  79.    LONG lTemp;
  80.    struct tm Century;
  81.  
  82.    if ( argc < 2 )
  83.    {
  84.       printf( "Usage: %s <filename>\r\n", argv[0] );
  85.       return 1;
  86.    }
  87.  
  88.    strcpy( FileName, argv[1] );
  89.    printf( "%s\r\n\r\n", FileName );
  90.  
  91.    /*------------------------------------------------
  92.    ** Display specified file's file date & time information
  93.    */
  94.    dp = opendir( FileName );
  95.    if ( dp != NULL )
  96.    {
  97.       dirBuf = readdir( dp );
  98.       if ( dirBuf != NULL )
  99.       {
  100.          lptr = (LONG *) &dirBuf->d_time;
  101.          sectime = _ConvertDOSTimeToCalendar( *lptr );
  102.          printf("Old date and time: %s\r\n", ctime(§ime));
  103.          closedir( dp );
  104.       } 
  105.       else 
  106.       {
  107.          printf("first readdir() failed.\n");
  108.          return -1;
  109.       }
  110.    } 
  111.    else 
  112.    {
  113.       printf("Could not find %s in the SYSTEM directory.\n", FileName);
  114.       return -1;
  115.    }
  116.  
  117.  
  118.    /*------------------------------------------------
  119.    ** Get and display current system time and date
  120.    */
  121.    currtime = time( NULL );
  122.    printf("Current time and date is %s\r\n", ctime(&currtime));
  123.    mbits = MLastUpdatedInSecondsBit;
  124.  
  125.    /*------------------------------------------------
  126.    ** Get system time & date for setting the files time & date
  127.    */
  128.    lTemp = (LONG)time( NULL );
  129.  
  130.    /*------------------------------------------------
  131.    ** File in tm structure to use a zero reference point that
  132.    ** ChangeDirectoryEntry expects.  Zero point for ChangeDirectoryEntry
  133.    ** is 1/1/2000
  134.    */
  135.    Century.tm_year = 2000 - 1900;  // 2000
  136.    Century.tm_mon  = 0;            // January
  137.    Century.tm_mday = 1;            // 1st
  138.    Century.tm_hour = 0;
  139.    Century.tm_min  = 0;
  140.    Century.tm_sec  = -1;
  141.    Century.tm_isdst = 0;
  142.  
  143.    /*------------------------------------------------
  144.    ** Prepare modification structure for ChangeDirectoryEntry call.
  145.    */
  146.    mods.MLastUpdatedInSeconds = lTemp - mktime (&Century);
  147.  
  148.  
  149.    /*------------------------------------------------
  150.    ** Call ChangeDirectoryEntry
  151.    */
  152.    result = ChangeDirectoryEntry( FileName, &mods, mbits, 0 );
  153.    if ( result != 0 )
  154.    {
  155.       printf("ChangeDirectoryEntry() failed, result = 0x%X \n", result);
  156.       return -1;
  157.    }
  158.  
  159.  
  160.    /*------------------------------------------------
  161.    ** Display specified file's file date & time information
  162.    */
  163.    dp = opendir( FileName );
  164.    if ( dp != NULL )
  165.    {
  166.       dirBuf = readdir( dp );
  167.       if ( dirBuf != NULL )
  168.       {
  169.          lptr = (LONG *) &dirBuf->d_time;
  170.          sectime = _ConvertDOSTimeToCalendar( *lptr );
  171.          printf("New date and time: %s ", ctime(§ime));
  172.          closedir( dp );
  173.       } 
  174.       else 
  175.       {
  176.          printf("second readdir() failed.\n");
  177.          return -1;
  178.       }
  179.    } 
  180.    else 
  181.    {
  182.       printf("Could not find %s in the SYSTEM directory.\n", FileName);
  183.       return -1;
  184.    }
  185.    return 0;
  186. }
  187.