-   Programming (
-   -   File dates. (

vexer 04-25-2004 12:41 PM

File dates.
How would I code touch (command), in C, so I could execute it onto files?

jlliagre 04-25-2004 01:55 PM


vexer 04-25-2004 09:53 PM

What if I was trying to change the date? with a touch -t?

jlliagre 04-25-2004 10:55 PM

utime(file, &utimebuf);

vexer 04-27-2004 11:09 PM

Is this written correctly? (I'm not too sure the actime and modtime are done correctly, nor do I know what the times format is aka, seconds, mins, hours)

#include <sys/time.h>

main() {
const char *filename = "file.c";
struct utimbuf *buf;

*buf.time_t.actime = 5;
*buf.time_t.modtime = 1;

int utime(const char *filename, struct utimbuf *buf);

return 0;

itsme86 04-28-2004 01:14 AM

It's more something like this:


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

int main(void)
  char *filename = "file.c";
  struct utimebuf buf;

  buf.actime = 5;
  buf.modtime = 1;

  utime(filename, &buf);

  return 0;

The actime and modtime members are both going to be much larger than 5 and 1 though. They should correspond to the number of seconds elapsed since midnight january 1, 1970 (the epoch).

All times are GMT -5. The time now is 01:40 AM.