author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qglobal.h" |
|
43 |
||
44 |
#ifdef Q_OS_VXWORKS |
|
45 |
||
46 |
#include "qplatformdefs.h" |
|
47 |
#include "qfunctions_vxworks.h" |
|
48 |
||
49 |
#include <vmLib.h> |
|
50 |
#include <selectLib.h> |
|
51 |
#include <ioLib.h> |
|
52 |
||
53 |
QT_USE_NAMESPACE |
|
54 |
||
55 |
#ifdef __cplusplus |
|
56 |
extern "C" { |
|
57 |
#endif |
|
58 |
||
59 |
// no lfind() - used by the TIF image format |
|
60 |
void *lfind(const void* key, const void* base, size_t* elements, size_t size, |
|
61 |
int (*compare)(const void*, const void*)) |
|
62 |
{ |
|
63 |
const char* current = (char*) base; |
|
64 |
const char* const end = (char*) (current + (*elements) * size); |
|
65 |
while (current != end) { |
|
66 |
if (compare(current, key) == 0) |
|
67 |
return (void*)current; |
|
68 |
current += size; |
|
69 |
} |
|
70 |
return 0; |
|
71 |
} |
|
72 |
||
73 |
||
74 |
// no rand_r(), but rand() |
|
75 |
// NOTE: this implementation is wrong for multi threaded applications, |
|
76 |
// but there is no way to get it right on VxWorks (in kernel mode) |
|
77 |
int rand_r(unsigned int * /*seedp*/) |
|
78 |
{ |
|
79 |
return rand(); |
|
80 |
} |
|
81 |
||
82 |
// no usleep() support |
|
83 |
int usleep(unsigned int usec) |
|
84 |
{ |
|
85 |
div_t dt = div(usec, 1000000); |
|
86 |
struct timespec ts = { dt.quot, dt.rem * 1000 }; |
|
87 |
||
88 |
return nanosleep(&ts, 0); |
|
89 |
} |
|
90 |
||
91 |
||
92 |
// gettimeofday() is declared, but is missing from the library |
|
93 |
// It IS however defined in the Curtis-Wright X11 libraries, so |
|
94 |
// we have to make the symbol 'weak' |
|
95 |
#if defined(Q_CC_DIAB) |
|
96 |
# pragma weak gettimeofday |
|
97 |
#endif |
|
98 |
int gettimeofday(struct timeval *tv, void /*struct timezone*/ *) |
|
99 |
{ |
|
100 |
// the compiler will optimize this and will only use one code path |
|
101 |
if (sizeof(struct timeval) == sizeof(struct timespec)) { |
|
102 |
int res = clock_gettime(CLOCK_REALTIME, (struct timespec *) tv); |
|
103 |
if (!res) |
|
104 |
tv->tv_usec /= 1000; |
|
105 |
return res; |
|
106 |
} else { |
|
107 |
struct timespec ts; |
|
108 |
||
109 |
int res = clock_gettime(CLOCK_REALTIME, &ts); |
|
110 |
if (!res) { |
|
111 |
tv->tv_sec = ts.tv_sec; |
|
112 |
tv->tv_usec = ts.tv_nsec / 1000; |
|
113 |
} |
|
114 |
return res; |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
// neither getpagesize() or sysconf(_SC_PAGESIZE) are available |
|
119 |
int getpagesize() |
|
120 |
{ |
|
121 |
return vmPageSizeGet(); |
|
122 |
} |
|
123 |
||
124 |
// symlinks are not supported (lstat is now just a call to stat - see qplatformdefs.h) |
|
125 |
int symlink(const char *, const char *) |
|
126 |
{ |
|
127 |
errno = EIO; |
|
128 |
return -1; |
|
129 |
} |
|
130 |
||
131 |
ssize_t readlink(const char *, char *, size_t) |
|
132 |
{ |
|
133 |
errno = EIO; |
|
134 |
return -1; |
|
135 |
} |
|
136 |
||
137 |
// there's no truncate(), but ftruncate() support... |
|
138 |
int truncate(const char *path, off_t length) |
|
139 |
{ |
|
140 |
int fd = open(path, O_WRONLY, 00777); |
|
141 |
if (fd >= 0) { |
|
142 |
int res = ftruncate(fd, length); |
|
143 |
int en = errno; |
|
144 |
close(fd); |
|
145 |
errno = en; |
|
146 |
return res; |
|
147 |
} |
|
148 |
// errno is already set by open |
|
149 |
return -1; |
|
150 |
} |
|
151 |
||
152 |
||
153 |
||
154 |
// VxWorks doesn't know about passwd & friends. |
|
155 |
// in order to avoid patching the unix fs path everywhere |
|
156 |
// we introduce some dummy functions that simulate a single |
|
157 |
// 'root' user on the system. |
|
158 |
||
159 |
uid_t getuid() |
|
160 |
{ |
|
161 |
return 0; |
|
162 |
} |
|
163 |
||
164 |
gid_t getgid() |
|
165 |
{ |
|
166 |
return 0; |
|
167 |
} |
|
168 |
||
169 |
uid_t geteuid() |
|
170 |
{ |
|
171 |
return 0; |
|
172 |
} |
|
173 |
||
174 |
struct passwd *getpwuid(uid_t uid) |
|
175 |
{ |
|
176 |
static struct passwd pwbuf = { "root", 0, 0, 0, 0, 0, 0 }; |
|
177 |
||
178 |
if (uid == 0) { |
|
179 |
return &pwbuf; |
|
180 |
} else { |
|
181 |
errno = ENOENT; |
|
182 |
return 0; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
struct group *getgrgid(gid_t gid) |
|
187 |
{ |
|
188 |
static struct group grbuf = { "root", 0, 0, 0 }; |
|
189 |
||
190 |
if (gid == 0) { |
|
191 |
return &grbuf; |
|
192 |
} else { |
|
193 |
errno = ENOENT; |
|
194 |
return 0; |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
#ifdef __cplusplus |
|
199 |
} // extern "C" |
|
200 |
#endif |
|
201 |
||
202 |
#endif // Q_OS_VXWORKS |