mirror of
https://github.com/systemd/systemd.git
synced 2025-02-03 17:47:28 +03:00
time: split get_timezone() into main function and zone1970.tab function
This allows for adding another function to read from a different timezone source, which is added in the next commit.
This commit is contained in:
parent
31097e2b99
commit
09a54a862b
@ -1262,7 +1262,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_timezones(char ***ret) {
|
static int get_timezones_from_zone1970_tab(char ***ret) {
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
_cleanup_strv_free_ char **zones = NULL;
|
_cleanup_strv_free_ char **zones = NULL;
|
||||||
int r;
|
int r;
|
||||||
@ -1270,35 +1270,49 @@ int get_timezones(char ***ret) {
|
|||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
f = fopen("/usr/share/zoneinfo/zone1970.tab", "re");
|
f = fopen("/usr/share/zoneinfo/zone1970.tab", "re");
|
||||||
if (f) {
|
if (!f)
|
||||||
for (;;) {
|
|
||||||
_cleanup_free_ char *line = NULL, *cc = NULL, *co = NULL, *tz = NULL;
|
|
||||||
|
|
||||||
r = read_line(f, LONG_LINE_MAX, &line);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
if (r == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
const char *p = line;
|
|
||||||
|
|
||||||
/* Line format is:
|
|
||||||
* 'country codes' 'coordinates' 'timezone' 'comments' */
|
|
||||||
r = extract_many_words(&p, NULL, 0, &cc, &co, &tz, NULL);
|
|
||||||
if (r < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Lines that start with # are comments. */
|
|
||||||
if (*cc == '#')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
r = strv_extend(&zones, tz);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
} else if (errno != ENOENT)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
_cleanup_free_ char *line = NULL, *cc = NULL, *co = NULL, *tz = NULL;
|
||||||
|
|
||||||
|
r = read_line(f, LONG_LINE_MAX, &line);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (r == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const char *p = line;
|
||||||
|
|
||||||
|
/* Line format is:
|
||||||
|
* 'country codes' 'coordinates' 'timezone' 'comments' */
|
||||||
|
r = extract_many_words(&p, NULL, 0, &cc, &co, &tz, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Lines that start with # are comments. */
|
||||||
|
if (*cc == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
r = strv_extend(&zones, tz);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ret = TAKE_PTR(zones);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_timezones(char ***ret) {
|
||||||
|
_cleanup_strv_free_ char **zones = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(ret);
|
||||||
|
|
||||||
|
r = get_timezones_from_zone1970_tab(&zones);
|
||||||
|
if (r < 0 && r != -ENOENT)
|
||||||
|
return r;
|
||||||
|
|
||||||
/* Always include UTC */
|
/* Always include UTC */
|
||||||
r = strv_extend(&zones, "UTC");
|
r = strv_extend(&zones, "UTC");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user