Welcome, Guest. Please login or register.

Author Topic: How do I check size/date of a file in ANSI C?  (Read 4009 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline ChaosLordTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2003
  • Posts: 2608
    • Show all replies
    • http://totalchaoseng.dbv.pl/news.php
How do I check size/date of a file in ANSI C?
« on: February 16, 2006, 04:51:05 AM »
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
 

Offline ChaosLordTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2003
  • Posts: 2608
    • Show all replies
    • http://totalchaoseng.dbv.pl/news.php
Re: How do I check size/date of a file in ANSI C?
« Reply #1 on: February 16, 2006, 07:58:15 AM »
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. :insane:  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? :hammer:

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

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
 

Offline ChaosLordTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2003
  • Posts: 2608
    • Show all replies
    • http://totalchaoseng.dbv.pl/news.php
Re: How do I check size/date of a file in ANSI C?
« Reply #2 on: February 16, 2006, 10:09:17 AM »
@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?  :-)
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
 

Offline ChaosLordTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2003
  • Posts: 2608
    • Show all replies
    • http://totalchaoseng.dbv.pl/news.php
Re: How do I check size/date of a file in ANSI C?
« Reply #3 on: February 16, 2006, 11:07:38 AM »
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. :insane:  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?
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
 

Offline ChaosLordTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2003
  • Posts: 2608
    • Show all replies
    • http://totalchaoseng.dbv.pl/news.php
Re: How do I check size/date of a file in ANSI C?
« Reply #4 on: February 16, 2006, 11:10:34 AM »
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. :-?
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