LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-25-2004, 11:41 AM   #1
vexer
Member
 
Registered: Jan 2003
Location: Sudbury Ontario, Canada
Distribution: Slackware
Posts: 388

Rep: Reputation: 30
File dates.


How would I code touch (command), in C, so I could execute it onto files?
 
Old 04-25-2004, 12:55 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,486

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
fd=open(file, O_WRONLY|O_NONBLOCK|O_CREAT|O_NOCTTY|O_LARGEFILE, 0666);
close(fd);
 
Old 04-25-2004, 08:53 PM   #3
vexer
Member
 
Registered: Jan 2003
Location: Sudbury Ontario, Canada
Distribution: Slackware
Posts: 388

Original Poster
Rep: Reputation: 30
What if I was trying to change the date? with a touch -t?
 
Old 04-25-2004, 09:55 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,486

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
utime(file, &utimebuf);
 
Old 04-27-2004, 10:09 PM   #5
vexer
Member
 
Registered: Jan 2003
Location: Sudbury Ontario, Canada
Distribution: Slackware
Posts: 388

Original Poster
Rep: Reputation: 30
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;
}
 
Old 04-28-2004, 12:14 AM   #6
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
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).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
file created/accessed dates plainkeyman Linux - General 4 10-27-2005 07:34 PM
Trouble working with file dates cboxall Linux - Newbie 2 07-21-2005 11:11 AM
file dates digitalgravy Linux - General 2 01-20-2005 10:58 AM
File Dates Rv5 Programming 5 09-07-2004 05:59 PM
Sorting a file containing dates subu_s Linux - General 2 06-03-2004 01:07 PM


All times are GMT -5. The time now is 09:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration