tobold.org

correct • elegant • free

△ Comp.lang.c △

◅ Expression to round up without branching

Structure problem ▻

Reading Date Stamp

In article <bXDl4.165$%13.4658@news2.tor.primus.ca>,
Adil Canteenwala <adilc@iprimus.ca> wrote:
>I am working with C on UNIX platform.
>Does anyone knows how can I read CREATED DATE STAMP of any file or directory
>through C program? So that I know how old the file/directory  is.

Standard C doesn't provide any way to do this; Unix does.  I've
therefore cross-posted this to comp.unix.programmer, and directed
followups there.

The system call you're after is stat(2).  A simple usage looks something
like this.

    #include <sys/types.h>
    #include <sys/stat.h>

    struct stat st;

    if (stat("myfile", &st) < 0) {
            ... /* deal with error */
    }

After the successful stat, you can find myfile's access, modification,
and inode-change times in st.st_atime, st.st_mtime, and st.st_ctime
respectively.  These all have [ ... something seems to be lost here ]

Note that Unix does not record the time when a file was first created;
st_mtime best fits the natural meaning of "how old".

Tim.
--
Tim Goodwin   | "If you don't know what closures are, you probably don't
Leicester, UK | want to know what closures are." -- Larry Wall

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.lang.c,comp.unix.programmer
Subject: Re: Reading Date Stamp
Followup-To: comp.unix.programmer
Date: 1 Feb 2000 17:08:45 -0000
Message-ID: <8773vj$unu$1@ltpcg.star.le.ac.uk>
References: <bXDl4.165$%13.4658@news2.tor.primus.ca>

△ Comp.lang.c △

◅ Expression to round up without branching

Structure problem ▻