Skip to content

Commit 09e0c1d

Browse files
committed
minor, treat zonename `localtime' specially, fixes bug #97
resort to /etc/localtime for now
1 parent e3e12c4 commit 09e0c1d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/dt-io-zone.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# include "config.h"
3939
#endif /* HAVE_CONFIG_H */
4040
#include <string.h>
41+
#include <sys/stat.h>
4142
#include "tzmap.h"
4243
#include "dt-io.h"
4344
#include "dt-io-zone.h"
@@ -135,6 +136,29 @@ __io_zone(const char *spec)
135136
return res;
136137
}
137138

139+
static char*
140+
__local(void)
141+
{
142+
static char tzmfn[PATH_MAX];
143+
144+
if (!*tzmfn) {
145+
struct stat st;
146+
147+
puts(tzname[0U]);
148+
puts(tzname[1U]);
149+
if (!stat("/etc/localtime", &st)) {
150+
memcpy(tzmfn, "/etc/localtime", 14L);
151+
goto gothim;
152+
}
153+
/* check /etc/timezone?
154+
* check /var/db/timezone?
155+
* check /etc/sysconfig/clock? */
156+
return NULL;
157+
}
158+
gothim:
159+
return tzmfn;
160+
}
161+
138162
zif_t
139163
dt_io_zone(const char *spec)
140164
{
@@ -167,6 +191,10 @@ Set TZMAP_DIR environment variable to where " TZMAP_SUF " files reside", tzmfn);
167191
if ((spec = tzm_find(tzm, ++p)) == NULL) {
168192
return NULL;
169193
}
194+
} else if (!strcmp(spec, "localtime")) {
195+
if ((spec = __local()) == NULL) {
196+
return NULL;
197+
}
170198
}
171199
return __io_zone(spec);
172200
}

0 commit comments

Comments
 (0)