forked from strawlab/iana-time-zone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl_haiku.cc
40 lines (32 loc) · 889 Bytes
/
impl_haiku.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "iana-time-zone/include/impl_haiku.h"
#include "iana-time-zone/src/tz_haiku.rs.h"
#include <cstring>
#include <Errors.h>
#include <LocaleRoster.h>
#include <String.h>
#include <TimeZone.h>
size_t ::tz_haiku::get_tz(uint8_t *buf, size_t buf_len) {
static_assert(sizeof(char) == sizeof(uint8_t), "Illegal char size");
if (!buf || !buf_len) {
return 0;
}
BLocaleRoster *locale_roster(BLocaleRoster::Default());
if (!locale_roster) {
return 0;
}
BTimeZone tz(NULL, NULL);
if (locale_roster->GetDefaultTimeZone(&tz) != B_OK) {
return 0;
}
BString bname(tz.ID());
int32_t length(bname.Length());
if (length <= 0 || size_t(length) > buf_len) {
return 0;
}
const char *sname(bname.String());
if (!sname) {
return 0;
}
std::memcpy(buf, sname, length);
return length;
}