From - Tue Oct 21 08:09:48 1997
Path: news.mitre.org!blanket.mitre.org!agate!ihnp4.ucsd.edu!mvb.saic.com!info-vax
From: shane.smith@ranplc.co.uk
Newsgroups: comp.os.vms
Subject: Re: Reading file size
Message-ID: <97102112511622@axpw3.ranplc.co.uk>
Date: Tue, 21 Oct 1997 12:51:16 GMT
Organization: Info-Vax<==>Comp.Os.Vms Gateway
X-Gateway-Source-Info: Mailing List
Lines: 51

Tom (babel@bph.krakow.pl) wrote:

> > > I'd like to write a program (DEC C++) that displays the size of given
> > > size (of course it does a lot more :)
[snip]
> Oh, by the way: do you know how would I read the time of file? (file
> creation or last update)
[snip]

Ok, here's a C fragment for you for the time bit. It's hacked out of
some working code, but it has been butchered to make it postable.
(Don't ask me why _XOPEN_SOURCE is defined, I've forgotten.)
It's really C, but the original works under C++ too.

#define _XOPEN_SOURCE 1
#include <stdlib.h>							/* Pull in definitions for standard c functions		*/
#include <stat.h>							/* Pull in definitions for fstat function and consts	*/
#include <errno.h>							/* Get access to the error code variables		*/
#include <perror.h>							/* Get access to the error-message array of pointers	*/

	struct stat	 stat_rec;					/* For holding the stats on the file			*/
	char		 filename_storage[ 128 ];			/* A buffer for a local string copy of the filename	*/
	int		 result;					/* For taking returned values				*/

	/* Put filename in filename_storage as a nul-terminated string	*/

	result = stat( filename_storage, &stat_rec );			/* Get the file information				*/
	switch ( result )						/*							*/
	{								/*							*/
	    case -2:							/*							*/
		puts( "---[Protected]--- " );				/* If it's protected against us, say so.		*/
		return ( -1 );						/* 							*/
									/*							*/
	    case -1:							/*							*/
		puts( strerror( errno ) );				/* If it failed, say why				*/
		return ( -1 );						/* 							*/
									/*							*/
	};								/*							*/

	/* The modification time is now in "stat_rec.st_mtime"		*/
	/* and the creation time is in "stat_rec.st_ctime" as integers.	*/
	/* Use localtime() and asctime() to convert them into ascii	*/
	/* format if that's how you want them.				*/

 #####  | Shane (Shane at ranplc dot co dot uk)        I said that, not R&N. |
#-O-O-#  --------------------------------------------------------------------
#  L  #  "The universe runs on the complex interweaving of three elements: 
 #===#    energy, matter and enlightened self-interest." - G'Kar, Babylon 5
  ###    "Bad things happen when the 'enlightened' bit is missing." - Shane

Fight SPAM; check out http.//www.cauce.org/      SPAMbot trap: abuse@127.0.0.1
