2 * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
3 * Distributed under the terms of the MIT License.
14 #include <StorageDefs.h>
16 #include <errno_private.h>
17 #include "LocaleBackend.h"
20 using BPrivate::Libroot::gLocaleBackend
;
21 using BPrivate::Libroot::LocaleBackend
;
24 static char sStandardTZName
[64] = { "GMT" };
25 static char sDaylightSavingTZName
[64] = { "GMT" };
36 // These two functions are used as a fallback when the locale backend could not
37 // be loaded. They are implemented in localtime_fading_out.c.
38 extern "C" struct tm
* __gmtime_r_fallback(const time_t* timep
, struct tm
* tmp
);
39 extern "C" time_t __mktime_fallback(struct tm
* tmp
);
45 if (gLocaleBackend
== NULL
&& LocaleBackend::LoadBackend() != B_OK
)
48 char timeZoneID
[B_FILE_NAME_LENGTH
] = { "GMT" };
49 _kern_get_timezone(NULL
, timeZoneID
, sizeof(timeZoneID
));
51 gLocaleBackend
->TZSet(timeZoneID
, getenv("TZ"));
56 localtime(const time_t* inTime
)
60 return localtime_r(inTime
, &tm
);
65 localtime_r(const time_t* inTime
, struct tm
* tmOut
)
73 if (gLocaleBackend
!= NULL
) {
74 status_t status
= gLocaleBackend
->Localtime(inTime
, tmOut
);
77 __set_errno(EOVERFLOW
);
82 // without a locale backend, there are no timezones, so we fall back to
83 // using a basic gmtime_r implementation.
84 return __gmtime_r_fallback(inTime
, tmOut
);
89 gmtime(const time_t* inTime
)
93 return gmtime_r(inTime
, &tm
);
98 gmtime_r(const time_t* inTime
, struct tm
* tmOut
)
100 if (inTime
== NULL
) {
106 if (gLocaleBackend
!= NULL
) {
107 status_t status
= gLocaleBackend
->Gmtime(inTime
, tmOut
);
110 __set_errno(EOVERFLOW
);
115 // without a locale backend, we fall back to using a basic gmtime_r
117 return __gmtime_r_fallback(inTime
, tmOut
);
122 mktime(struct tm
* inTm
)
130 if (gLocaleBackend
!= NULL
) {
132 status_t status
= gLocaleBackend
->Mktime(inTm
, timeOut
);
134 if (status
!= B_OK
) {
135 __set_errno(EOVERFLOW
);
142 // without a locale backend, we fall back to using a basic gmtime_r
144 return __mktime_fallback(inTm
);