amiga.org
     
iconAll times are GMT -6. The time now is 05:12 PM. | Welcome to Forum, please register to access all of our features.

» Amiga.org » Operating System Specific Discussions » Amiga OS » Amiga OS -- Development » How do I check size/date of a file in ANSI C?

Amiga OS -- Development This particular forum deals with issues regarding development for all versions of AmigaOS.

Reply
 
Thread Tools Display Modes
Old 02-15-2006, 09:51 PM   #1
ChaosLord
Premium Member
Points: 14,695, Level: 78 Points: 14,695, Level: 78 Points: 14,695, Level: 78
Activity: 28% Activity: 28% Activity: 28%
 
ChaosLord's Avatar
 
Join Date: Nov 2003
Location: Houston, Texas
Posts: 2,257
Default How do I check size/date of a file in ANSI C?

How do I check size and date of a file in ANSI C?
__________________
Wanna try a wonderfull strategy game with lots of handdrawn anims,
Magic Spells and Monsters, Incredible playability and lastability,
English speech, etc. Total Chaos AGA
ChaosLord is offline   Reply With Quote
Old 02-15-2006, 10:11 PM   #2
Castellen
Cult Member
Points: 9,898, Level: 66 Points: 9,898, Level: 66 Points: 9,898, Level: 66
Activity: 1% Activity: 1% Activity: 1%
 
Join Date: Feb 2002
Location: Antarctica
Posts: 936
Default Re: How do I check size/date of a file in ANSI C?

I usually use stat() or lstat() though these might be more Unix specific???

More details in this thread.
Castellen is offline   Reply With Quote
Old 02-16-2006, 12:29 AM   #3
adolescent
Desperately needs a life
Points: 13,811, Level: 76 Points: 13,811, Level: 76 Points: 13,811, Level: 76
Activity: 7% Activity: 7% Activity: 7%
 
adolescent's Avatar
 
Join Date: Sep 2003
Posts: 3,056
Default Re: How do I check size/date of a file in ANSI C?

There's no function to get file date in pure ANSI C. But, look for stat() like Castellen mentioned.
__________________
Time to move on. Bye Amiga.org.
adolescent is offline   Reply With Quote
Old 02-16-2006, 12:58 AM   #4
ChaosLord
Premium Member
Points: 14,695, Level: 78 Points: 14,695, Level: 78 Points: 14,695, Level: 78
Activity: 28% Activity: 28% Activity: 28%
 
ChaosLord's Avatar
 
Join Date: Nov 2003
Location: Houston, Texas
Posts: 2,257
Default Re: How do I check size/date of a file in ANSI C?

I am already using stat() but the problem is that stat() in SASC triggers a read of a nonexistent environment variable TZ which is lame and slow. I am doing thousands of stat() in a loop.

Accessing an environment variable for no reason every time you check the existence of a file sounds like something linux would do. So that is why I was searching for a cleaner way that is also multiplatform.

Does stat() in all compilers trigger this lame environment variable access? Or is it just some stupid thing in SASC? Its easy to run SnoopDos to check.

How can I do surgery on my SASC to amputate the offending code?

p.s. what the heck is the difference between stat() and lstat() ?

ChaosLord is offline   Reply With Quote
Old 02-16-2006, 03:02 AM   #5
chris
Cult Member
Points: 10,477, Level: 68 Points: 10,477, Level: 68 Points: 10,477, Level: 68
Activity: 7% Activity: 7% Activity: 7%
 
chris's Avatar
 
Join Date: Mar 2002
Posts: 600
Send a message via ICQ to chris
Default Re: How do I check size/date of a file in ANSI C?

Why not #ifndef around the block and add AmigaOS-specific replacement code?

You can use Lock() and Examine() or Open() and ExamineFH() to get a FileInfoBlock, which will tell you the date and size.

Chris
__________________
"Miracles we do at once, the impossible takes a little longer" - AJS on Hyperion
Avatar picture is Tabitha by Eric W Schwartz
chris is offline   Reply With Quote
Old 02-16-2006, 03:09 AM   #6
ChaosLord
Premium Member
Points: 14,695, Level: 78 Points: 14,695, Level: 78 Points: 14,695, Level: 78
Activity: 28% Activity: 28% Activity: 28%
 
