Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfunctions_vxworks.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qglobal.h"
5
6#ifdef Q_OS_VXWORKS
7
8#include "qplatformdefs.h"
10
11#if defined(_WRS_KERNEL)
12#include <vmLib.h>
13#endif
14#include <selectLib.h>
15#include <ioLib.h>
16
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23// no lfind() - used by the TIF image format
24void *lfind(const void* key, const void* base, size_t* elements, size_t size,
25 int (*compare)(const void*, const void*))
26{
27 const char* current = (char*) base;
28 const char* const end = (char*) (current + (*elements) * size);
29 while (current != end) {
30 if (compare(current, key) == 0)
31 return (void*)current;
32 current += size;
33 }
34 return 0;
35}
36
37
38// no rand_r(), but rand()
39// NOTE: this implementation is wrong for multi threaded applications,
40// but there is no way to get it right on VxWorks (in kernel mode)
41#if defined(_WRS_KERNEL)
42int rand_r(unsigned int * /*seedp*/)
43{
44 return rand();
45}
46#endif
47
48// no usleep() support
49int usleep(unsigned int usec)
50{
51 div_t dt = div(usec, 1000000);
52 struct timespec ts = { dt.quot, dt.rem * 1000 };
53
54 return nanosleep(&ts, 0);
55}
56
57
58// gettimeofday() is declared, but is missing from the library
59// It IS however defined in the Curtis-Wright X11 libraries, so
60// we have to make the symbol 'weak'
61#if defined(Q_CC_DIAB) && !defined(VXWORKS_DKM) && !defined(VXWORKS_RTP)
62# pragma weak gettimeofday
63#endif
64int gettimeofday(struct timeval *tv, void /*struct timezone*/ *)
65{
66 // the compiler will optimize this and will only use one code path
67 if (sizeof(struct timeval) == sizeof(struct timespec)) {
68 int res = clock_gettime(CLOCK_REALTIME, (struct timespec *) tv);
69 if (!res)
70 tv->tv_usec /= 1000;
71 return res;
72 } else {
73 struct timespec ts;
74
75 int res = clock_gettime(CLOCK_REALTIME, &ts);
76 if (!res) {
77 tv->tv_sec = ts.tv_sec;
78 tv->tv_usec = ts.tv_nsec / 1000;
79 }
80 return res;
81 }
82}
83
84// neither getpagesize() or sysconf(_SC_PAGESIZE) are available
85int getpagesize()
86{
87#if defined(_WRS_KERNEL)
88 return vmPageSizeGet();
89#else
90 return sysconf(_SC_PAGESIZE);
91#endif
92}
93
94// symlinks are not supported (lstat is now just a call to stat - see qplatformdefs.h)
95int symlink(const char *, const char *)
96{
97 errno = EIO;
98 return -1;
99}
100
101ssize_t readlink(const char *, char *, size_t)
102{
103 errno = EIO;
104 return -1;
105}
106
107// there's no truncate(), but ftruncate() support...
108int truncate(const char *path, off_t length)
109{
110 int fd = open(path, O_WRONLY, 00777);
111 if (fd >= 0) {
112 int res = ftruncate(fd, length);
113 int en = errno;
114 close(fd);
115 errno = en;
116 return res;
117 }
118 // errno is already set by open
119 return -1;
120}
121
122
123
124// VxWorks doesn't know about passwd & friends.
125// in order to avoid patching the unix fs path everywhere
126// we introduce some dummy functions that simulate a single
127// 'root' user on the system.
128
129uid_t getuid()
130{
131 return 0;
132}
133
134gid_t getgid()
135{
136 return 0;
137}
138
139uid_t geteuid()
140{
141 return 0;
142}
143
144struct passwd *getpwuid(uid_t uid)
145{
146 static struct passwd pwbuf = { "root", 0, 0, 0, 0, 0, 0 };
147
148 if (uid == 0) {
149 return &pwbuf;
150 } else {
151 errno = ENOENT;
152 return 0;
153 }
154}
155
156struct group *getgrgid(gid_t gid)
157{
158 static struct group grbuf = { "root", 0, 0, 0 };
159
160 if (gid == 0) {
161 return &grbuf;
162 } else {
163 errno = ENOENT;
164 return 0;
165 }
166}
167
168#ifdef __cplusplus
169} // extern "C"
170#endif
171
172#endif // Q_OS_VXWORKS
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLboolean GLuint group
GLuint64 GLenum GLint fd
GLuint res
GLsizei const GLchar *const * path
static const QTextHtmlElement elements[Html_NumElements]
static int compare(quint64 a, quint64 b)
file open(QIODevice::ReadOnly)