1'
2' LinuxDriver.vb
3'
4' Authors:
5'   Rolf Bjarne Kvinge (RKvinge@novell.com>
6'
7' Copyright (C) 2007 Novell (http://www.novell.com)
8'
9' Permission is hereby granted, free of charge, to any person obtaining
10' a copy of this software and associated documentation files (the
11' "Software"), to deal in the Software without restriction, including
12' without limitation the rights to use, copy, modify, merge, publish,
13' distribute, sublicense, and/or sell copies of the Software, and to
14' permit persons to whom the Software is furnished to do so, subject to
15' the following conditions:
16'
17' The above copyright notice and this permission notice shall be
18' included in all copies or substantial portions of the Software.
19'
20' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27'
28Imports System
29Imports System.Runtime.InteropServices
30
31Namespace Microsoft.VisualBasic.OSSpecific
32    Friend Class LinuxDriver
33        Inherits OSDriver
34
35        Public Overrides Sub SetDate(ByVal Value As Date)
36            Dim Now As System.DateTime = DateTime.Now
37            Dim NewDate As System.DateTime = New DateTime(Value.Year, Value.Month, Value.Day, Now.Hour, Now.Minute, Now.Second, Now.Millisecond)
38            Dim secondsTimeSpan As System.TimeSpan = NewDate.ToUniversalTime().Subtract(New DateTime(1970, 1, 1, 0, 0, 0))
39            Dim seconds As Integer = CType(secondsTimeSpan.TotalSeconds, Integer)
40
41#If TARGET_JVM = False Then
42            If (stime(seconds) = -1) Then
43                Throw New UnauthorizedAccessException("The caller is not the super-user.")
44            End If
45#Else
46            MyBase.SetTime (Value)
47#End If
48        End Sub
49
50
51        Public Overrides Sub SetTime(ByVal Value As Date)
52            Dim Now As System.DateTime = DateTime.Now
53            Dim NewDate As System.DateTime = New DateTime(Now.Year, Now.Month, Now.Day, Value.Hour, Value.Minute, Value.Second, Value.Millisecond)
54            Dim secondsTimeSpan As System.TimeSpan = NewDate.ToUniversalTime().Subtract(New DateTime(1970, 1, 1, 0, 0, 0))
55            Dim seconds As Integer = CType(secondsTimeSpan.TotalSeconds, Integer)
56
57#If TARGET_JVM = False Then
58            If (stime(seconds) = -1) Then
59                Throw New UnauthorizedAccessException("The caller is not the super-user.")
60            End If
61#Else
62            MyBase.SetTime (Value)
63#End If
64        End Sub
65
66#If TARGET_JVM = False Then
67        <DllImport("libc", EntryPoint:="stime", _
68           SetLastError:=True, CharSet:=CharSet.Unicode, _
69           ExactSpelling:=True, _
70           CallingConvention:=CallingConvention.StdCall)> _
71        Friend Shared Function stime(ByRef t As Integer) As Integer
72            ' Leave function empty - DllImport attribute forwards calls to stime to
73            ' stime in libc.dll
74        End Function
75#End If
76
77    End Class
78End Namespace