4

Since the system /usr/share/zoneinfo database is updated fairly frequently, I would like to be able to load it (and reload it) dynamically in a very long running C++ program.

Now I know the standard library will use this database, but I doubt it offers dynamic reloading of it (or at least I couldn't find anything about it with Google.)

Is there any C or C++ library or code that I can use to do this?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Eloff
  • 20,828
  • 17
  • 83
  • 112
  • One way I can think of that's really ugly is to call an external process that loads the timezone data via the C stdlib and then serializes it and sends it via a pipe to the parent process. I would hate to have to do it that way though. – Eloff Aug 28 '12 at 00:03
  • You could always try to find out by downloading the source for the standard library, and check the timezone functions to see if it loads the database each time or caches it. – Some programmer dude Aug 28 '12 at 06:24
  • @JoachimPileborg Any stdlib that doesn't cache it should be slapped around the ears. Finding, reading, and parsing those zoneinfo files each time you call localtime() would be unworkably slow for many applications. – Eloff Aug 30 '12 at 19:54

2 Answers2

3

I'm an idiot. IANA which provides the zoneinfo database, also provides a library for working with it. Funnily enough I discovered this by reading the postgresql source code.

I'm not sure if this is sufficient, but it's public domain licensed so at the least I can pull it into my code and bend it to my needs.

Eloff
  • 20,828
  • 17
  • 83
  • 112
1

localtime et al use the timezone conversion information as set by tzset, so you would usually be able to reload that information by setting TZ to some value, calling tzset, setting it back and calling it again. This will work with glibc, but you should probably check on other platforms.

Otherwise, you're using some other non-Posix API to access the zoneinfo database, and you should look at the facilities that library has for reloading its data.

ecatmur
  • 152,476
  • 27
  • 293
  • 366
  • I'll need some non-Posix API because I'll need safe multi-threaded access to it. That means reloading the data into seperate memory and then swapping a pointer from the old data to the new data. In a single-threaded environment your approach would be ideal. – Eloff Aug 28 '12 at 12:42