ChaosLord's Avatar
 
Join Date: Nov 2003
Location: Houston, Texas
Posts: 2,257
Default Re: How do I check size/date of a file in ANSI C?

@chris

The deal is that I could do your idea but
I would have to do it in many different places
and the code is already around 200,000 lines
and adding a bunch of giant blocks of #ifdef AMIGA
code would really messify things...

Do you know any secret trick to do it super elegantly and simply? :-)
ChaosLord is offline   Reply With Quote
Old 02-16-2006, 03:35 AM   #7
Karlos
Sockologist
Points: 48,752, Level: 100 Points: 48,752, Level: 100 Points: 48,752, Level: 100
Activity: 8% Activity: 8% Activity: 8%
 
Karlos's Avatar
 
Join Date: Nov 2002
Location: I solve practical problems...
Posts: 16,606
Blog Entries: 18
Default Re: How do I check size/date of a file in ANSI C?

Why not simply write a wrapper function that does the job you need and simply have the implementation of that function #ifdef AMIGA ?
__________________
OCA
This isn't SCSI... This is SATA!!!
I have CDO. It's like OCD except all the letters are in ascending order. The way they should be.
Core2 Quad Q9450 2.66GHz / X48T / 4GB DDR3 / nVidia GTX275 / Linux x64, AROS, Win64
A1XE 800MHz / 512MB / Radeon 9200 / OS4.1
A1200T BPPC 240MHz / 256MB / Permedia 2 / OS 3.1 - OS3.9, OS4
A1200T Apollo 1240 28MHz / 32MB / Mediator1200 / Voodoo 3000 / OS3.9
A1200D Apollo 1240 25MHz (ejector seat ROM edition) / 32MB
Karlos is offline   Reply With Quote
Old 02-16-2006, 03:37 AM   #8
Cymric
Defender of the Faith
Points: 7,150, Level: 55 Points: 7,150, Level: 55 Points: 7,150, Level: 55
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2002
Posts: 1,031
Default Re: How do I check size/date of a file in ANSI C?

Quote:
ChaosLord wrote:
I am already using stat() but the problem is that stat() in SASC triggers a read of a nonexistent environment variable TZ which is lame and slow. I am doing thousands of stat() in a loop.
Either that, or change to a different c.lib, or use the #define-method, or write your own stat()-code which gets linked before c.lib. The last method is probably the best solution, as your portable fallthrough solution would be limited to one maintainable place in your code.

Quote:
Accessing an environment variable for no reason every time you check the existence of a file sounds like something linux would do. So that is why I was searching for a cleaner way that is also multiplatform.
Since TZ is 'time zone', I am not at all impressed by this line of reasoning. That people do not use time zones and instead just force the clock of their computer to the right time is not SAS/C's fault---instead, it is following proper Unix programming guidelines.

Quote:
p.s. what the heck is the difference between stat() and lstat() ?
On the Amiga, not really important, if memory serves me. The calls return different results when fed a file or a link, either hard or soft. One gives the results for the link itself, the other follows it through to the file pointed at. Links never worked properly under FFS. Or they did, but then only the softlink. Or was it the hardlink?
__________________
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
Cymric is offline   Reply With Quote
Old 02-16-2006, 04:07 AM   #9
ChaosLord
Premium Member
Points: 14,695, Level: 78 Points: 14,695, Level: 78 Points: 14,695, Level: 78
Activity: 28% Activity: 28% Activity: 28%
 
ChaosLord's Avatar
 
Join Date: Nov 2003
Location: Houston, Texas
Posts: 2,257
Default Re: How do I check size/date of a file in ANSI C?

Quote:
Cymric wrote:
Quote:
ChaosLord wrote:
I am already using stat() but the problem is that stat() in SASC triggers a read of a nonexistent environment variable TZ which is lame and slow. I am doing thousands of stat() in a loop.
Either that, or change to a different c.lib, or use the #define-method, or write your own stat()-code which gets linked before c.lib. The last method is probably the best solution, as your portable fallthrough solution would be limited to one maintainable place in your code.
Okey dokey so I can make my own stat() function
that uses AmigaOS way of doing things that will fill in
a unix struct stat so all the time compare code will work without change.

