2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
20 internal static partial class Interop
22 internal static partial class Libc
24 [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
25 internal static extern int Free(IntPtr ptr);
27 // Broken-down time is stored in the structure tm which is defined in <time.h> as follows:
28 [StructLayout(LayoutKind.Sequential)]
29 internal struct SystemTime
41 // The glibc version of struct tm has additional fields
42 public long tm_gmtoff;
43 public IntPtr tm_zone;
45 public static implicit operator SystemTime(DateTime value)
47 SystemTime tm = new SystemTime();
48 tm.tm_sec = value.Second;
49 tm.tm_min = value.Minute;
50 tm.tm_hour = value.Hour;
51 tm.tm_mday = value.Day;
52 tm.tm_mon = value.Month - 1;
53 tm.tm_year = value.Year - 1900;
54 tm.tm_wday = (int)value.DayOfWeek;
55 tm.tm_yday = value.DayOfYear;
56 tm.tm_isdst = value.IsDaylightSavingTime() ? 1 : 0;
60 public static implicit operator DateTime(SystemTime value)
62 DateTime date = new DateTime(value.tm_year + 1900, value.tm_mon + 1, value.tm_mday, value.tm_hour, value.tm_min, value.tm_sec);