views:

65

answers:

1

I have a program (jhead) that compiles with very few tweaks for both Windows and generic Unix variants. From time to time, windows users ask if it can be modified to also set the "creation date/time" of the files, but I don't see a way to do this with the POSIX api. What I'm currently doing is:

{
    struct utimbuf mtime;
    mtime.actime = NewUnixTime;
    mtime.modtime = NewUnixTime;
    utime(FileName, &mtime);
}

Ideally, struct utimebuf would just have a creation time, but it doesn't. It strikes me it would take a lot of windows specific, non-portable code to change the creation time under Windows. Is there another POSIX way of doing this? Any suggestions?

A: 

POSIX only recognizes three different file times:

  1. atime (access time): The last time the file was read
  2. mtime (modification time): The last time the file was written
  3. ctime (attribute change time): The last time the file's metadata was modified

Any other file times that may exist in the underlying OS require OS-specific API calls in order to be modified.

And don't worry about creating non-portable code; only these times really exist under most *nix variants.

Ignacio Vazquez-Abrams