From: Marcel Holtmann Date: Wed, 20 Apr 2011 17:01:34 +0000 (-0700) Subject: timezone: Add support for writing new timezone information X-Git-Tag: 2.0_alpha~1515 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=847d9e301526290c8d7450c8249445b36049bf7f;p=framework%2Fconnectivity%2Fconnman.git timezone: Add support for writing new timezone information --- 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;