示例#1
0
void main()
  {
    time_t time_of_day;
    auto char buf[26];

    time_of_day = time( NULL );
    printf( "It is now: %s", _ctime( &time_of_day, buf ) );
  }
示例#2
0
int main()
{
	time_t t1, t2;
	struct tm tm1, tm2;

	time( &t1 );
	tm1 = *localtime(&t1);
	t1 = mktime(&tm1);
	tm1 = *gmtime(&t1);

	_time( &t2 );
	tm2 = *_localtime(&t2);
	t2 = _mktime(&tm2);
	tm2 = *_gmtime(&t2);

	// time, mktime
	if( t1==t2 )
		OutputDebugString( "ok\n" );
	else
	{
		static char buf[128];
		wsprintf( buf, "ng : %d, %d\n", t1, t2 );
		OutputDebugString( buf );
	}

	// localtime, gmtime
	if( 0==memcmp( &tm1, &tm2, sizeof(struct tm) ) )
		OutputDebugString( "ok\n" );
	else
		OutputDebugString( "ng\n" );

	// ctime
	OutputDebugString( ctime(&t1) );
	OutputDebugString( _ctime(&t2) );

	// asctime
	OutputDebugString( asctime(&tm1) );
	OutputDebugString( _asctime(&tm2) );

	return 0;
}
示例#3
0
void CopyFile(const char *source, const char *dest)
{
    char Buffer[BUFFER_SIZE];
    int numBytes=BUFFER_SIZE+1;
    struct stat fileInfo;
    time_t fileTime;
    struct utimbuf times;
    FILE *in;
    FILE *out;


    time_t time_of_day;
    char buf[26];
    time_of_day = time( NULL );
    _ctime( &time_of_day, buf );
    buf[24]= '\0';


    // see if file is already present.
    if( access( dest, F_OK ) == 0 ) {
        printf("Found existing copy of %s\n",dest);
        ClearFile(dest);
    }



    printf("Copying file: %s.\n to %s.\n",source, dest);

    in = fopen(source,"rt");
    out = fopen(dest,"wt");

    if((in == NULL) )
    {
        printf("Error opening source file for copying: %s\n",source);
        return;
    }
    if( (out == NULL))
    {
        printf("Error opening destination file for copying: %s\n",dest);
        return;
    }

    // print status message
    fprintf(out,Marker,buf );
    while(numBytes >= BUFFER_SIZE) {
        numBytes = fread(Buffer,1,BUFFER_SIZE,in);
        fwrite(Buffer,1,numBytes,out);
    }
    fclose(in);
    fclose(out);

    // set fake file creation time.
    if(-1 != stat( source, &fileInfo) ) {
        times.actime = fileInfo.st_mtime;
        times.modtime = fileInfo.st_mtime;
        utime( dest, &times);
    }



    // set file access:
    chmod(dest,S_IRUSR | S_IRGRP | S_IROTH);

}