1 mike 1.8 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.8 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include "System.h"
30
31 PEGASUS_NAMESPACE_BEGIN
32
33 #include <windows.h>
34 #include <sys/types.h>
35 #include <time.h>
36 #include <sys/timeb.h>
37 #include <io.h>
38 #include <direct.h>
39 #include <sys/stat.h>
40 #include <sys/types.h>
41
42 #define ACCESS_EXISTS 0
43 mike 1.8 #define ACCESS_WRITE 2
44 #define ACCESS_READ 4
45 #define ACCESS_READ_AND_WRITE 6
46
47 void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
48 {
49 FILETIME ft;
50 GetSystemTimeAsFileTime(&ft);
51 ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
52 largeInt.QuadPart -= 0x19db1ded53e8000;
53 seconds = long(largeInt.QuadPart / (10000 * 1000));
54 milliseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
55 }
56
57 String System::getCurrentASCIITime()
58 {
59 char tmpbuf[128];
60 _strtime( tmpbuf );
61 String time = tmpbuf;
62 _strdate( tmpbuf );
63 time.append("-");
64 mike 1.8 time.append(tmpbuf);
65 return time;
66 }
67
68 void System::sleep(Uint32 seconds)
69 {
70 Sleep(seconds * 1000);
71 }
72
73 Boolean System::exists(const char* path)
74 {
75 return _access(path, ACCESS_EXISTS) == 0;
76 }
77
78 Boolean System::canRead(const char* path)
79 {
80 return _access(path, ACCESS_READ) == 0;
81 }
82
83 Boolean System::canWrite(const char* path)
84 {
85 mike 1.8 return _access(path, ACCESS_WRITE) == 0;
86 }
87
88 Boolean System::getCurrentDirectory(char* path, Uint32 size)
89 {
90 return GetCurrentDirectory(size, path) != 0;
91 }
92
93 Boolean System::isDirectory(const char* path)
94 {
95 struct stat st;
96
97 if (stat(path, &st) != 0)
98 return false;
99
100 return (st.st_mode & _S_IFDIR) != 0;
101 }
102
103 Boolean System::changeDirectory(const char* path)
104 {
105 return chdir(path) == 0;
106 mike 1.8 }
107
108 Boolean System::makeDirectory(const char* path)
109 {
110 return _mkdir(path) == 0;
111 }
112
113 Boolean System::getFileSize(const char* path, Uint32& size)
114 {
115 struct stat st;
116
117 if (stat(path, &st) != 0)
118 return false;
119
120 size = st.st_size;
121 return true;
122 }
123
124 Boolean System::removeDirectory(const char* path)
125 {
126 return rmdir(path) == 0;
127 mike 1.8 }
128
129 Boolean System::removeFile(const char* path)
130 {
131 return unlink(path) == 0;
132 }
133
134 Boolean System::renameFile(const char* oldPath, const char* newPath)
135 {
136 return rename(oldPath, newPath) == 0;
137 }
138
139 DynamicLibraryHandle System::loadDynamicLibrary(const char* fileName)
140 {
141 return DynamicLibraryHandle(LoadLibrary(fileName));
142 }
143
144 DynamicSymbolHandle System::loadDynamicSymbol(
145 DynamicLibraryHandle libraryHandle,
146 const char* symbolName)
147 {
148 mike 1.8 return DynamicSymbolHandle(GetProcAddress(
149 (HINSTANCE)libraryHandle, symbolName));
150 }
151
|