PS2SDK
PS2 Homebrew Libraries
timezone.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #include <time.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <reent.h>
22 
23 #include <ps2sdkapi.h>
24 #define OSD_CONFIG_NO_LIBCDVD
25 #include "osd_config.h"
26 
27 #ifdef F__libcglue_timezone_update_impl
28 void _libcglue_timezone_update_impl()
29 {
30  /* Initialize timezone from PS2 OSD configuration */
31  int tzOffset = configGetTimezone();
32  int tzOffsetAbs = tzOffset < 0 ? -tzOffset : tzOffset;
33  int hours = tzOffsetAbs / 60;
34  int minutes = tzOffsetAbs - hours * 60;
35  int daylight = configIsDaylightSavingEnabled();
36  static char tz[28];
37  #pragma GCC diagnostic push
38  #pragma GCC diagnostic ignored "-Wformat-overflow"
39  snprintf(tz, sizeof(tz), "GMT%s%02i:%02i%s", tzOffset < 0 ? "+" : "-", hours, minutes, daylight ? "DST" : "");
40  #pragma GCC diagnostic pop
41  setenv("TZ", tz, 1);
42 }
43 #endif
44 
45 #ifdef F__libcglue_timezone_update
46 // Defined in newlib: newlib/libc/time/tzset_r.c
47 void __attribute((weak)) _tzset_unlocked_r(struct _reent *reent_ptr);
48 __attribute__((weak))
49 void _libcglue_timezone_update()
50 {
51  // cppcheck-suppress knownConditionTrueFalse
52  if (&_tzset_unlocked_r)
53  {
54  _libcglue_timezone_update_impl();
55  }
56 }
57 #endif
58 
59 #ifdef F_ps2sdk_setTimezone
60 void ps2sdk_setTimezone(int timezone) {
61  configSetTimezone(timezone);
62  _libcglue_timezone_update();
63 }
64 #endif
65 
66 #ifdef F_ps2sdk_setDaylightSaving
67 void ps2sdk_setDaylightSaving(int daylightSaving) {
68  configSetDaylightSavingEnabled(daylightSaving);
69  _libcglue_timezone_update();
70 }
71 #endif
configSetDaylightSavingEnabled
void configSetDaylightSavingEnabled(int enabled)
configGetTimezone
int configGetTimezone(void)
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60
configIsDaylightSavingEnabled
int configIsDaylightSavingEnabled(void)
time.h
stdio.h
osd_config.h
stdlib.h
configSetTimezone
void configSetTimezone(int offset)