PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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
22#include <ps2sdkapi.h>
23#define OSD_CONFIG_NO_LIBCDVD
24#include "osd_config.h"
25
26#define posixIODriver { open, close, (int (*)(int, void *, int))read, O_RDONLY }
27
28#ifdef F__libcglue_timezone_update
29__attribute__((weak))
30void _libcglue_timezone_update()
31{
32 /* Initialize timezone from PS2 OSD configuration */
33 _io_driver driver = posixIODriver;
34 int tzOffset = configGetTimezoneWithIODriver(&driver);
35 int tzOffsetAbs = tzOffset < 0 ? -tzOffset : tzOffset;
36 int hours = tzOffsetAbs / 60;
37 int minutes = tzOffsetAbs - hours * 60;
38 int daylight = configIsDaylightSavingEnabledWithIODriver(&driver);
39 static char tz[15];
40 #pragma GCC diagnostic push
41 #pragma GCC diagnostic ignored "-Wformat-overflow"
42 sprintf(tz, "GMT%s%02i:%02i%s", tzOffset < 0 ? "+" : "-", hours, minutes, daylight ? "DST" : "");
43 #pragma GCC diagnostic pop
44 setenv("TZ", tz, 1);
45}
46#endif
47
48#ifdef F_ps2sdk_setTimezone
49void ps2sdk_setTimezone(int timezone) {
50 _io_driver driver = posixIODriver;
51 configSetTimezoneWithIODriver(timezone, &driver, _libcglue_timezone_update);
52}
53#endif
54
55#ifdef F_ps2sdk_setDaylightSaving
56void ps2sdk_setDaylightSaving(int daylightSaving) {
57 _io_driver driver = posixIODriver;
58 configSetDaylightSavingEnabledWithIODriver(daylightSaving, &driver, _libcglue_timezone_update);
59}
60#endif