xref: /haiku/src/system/libroot/posix/time/localtime.cpp (revision 1345706a9ff6ad0dc041339a02d4259998b0765d)
1 /*
2  * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <stdio.h>
8 #include <string.h>
9 
10 #include <localtime.h>
11 
12 #include <FindDirectory.h>
13 #include <StorageDefs.h>
14 
15 
16 char* tzname[2] = { "???", "???" };
17 long timezone = 0;
18 int daylight = 0;
19 
20 
21 namespace BPrivate {
22 
23 
24 static time_zone_info tzInfo;
25 
26 
27 extern "C" void
28 tzset(void)
29 {
30 	char path[B_PATH_NAME_LENGTH];
31 	if (find_directory(B_COMMON_SETTINGS_DIRECTORY, -1, false, path,
32 			sizeof(path)) < 0)
33 		return;
34 	strlcat(path, "/", sizeof(path));
35 	strlcat(path, skPosixTimeZoneInfoFile, sizeof(path));
36 
37 	FILE* tzInfoFile = fopen(path, "r");
38 	if (tzInfoFile == NULL)
39 		return;
40 
41 	size_t numRead = fread(&tzInfo, sizeof(tzInfo), 1, tzInfoFile);
42 	fclose(tzInfoFile);
43 
44 	if (numRead != 1)
45 		return;
46 
47 	tzname[0] = tzInfo.short_std_name;
48 	tzname[1] = tzInfo.short_dst_name;
49 	timezone = tzInfo.offset_from_gmt;
50 	daylight = tzInfo.uses_daylight_saving;
51 }
52 
53 
54 }	// namespace BPrivate
55