mailto: blog -at- heyrick -dot- eu

Navi: Previous entry Display calendar Next entry
Switch to desktop version

FYI! Last read at 12:55 on 2024/04/28.

Fixing RISC OS's CLib

My adventure started with this little bit of code:
Try as I might, it told me the time according to British Summer Time.

So the first thing I did was go on the forums and moan. That's what the internet is for, right?

Then I decided to look and see if I could paste support for CET and CEST into the UK territory:

Actually, it wasn't difficult. And since I'd already built a ROM from this older (mid-May) source, it took only a couple of minutes for me to build a new ROM.

So I could do this:

instead of setting the DST option and TimeZone offset by hand, 'cos that's clumsy and boring.

The stupid thing still couldn't tell me the correct time.

Turns out that - regardless of some of the opinions in the forum - Territory is actually quite capable of handling arbitrary timezone offsets. This particular fault was not with Territory. This particular fault was best experienced by looking at the code for C's localtime() function:

What is happening here is that the system DST flag is being returned. Then, we are looking for the timezone offset (from UTC) in either the default C locale, or in a specified locale. This is because when your program starts, you can do something like setlocale("usa/est"); to set the American Eastern Standard Time as the locale.
The system call Territory_ReadTimeZones is called to read the offset, which is then bodged according to the DST flag.

Ah. So now we're getting somewhere. Here is what the PRM says for that system call:

In a spectacularly poorly thought out plan, there was no official way to read more than the first defined timezone pairing. This means America, with its five timezones, would have responded EST/EDT and nothing else. More recently, by using a "magic value" (R4 = "ZONE"), it is possible to pass an offset in R1 to increment through the timezones available.

At any rate, this means that localtime() absolutely cannot work in a multi-zone territory where the configured zone is not the first; and looking back through the CVS change history, I don't think that it has ever worked correctly.

The biggest pile of nonsense is that Territory actually provides a call to do just exactly what we want:

I don't know why they didn't use this in the first place?

So, localtime() is now modified as such:

The behaviour for named zones is retained. For us using the default C locale? We just ask what the offset is. No munging, no nothing. Territory has already sussed all of that.

New ROM built, installed, and tested with UK-with-CEST and various US timezones. Works fine.

 

Phew! What an adventure!
A ticket has been opened, corrective modifications have been sent to ROOL, so hopefully soon localtime() will work for everybody.

 

 

Your comments:

No comments yet...

Add a comment (v0.11) [help?]
Your name:

 
Your email (optional):

 
Validation:
Please type 06777 backwards.

 
Your comment:

 

Navi: Previous entry Display calendar Next entry
Switch to desktop version

Search:

See the rest of HeyRick :-)