LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   File dates. (https://www.linuxquestions.org/questions/programming-9/file-dates-174405/)

vexer 04-25-2004 11:41 AM

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

jlliagre 04-25-2004 12:55 PM

fd=open(file, O_WRONLY|O_NONBLOCK|O_CREAT|O_NOCTTY|O_LARGEFILE, 0666);
close(fd);

vexer 04-25-2004 08:53 PM

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

jlliagre 04-25-2004 09:55 PM

utime(file, &utimebuf);

vexer 04-27-2004 10: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 12:14 AM

It's more something like this:

Code:

#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 10:33 PM.