Date & Time representation in "struct stat" - <sys/stat.h>

M

Magesh

How date-time attributes of a file are represented in the structure
"struct stat"? Coz as I noted they found to be unsigned integers and I
donno how they are interpreted as date & time in the members st_atime,
st_mtime, and st_ctime. I don't want any lib fun that returns the
corresponding time formatted string coz what I want to know is the
interpretation of date-time in those members so that I could extract
them and use it for some purpose.

Thx in advance to whoever participates this discussion...
- Magesh
 
J

Joachim Schmitz

Magesh said:
How date-time attributes of a file are represented in the structure
"struct stat"? Coz as I noted they found to be unsigned integers and I
donno how they are interpreted as date & time in the members st_atime,
st_mtime, and st_ctime. I don't want any lib fun that returns the
corresponding time formatted string coz what I want to know is the
interpretation of date-time in those members so that I could extract
them and use it for some purpose.
These are seconds since the Epoch (1st Jan 1970 0:00 GMT)

However: this isn't the right NG as stat() and this struct statare not part
of any C Standard but part of POSIX, so comp.unix.programmer would be the
right place. (Follow up set, I hope)

Bye, Jojo
 
M

Mark Bluemel

Magesh said:
How date-time attributes of a file are represented in the structure
"struct stat"? Coz as I noted they found to be unsigned integers and I
donno how they are interpreted as date & time in the members st_atime,
st_mtime, and st_ctime. I don't want any lib fun that returns the
corresponding time formatted string coz what I want to know is the
interpretation of date-time in those members so that I could extract
them and use it for some purpose.

Thx in advance to whoever participates this discussion...

stat.h is required by POSIX, not by the C language specification.

Your question is really a Unix(-like) question rather than a C question
and would be better directed to comp.unix.programmer (I'd set followups
if my newsreader let me).

<Off-topic>

See http://en.wikipedia.org/wiki/Unix_time for a discussion of Unix time
handling.

</Off-topic>
 
G

Gordon Burditt

How date-time attributes of a file are represented in the structure
"struct stat"? Coz as I noted they found to be unsigned integers and I
donno how they are interpreted as date & time in the members st_atime,
st_mtime, and st_ctime. I don't want any lib fun that returns the
corresponding time formatted string coz what I want to know is the
interpretation of date-time in those members so that I could extract
them and use it for some purpose.

C does not define a struct stat, however, typically the elements
you refer to are a time_t. (Or maybe a structure containing a
time_t and something representing fractional seconds.) See also
localtime() and ctime(). ctime() does format them as a string but
localtime() breaks it down into a struct tm, which you can use for
various things like figuring out the day of the week the file was
last modified.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top