#include <glib.h>
Go to the source code of this file.
Data Structures | |
struct | tz_info |
Defines | |
#define | TOTAL_TIMEZONES 33 |
#define | TZ_FILE "/home/root/.timezone" |
Functions | |
gchar * | get_timezone (void) |
gint | get_timezone_index (const char *tzname, gboolean *is_dst) |
gboolean | set_time_from_server (void) |
void | set_time_utc (time_t utc_time) |
gboolean | set_timezone (const char *tzname, gboolean is_dst) |
Variables | |
static const tz_info | timezones [TOTAL_TIMEZONES] |
#define TOTAL_TIMEZONES 33 |
Copyright (C) 2009 iRex Technologies B.V. All rights reserved.
Definition at line 34 of file time_utils.h.
Referenced by create_timezone_widget(), get_timezone_index(), and on_timezone_input().
#define TZ_FILE "/home/root/.timezone" |
Definition at line 35 of file time_utils.h.
Referenced by get_timezone(), on_reset_button_clicked(), and set_timezone().
gchar* get_timezone | ( | void | ) |
Definition at line 128 of file time_utils.c.
References ERRORPRINTF, LOGPRINTF, and TZ_FILE.
Referenced by init_widgets().
00129 { 00130 LOGPRINTF("entry"); 00131 00132 char actual_tzfile[256]; 00133 memset(actual_tzfile, 0, sizeof(actual_tzfile)); 00134 00135 // get timezone reference 00136 if (readlink(TZ_FILE, actual_tzfile, sizeof(actual_tzfile)) == -1) 00137 { 00138 ERRORPRINTF("Can't dereference symlink %s, errno [%d][%s]", TZ_FILE, errno, strerror(errno)); 00139 return NULL; 00140 } 00141 00142 // check if it exists 00143 if (!g_file_test(actual_tzfile, G_FILE_TEST_IS_REGULAR)) 00144 { 00145 ERRORPRINTF("Can't find symlink target %s", actual_tzfile); 00146 return NULL; 00147 } 00148 00149 return g_path_get_basename(actual_tzfile); 00150 }
gint get_timezone_index | ( | const char * | tzname, | |
gboolean * | is_dst | |||
) |
Definition at line 178 of file time_utils.c.
References DEFAULT_TIMEZONE_NAME, DST_FLAG, LOGPRINTF, timezones, TOTAL_TIMEZONES, and WARNPRINTF.
Referenced by init_widgets().
00179 { 00180 LOGPRINTF("entry"); 00181 00182 gboolean is_dst; 00183 gint tzindex = -1; 00184 00185 if (tzname == NULL) 00186 { 00187 tzname = DEFAULT_TIMEZONE_NAME; 00188 WARNPRINTF("No timezone given, use default [%s]", tzname); 00189 } 00190 00191 int tzlength = strlen(tzname); 00192 is_dst = g_str_has_suffix(tzname, DST_FLAG); 00193 if (is_dst) 00194 { 00195 // ignore DST suffix 00196 tzlength -= strlen(DST_FLAG); 00197 } 00198 00199 int i; 00200 for (i=0; i<TOTAL_TIMEZONES; i++) 00201 { 00202 if (strncmp(tzname, timezones[i].tzname, tzlength) == 0) 00203 { 00204 tzindex = i; 00205 break; 00206 } 00207 } 00208 00209 if (tzindex == -1) 00210 { 00211 WARNPRINTF("Can't find zoneinfo for [%s]", tzname); 00212 tzindex = 12; // default to GMT 00213 is_dst = FALSE; 00214 } 00215 00216 if (dst) 00217 { 00218 *dst = is_dst; 00219 } 00220 00221 return tzindex; 00222 }
gboolean set_time_from_server | ( | void | ) |
Definition at line 238 of file time_utils.c.
References ERRORPRINTF, get_server_time(), LOGPRINTF, and set_time_utc().
00239 { 00240 LOGPRINTF("entry"); 00241 00242 time_t utc_time = get_server_time(); 00243 if (utc_time == 0) { 00244 ERRORPRINTF("Failed to get server time"); 00245 return FALSE; 00246 } 00247 00248 set_time_utc(utc_time); 00249 return TRUE; 00250 }
void set_time_utc | ( | time_t | utc_time | ) |
Definition at line 225 of file time_utils.c.
References LOGPRINTF.
Referenced by set_time_from_server().
00226 { 00227 LOGPRINTF("entry"); 00228 00229 struct timeval tp; 00230 gettimeofday(&tp, NULL); 00231 tp.tv_sec = utc_time; 00232 settimeofday(&tp, NULL); 00233 00234 system("/sbin/hwclock -w -u"); 00235 }
gboolean set_timezone | ( | const char * | tzname, | |
gboolean | is_dst | |||
) |
Definition at line 153 of file time_utils.c.
References DST_FLAG, ERRORPRINTF, LOGPRINTF, TZ_FILE, and TZ_FILES_DIR.
Referenced by datetime_base_save_datetime().
00154 { 00155 LOGPRINTF("entry"); 00156 00157 char actual_tzfile[256]; 00158 00159 snprintf(actual_tzfile, 256, "%s%s%s", TZ_FILES_DIR, tzname, is_dst ? DST_FLAG : ""); 00160 LOGPRINTF("symlink %s to %s", actual_tzfile, TZ_FILE); 00161 if (g_file_test(TZ_FILE, G_FILE_TEST_EXISTS) && (unlink(TZ_FILE) != 0)) 00162 { 00163 ERRORPRINTF("Can't remove %s", TZ_FILE); 00164 return FALSE; 00165 } 00166 00167 if (symlink(actual_tzfile, TZ_FILE) != 0) 00168 { 00169 ERRORPRINTF("Can't create symlink from %s to %s", actual_tzfile, TZ_FILE); 00170 return FALSE; 00171 } 00172 00173 return TRUE; 00174 }
Definition at line 44 of file time_utils.h.
Referenced by datetime_base_save_datetime(), get_timezone_index(), on_timezone_input(), and on_timezone_output().