~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/kernel/qfunctions_vxworks.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtCore module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
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