Extension to tzcode to support additional timezones

Christos Zoulas christos at zoulas.com
Tue Oct 26 19:08:52 UTC 2010


On Oct 26,  1:55pm, wollman at csail.mit.edu (Garrett Wollman) wrote:
-- Subject: Re: Extension to tzcode to support additional timezones

| <<On Tue, 26 Oct 2010 13:44:20 -0400, christos at zoulas.com (Christos Zoulas) said:
| 
| > I just have:
| 
| > typedef struct __state *timezone_t;
| 
| Please don't.  C does not have opaque typedefs, only opaque
| structures.

I understand this and typedef'ing things is problematic because you
cannot typedef things multiple times, so you end up having to include
a particular header that provides the typedef to bring it in scope
instead of just having to do a forward struct declaration. But is it
really better in this case?

I can easily change the code to 'struct tz' or 'struct timezone' if
people want.

Oh, and I've implemented the string pooling code already for tm_zone:


/*
 * Simple array based string pool.
 */

#include <stdlib.h>
#include <string.h>

static char **pool;
static size_t poollen;
static size_t poolmax;

char *tzstrpool(const char *);

/*
 * This code is very simple because we don't expect to have more than
 * a handful of zones active and it should not become performance critical.
 */
char *
tzstrpool(const char *str)
{
        size_t i;

        for (i = 0; i < poollen; i++)
                if (strcmp(str, pool[i]) == 0)
                        return pool[i];

        if (poollen == poolmax) {
                char **npool;
		size_t npoolmax = poolmax + 20;
                poolmax += 20;
                npool = realloc(pool, sizeof(*npool) * npoolmax);
                if (npool == NULL)
                        return NULL;
		pool = npool;
		poolmax = npoolmax;
        }

        pool[poollen] = strdup(str);
        if (pool[poollen] == NULL)
                return NULL;

        return pool[poollen++];
}




More information about the tz mailing list