1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QFUNCTIONS_VXWORKS_H
41 #define QFUNCTIONS_VXWORKS_H
42 
43 #include <QtCore/qglobal.h>
44 
45 #ifdef Q_OS_VXWORKS
46 
47 #include <unistd.h>
48 #include <pthread.h>
49 #include <dirent.h>
50 #include <signal.h>
51 #include <string.h>
52 #include <strings.h>
53 #include <errno.h>
54 #include <sys/types.h>
55 #include <sys/ioctl.h>
56 #if defined(_WRS_KERNEL)
57 #include <sys/times.h>
58 #else
59 #include <sys/time.h>
60 #endif
61 #include <sys/socket.h>
62 #include <sys/stat.h>
63 #include <sys/wait.h>
64 #include <netinet/in.h>
65 
66 // VxWorks has public header mbuf.h which defines following variables for DKM.
67 // Let's undef those to because they overlap with Qt variable names-
68 // File mbuf.h is included in headers <netinet/in.h> <net/if.h>, so make sure
69 // that those are included before undef's.
70 #if defined(mbuf)
71 #  undef mbuf
72 #endif
73 #if defined(m_data)
74 #  undef m_data
75 #endif
76 #if defined(m_type)
77 #  undef m_type
78 #endif
79 #if defined(m_next)
80 #  undef m_next
81 #endif
82 #if defined(m_len)
83 #  undef m_len
84 #endif
85 #if defined(m_flags)
86 #  undef m_flags
87 #endif
88 #if defined(m_hdr)
89 #  undef m_hdr
90 #endif
91 #if defined(m_ext)
92 #  undef m_ext
93 #endif
94 #if defined(m_act)
95 #  undef m_act
96 #endif
97 #if defined(m_nextpkt)
98 #  undef m_nextpkt
99 #endif
100 #if defined(m_pkthdr)
101 #  undef m_pkthdr
102 #endif
103 
104 QT_BEGIN_NAMESPACE
105 
106 #ifdef QT_BUILD_CORE_LIB
107 #endif
108 
109 QT_END_NAMESPACE
110 
111 #ifndef RTLD_LOCAL
112 #define RTLD_LOCAL  0
113 #endif
114 
115 #ifndef NSIG
116 #define NSIG _NSIGS
117 #endif
118 
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122 
123 // isascii is missing (sometimes!!)
124 #ifndef isascii
isascii(int c)125 inline int isascii(int c)  { return (c & 0x7f); }
126 #endif
127 
128 // no lfind() - used by the TIF image format
129 void *lfind(const void* key, const void* base, size_t* elements, size_t size,
130             int (*compare)(const void*, const void*));
131 
132 // no rand_r(), but rand()
133 // NOTE: this implementation is wrong for multi threaded applications,
134 // but there is no way to get it right on VxWorks (in kernel mode)
135 #if defined(_WRS_KERNEL)
136 int rand_r(unsigned int * /*seedp*/);
137 #endif
138 
139 // no usleep() support
140 int usleep(unsigned int);
141 
142 #if defined(VXWORKS_DKM) || defined(VXWORKS_RTP)
143 int gettimeofday(struct timeval *, void *);
144 #else
145 // gettimeofday() is declared, but is missing from the library.
146 // It IS however defined in the Curtis-Wright X11 libraries, so
147 // we have to make the symbol 'weak'
148 int gettimeofday(struct timeval *tv, void /*struct timezone*/ *) __attribute__((weak));
149 #endif
150 
151 // getpagesize() not available
152 int getpagesize();
153 
154 // symlinks are not supported (lstat is now just a call to stat - see qplatformdefs.h)
155 int symlink(const char *, const char *);
156 ssize_t readlink(const char *, char *, size_t);
157 
158 // there's no truncate(), but ftruncate() support...
159 int truncate(const char *path, off_t length);
160 
161 // VxWorks doesn't know about passwd & friends.
162 // in order to avoid patching the unix fs path everywhere
163 // we introduce some dummy functions that simulate a single
164 // 'root' user on the system.
165 
166 uid_t getuid();
167 gid_t getgid();
168 uid_t geteuid();
169 
170 struct passwd {
171     char   *pw_name;       /* user name */
172     char   *pw_passwd;     /* user password */
173     uid_t   pw_uid;        /* user ID */
174     gid_t   pw_gid;        /* group ID */
175     char   *pw_gecos;      /* real name */
176     char   *pw_dir;        /* home directory */
177     char   *pw_shell;      /* shell program */
178 };
179 
180 struct group {
181     char   *gr_name;       /* group name */
182     char   *gr_passwd;     /* group password */
183     gid_t   gr_gid;        /* group ID */
184     char  **gr_mem;        /* group members */
185 };
186 
187 struct passwd *getpwuid(uid_t uid);
188 struct group *getgrgid(gid_t gid);
189 
190 #ifdef __cplusplus
191 } // extern "C"
192 #endif
193 
194 #endif // Q_OS_VXWORKS
195 #endif // QFUNCTIONS_VXWORKS_H
196