From 847d9e301526290c8d7450c8249445b36049bf7f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 20 Apr 2011 10:01:34 -0700 Subject: [PATCH] timezone: Add support for writing new timezone information --- src/timezone.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/timezone.c b/src/timezone.c index 717270b..263ee4e 100644 --- a/src/timezone.c +++ b/src/timezone.c @@ -268,11 +268,59 @@ done: return zone; } +static int write_file(void *src_map, struct stat *src_st, const char *pathname) +{ + int fd; + ssize_t written; + + DBG("pathname %s", pathname); + + fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd < 0) + return -EIO; + + written = write(fd, src_map, src_st->st_size); + + close(fd); + + if (written < 0) + return -EIO; + + return 0; +} + int __connman_timezone_change(const char *zone) { + struct stat st; + char *map, pathname[PATH_MAX]; + int fd, err; + DBG("zone %s", zone); - return -EIO; + snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone); + + fd = open(pathname, O_RDONLY); + if (fd < 0) + return -EINVAL; + + if (fstat(fd, &st) < 0) { + close(fd); + return -EIO; + } + + map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (map == NULL || map == MAP_FAILED) { + close(fd); + return -EIO; + } + + err = write_file(map, &st, ETC_LOCALTIME); + + munmap(map, st.st_size); + + close(fd); + + return err; } static guint inotify_watch = 0; -- 2.7.4