BUT... how do I convert from AmigaDOS time format to Unix time_t format?


Quote:
Quote:
Accessing an environment variable for no reason every time you check the existence of a file sounds like something linux would do. So that is why I was searching for a cleaner way that is also multiplatform.
Since TZ is 'time zone', I am not at all impressed by this line of reasoning. That people do not use time zones and instead just force the clock of their computer to the right time is not SAS/C's fault---instead, it is following proper Unix programming guidelines.
But the timezone of my computer has nothing to do with the
time that some file was created many years ago on someone elses computer... Does it?

I guess you are saying that linux constantly converts all filedates to/from GMT?

So all filedates in linux are stored on the HD in GMT?

And since AmigaOS does not store filedates in GMT but
instead stores the actual date where it was created,
the stat() function in SASC should be rewritten
to NOT check TZ since adding in the user's TimeZone
under AmigaOS would then give the wrong date.

Correct?
ChaosLord is offline   Reply With Quote
Old 02-16-2006, 04:10 AM   #10
ChaosLord
Premium Member
Points: 14,695, Level: 78 Points: 14,695, Level: 78 Points: 14,695, Level: 78
Activity: 28% Activity: 28% Activity: 28%
 
ChaosLord's Avatar
 
Join Date: Nov 2003
Location: Houston, Texas
Posts: 2,257
Default Re: How do I check size/date of a file in ANSI C?

Quote:
Karlos wrote:
Why not simply write a wrapper function that does the job you need and simply have the implementation of that function #ifdef AMIGA ?
Yes I was thinking the same thing :-)

But I donno how to convert from Amiga time to Unix time_t time. :-?
ChaosLord is offline   Reply With Quote
Old 02-16-2006, 04:17 AM   #11
Karlos
Sockologist
Points: 48,752, Level: 100 Points: 48,752, Level: 100 Points: 48,752, Level: 100
Activity: 8% Activity: 8% Activity: 8%
 
Karlos's Avatar
 
Join Date: Nov 2002
Location: I solve practical problems...
Posts: 16,606
Blog Entries: 18
Default Re: How do I check size/date of a file in ANSI C?

Don't both systems measure time (32-bit integer) as the number of seconds since a particular epoch date?

If so, provided you know the difference between them. If memory serves, the Unix epoch is 00:00:00 Jan 01 1970 and the Amiga epoch is 00:00:00 Jan 01 1978

I would assume, if you evaluate the amiga epoch date as a unix datestamp you have a displacement you can use to convert an amiga 32-bit datestamp to a unix one and vice versa.
__________________
OCA
This isn't SCSI... This is SATA!!!
I have CDO. It's like OCD except all the letters are in ascending order. The way they should be.
Core2 Quad Q9450 2.66GHz / X48T / 4GB DDR3 / nVidia GTX275 / Linux x64, AROS, Win64
A1XE 800MHz / 512MB / Radeon 9200 / OS4.1
A1200T BPPC 240MHz / 256MB / Permedia 2 / OS 3.1 - OS3.9, OS4
A1200T Apollo 1240 28MHz / 32MB / Mediator1200 / Voodoo 3000 / OS3.9
A1200D Apollo 1240 25MHz (ejector seat ROM edition) / 32MB
Karlos is offline   Reply With Quote
Reply

Bookmarks

Tags
size or date , ansi , file , check

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ansi capable telnet application for OS3.x? AmiKit Amiga Software Issues and Discussion 5 04-09-2009 12:37 PM
Octamed tutorials biggest file size >720kb ElZorro Amiga Software Issues and Discussion 10 12-26-2006 03:11 AM
OS call to get file size gazsp Amiga OS -- Development 7 01-28-2006 03:20 PM
The size of a file srg86 Amiga OS -- Development 6 05-04-2005 07:08 AM
More GNU C++ (ANSI C++ mode) oddness Karlos Amiga OS -- Development 14 03-26-2004 11:02 AM