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 >
Wrap
C/C++ Source or Header
|
1995-08-28
|
5KB
|
187 lines
/**************************************************************************
** File: xfss1.c
**
** Desc: Example program showing how to set a file date and time using
** ChangeDirectoryEntry()
**
**
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
**
** QMK386 Options
**
** none
**
**
** Programmers:
**
** Ini Who Firm
** ---------------------------------------------------------------------
** DWH Dirk W. Howard Novell Developer Support
**
**
** History:
**
** When Who What
** ---------------------------------------------------------------------
** 8-28-1995 DWH First code.
**
*/
/**************************************************************************
** Macro definitions & function prototypes
*/
/*------------------------------------------------
** Include Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <nwfile.h>
#include <time.h>
#include <dos.h>
#include <nwdir.h>
#include <direct.h>
#include <share.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
char FileName[128];
struct dirent *dirBuf; struct ModifyStructure mods;
LONG mbits;
DIR *dp; time_t currtime;
LONG sectime;
LONG *lptr; char fileDateAndTime[ 40 ]; struct _DOSTime filTim; struct _DOSDate filDat;
int main( int argc, char *argv[] )
{
int result;
LONG lTemp;
struct tm Century;
if ( argc < 2 )
{
printf( "Usage: %s <filename>\r\n", argv[0] );
return 1;
}
strcpy( FileName, argv[1] );
printf( "%s\r\n\r\n", FileName );
/*------------------------------------------------
** Display specified file's file date & time information
*/
dp = opendir( FileName );
if ( dp != NULL )
{
dirBuf = readdir( dp );
if ( dirBuf != NULL )
{
lptr = (LONG *) &dirBuf->d_time;
sectime = _ConvertDOSTimeToCalendar( *lptr );
printf("Old date and time: %s\r\n", ctime(§ime));
closedir( dp );
}
else
{
printf("first readdir() failed.\n");
return -1;
}
}
else
{
printf("Could not find %s in the SYSTEM directory.\n", FileName);
return -1;
}
/*------------------------------------------------
** Get and display current system time and date
*/
currtime = time( NULL );
printf("Current time and date is %s\r\n", ctime(&currtime));
mbits = MLastUpdatedInSecondsBit;
/*------------------------------------------------
** Get system time & date for setting the files time & date
*/
lTemp = (LONG)time( NULL );
/*------------------------------------------------
** File in tm structure to use a zero reference point that
** ChangeDirectoryEntry expects. Zero point for ChangeDirectoryEntry
** is 1/1/2000
*/
Century.tm_year = 2000 - 1900; // 2000
Century.tm_mon = 0; // January
Century.tm_mday = 1; // 1st
Century.tm_hour = 0;
Century.tm_min = 0;
Century.tm_sec = -1;
Century.tm_isdst = 0;
/*------------------------------------------------
** Prepare modification structure for ChangeDirectoryEntry call.
*/
mods.MLastUpdatedInSeconds = lTemp - mktime (&Century);
/*------------------------------------------------
** Call ChangeDirectoryEntry
*/
result = ChangeDirectoryEntry( FileName, &mods, mbits, 0 );
if ( result != 0 )
{
printf("ChangeDirectoryEntry() failed, result = 0x%X \n", result);
return -1;
}
/*------------------------------------------------
** Display specified file's file date & time information
*/
dp = opendir( FileName );
if ( dp != NULL )
{
dirBuf = readdir( dp );
if ( dirBuf != NULL )
{
lptr = (LONG *) &dirBuf->d_time;
sectime = _ConvertDOSTimeToCalendar( *lptr );
printf("New date and time: %s ", ctime(§ime));
closedir( dp );
}
else
{
printf("second readdir() failed.\n");
return -1;
}
}
else
{
printf("Could not find %s in the SYSTEM directory.\n", FileName);
return -1;
}
return 0;
}