Combine environment variable implementations
Environment variable storage implementations on Windows Runtime and CE are very similar. For better maintainability have just one implementation. Change-Id: I12ec38f7bde3fcc0bcc56face88d5f19cf3b3504 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Andreas Holzammer <andreas.holzammer@kdab.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
This commit is contained in:
parent
eb812cf3ce
commit
ba40d1a872
@ -88,6 +88,7 @@ wince {
|
||||
SOURCES += \
|
||||
kernel/qfunctions_wince.cpp
|
||||
HEADERS += \
|
||||
kernel/qfunctions_fake_env_p.h \
|
||||
kernel/qfunctions_wince.h
|
||||
}
|
||||
|
||||
@ -95,6 +96,7 @@ winrt {
|
||||
SOURCES += \
|
||||
kernel/qfunctions_winrt.cpp
|
||||
HEADERS += \
|
||||
kernel/qfunctions_fake_env_p.h \
|
||||
kernel/qfunctions_winrt.h
|
||||
}
|
||||
|
||||
|
101
src/corelib/kernel/qfunctions_fake_env_p.h
Normal file
101
src/corelib/kernel/qfunctions_fake_env_p.h
Normal file
@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL21$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see http://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** As a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QFUNCTIONS_FAKE_ENV_P_H
|
||||
#define QFUNCTIONS_FAKE_ENV_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists for the convenience
|
||||
// of the QLibrary class. This header file may change from
|
||||
// version to version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qbytearray.h"
|
||||
#include "qhash.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// Environment ------------------------------------------------------
|
||||
Q_CORE_EXPORT QHash<QByteArray, QByteArray> &qt_app_environment()
|
||||
{
|
||||
static QHash<QByteArray, QByteArray> internalEnvironment;
|
||||
return internalEnvironment;
|
||||
}
|
||||
|
||||
errno_t qt_fake_getenv_s(size_t *sizeNeeded, char *buffer, size_t bufferSize, const char *varName)
|
||||
{
|
||||
if (!sizeNeeded)
|
||||
return EINVAL;
|
||||
|
||||
QHash<QByteArray, QByteArray>::const_iterator iterator = qt_app_environment().constFind(varName);
|
||||
if (iterator == qt_app_environment().constEnd()) {
|
||||
if (buffer)
|
||||
buffer[0] = '\0';
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
const int size = iterator->size() + 1;
|
||||
if (bufferSize < size_t(size)) {
|
||||
*sizeNeeded = size;
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
qstrcpy(buffer, iterator->constData());
|
||||
return 0;
|
||||
}
|
||||
|
||||
errno_t qt_fake__putenv_s(const char *varName, const char *value)
|
||||
{
|
||||
QHash<QByteArray, QByteArray>::iterator iterator = qt_app_environment().find(varName);
|
||||
QHash<QByteArray, QByteArray>::iterator end = qt_app_environment().end();
|
||||
if (!value || !*value) {
|
||||
if (iterator != end)
|
||||
qt_app_environment().erase(iterator);
|
||||
} else {
|
||||
if (iterator == end)
|
||||
qt_app_environment()[varName] = QByteArray(value);
|
||||
else
|
||||
(*iterator) = value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QFUNCTIONS_FAKE_ENV_P_H
|
@ -44,9 +44,8 @@
|
||||
|
||||
#include "qplatformdefs.h"
|
||||
#include "qfunctions_wince.h"
|
||||
#include "qfunctions_fake_env_p.h"
|
||||
#include "qstring.h"
|
||||
#include "qbytearray.h"
|
||||
#include "qhash.h"
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
@ -399,51 +398,4 @@ int qt_wince__getpid()
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
// Environment ------------------------------------------------------
|
||||
inline QHash<QByteArray, QByteArray>& qt_app_environment()
|
||||
{
|
||||
static QHash<QByteArray, QByteArray> internalEnvironment;
|
||||
return internalEnvironment;
|
||||
}
|
||||
|
||||
errno_t qt_wince_getenv_s(size_t* sizeNeeded, char* buffer, size_t bufferSize, const char* varName)
|
||||
{
|
||||
if (!sizeNeeded)
|
||||
return EINVAL;
|
||||
|
||||
if (!qt_app_environment().contains(varName)) {
|
||||
if (buffer)
|
||||
buffer[0] = '\0';
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
QByteArray value = qt_app_environment().value(varName);
|
||||
if (!value.endsWith('\0')) // win32 guarantees terminated string
|
||||
value.append('\0');
|
||||
|
||||
if (bufferSize < (size_t)value.size()) {
|
||||
*sizeNeeded = value.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(buffer, value.constData());
|
||||
return 0;
|
||||
}
|
||||
|
||||
errno_t qt_wince__putenv_s(const char* varName, const char* value)
|
||||
{
|
||||
QByteArray input = value;
|
||||
if (input.isEmpty()) {
|
||||
if (qt_app_environment().contains(varName))
|
||||
qt_app_environment().remove(varName);
|
||||
} else {
|
||||
// win32 guarantees terminated string
|
||||
if (!input.endsWith('\0'))
|
||||
input.append('\0');
|
||||
qt_app_environment()[varName] = input;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // Q_OS_WINCE
|
||||
|
@ -76,8 +76,8 @@ QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
// Environment ------------------------------------------------------
|
||||
errno_t qt_wince_getenv_s(size_t*, char*, size_t, const char*);
|
||||
errno_t qt_wince__putenv_s(const char*, const char*);
|
||||
errno_t qt_fake_getenv_s(size_t*, char*, size_t, const char*);
|
||||
errno_t qt_fake__putenv_s(const char*, const char*);
|
||||
|
||||
#ifdef __cplusplus // have this as tiff plugin is written in C
|
||||
extern "C" {
|
||||
@ -398,20 +398,20 @@ typedef DWORD OLE_COLOR;
|
||||
{ \
|
||||
return qt_wince_##funcname(p1); \
|
||||
}
|
||||
#define generate_inline_return_func2(funcname, returntype, param1, param2) \
|
||||
#define generate_inline_return_func2(funcname, returntype, prependnamespace, param1, param2) \
|
||||
inline returntype funcname(param1 p1, param2 p2) \
|
||||
{ \
|
||||
return qt_wince_##funcname(p1, p2); \
|
||||
return prependnamespace##funcname(p1, p2); \
|
||||
}
|
||||
#define generate_inline_return_func3(funcname, returntype, param1, param2, param3) \
|
||||
inline returntype funcname(param1 p1, param2 p2, param3 p3) \
|
||||
{ \
|
||||
return qt_wince_##funcname(p1, p2, p3); \
|
||||
}
|
||||
#define generate_inline_return_func4(funcname, returntype, param1, param2, param3, param4) \
|
||||
#define generate_inline_return_func4(funcname, returntype, prependnamespace, param1, param2, param3, param4) \
|
||||
inline returntype funcname(param1 p1, param2 p2, param3 p3, param4 p4) \
|
||||
{ \
|
||||
return qt_wince_##funcname(p1, p2, p3, p4); \
|
||||
return prependnamespace##funcname(p1, p2, p3, p4); \
|
||||
}
|
||||
#define generate_inline_return_func5(funcname, returntype, param1, param2, param3, param4, param5) \
|
||||
inline returntype funcname(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
|
||||
@ -433,28 +433,28 @@ typedef unsigned (__stdcall *StartAdressExFunc)(void *);
|
||||
typedef void(*StartAdressFunc)(void *);
|
||||
typedef int ( __cdecl *CompareFunc ) (const void *, const void *) ;
|
||||
|
||||
generate_inline_return_func4(getenv_s, errno_t, size_t *, char *, size_t, const char *)
|
||||
generate_inline_return_func2(_putenv_s, errno_t, const char *, const char *)
|
||||
generate_inline_return_func4(getenv_s, errno_t, qt_fake_, size_t *, char *, size_t, const char *)
|
||||
generate_inline_return_func2(_putenv_s, errno_t, qt_fake_, const char *, const char *)
|
||||
generate_inline_return_func0(_getpid, int)
|
||||
generate_inline_return_func1(time_tToFt, FILETIME, time_t)
|
||||
generate_inline_return_func1(ftToTime_t, time_t, FILETIME)
|
||||
generate_inline_return_func0(_getdrive, int)
|
||||
generate_inline_return_func2(_waccess, int, const wchar_t *, int)
|
||||
generate_inline_return_func2(_waccess, int, qt_wince_, const wchar_t *, int)
|
||||
generate_inline_return_func3(_wopen, int, const wchar_t *, int, int)
|
||||
generate_inline_return_func2(_fdopen, FILE *, int, const char *)
|
||||
generate_inline_return_func2(fdopen, FILE *, int, const char *)
|
||||
generate_inline_return_func2(_fdopen, FILE *, qt_wince_, int, const char *)
|
||||
generate_inline_return_func2(fdopen, FILE *, qt_wince_, int, const char *)
|
||||
generate_inline_return_func1(rewind, void, FILE *)
|
||||
generate_inline_return_func0(tmpfile, FILE *)
|
||||
generate_inline_return_func2(_rename, int, const char *, const char *)
|
||||
generate_inline_return_func2(_rename, int, qt_wince_, const char *, const char *)
|
||||
generate_inline_return_func1(_remove, int, const char *)
|
||||
generate_inline_return_func1(SetErrorMode, int, int)
|
||||
#if _WIN32_WCE < 0x800
|
||||
generate_inline_return_func2(_chmod, bool, const char *, int)
|
||||
generate_inline_return_func2(_wchmod, bool, const wchar_t *, int)
|
||||
generate_inline_return_func2(_chmod, bool, qt_wince_, const char *, int)
|
||||
generate_inline_return_func2(_wchmod, bool, qt_wince_, const wchar_t *, int)
|
||||
#endif
|
||||
generate_inline_return_func7(CreateFileA, HANDLE, LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE)
|
||||
generate_inline_return_func4(SetWindowOrgEx, BOOL, HDC, int, int, LPPOINT)
|
||||
generate_inline_return_func2(calloc, void *, size_t, size_t)
|
||||
generate_inline_return_func4(SetWindowOrgEx, BOOL, qt_wince_, HDC, int, int, LPPOINT)
|
||||
generate_inline_return_func2(calloc, void *, qt_wince_, size_t, size_t)
|
||||
generate_inline_return_func0(GetThreadLocale, DWORD)
|
||||
generate_inline_return_func3(_beginthread, HANDLE, StartAdressFunc, unsigned, void *)
|
||||
generate_inline_return_func6(_beginthreadex, unsigned long, void *, unsigned, StartAdressExFunc, void *, unsigned, unsigned *)
|
||||
|
@ -35,59 +35,10 @@
|
||||
|
||||
#ifdef Q_OS_WINRT
|
||||
|
||||
#include "qstring.h"
|
||||
#include "qbytearray.h"
|
||||
#include "qhash.h"
|
||||
#include "qfunctions_fake_env_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// Environment ------------------------------------------------------
|
||||
inline QHash<QByteArray, QByteArray> &qt_app_environment()
|
||||
{
|
||||
static QHash<QByteArray, QByteArray> internalEnvironment;
|
||||
return internalEnvironment;
|
||||
}
|
||||
|
||||
errno_t qt_winrt_getenv_s(size_t* sizeNeeded, char* buffer, size_t bufferSize, const char* varName)
|
||||
{
|
||||
if (!sizeNeeded)
|
||||
return EINVAL;
|
||||
|
||||
if (!qt_app_environment().contains(varName)) {
|
||||
if (buffer)
|
||||
buffer[0] = '\0';
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
QByteArray value = qt_app_environment().value(varName);
|
||||
if (!value.endsWith('\0')) // win32 guarantees terminated string
|
||||
value.append('\0');
|
||||
|
||||
if (bufferSize < (size_t)value.size()) {
|
||||
*sizeNeeded = value.size();
|
||||
return ERANGE;
|
||||
}
|
||||
|
||||
strcpy(buffer, value.constData());
|
||||
return 0;
|
||||
}
|
||||
|
||||
errno_t qt_winrt__putenv_s(const char* varName, const char* value)
|
||||
{
|
||||
QByteArray input = value;
|
||||
if (input.isEmpty()) {
|
||||
if (qt_app_environment().contains(varName))
|
||||
qt_app_environment().remove(varName);
|
||||
} else {
|
||||
// win32 on winrt guarantees terminated string
|
||||
if (!input.endsWith('\0'))
|
||||
input.append('\0');
|
||||
qt_app_environment()[varName] = input;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qt_winrt_tzset()
|
||||
{
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ QT_BEGIN_NAMESPACE
|
||||
#endif
|
||||
|
||||
// Environment ------------------------------------------------------
|
||||
errno_t qt_winrt_getenv_s(size_t*, char*, size_t, const char*);
|
||||
errno_t qt_winrt__putenv_s(const char*, const char*);
|
||||
errno_t qt_fake_getenv_s(size_t*, char*, size_t, const char*);
|
||||
errno_t qt_fake__putenv_s(const char*, const char*);
|
||||
void qt_winrt_tzset();
|
||||
void qt_winrt__tzset();
|
||||
|
||||
@ -91,20 +91,20 @@ QT_END_NAMESPACE
|
||||
{ \
|
||||
return QT_PREPEND_NAMESPACE(qt_winrt_##funcname)(p1); \
|
||||
}
|
||||
#define generate_inline_return_func2(funcname, returntype, param1, param2) \
|
||||
#define generate_inline_return_func2(funcname, returntype, prependnamespace, param1, param2) \
|
||||
inline returntype funcname(param1 p1, param2 p2) \
|
||||
{ \
|
||||
return QT_PREPEND_NAMESPACE(qt_winrt_##funcname)(p1, p2); \
|
||||
return QT_PREPEND_NAMESPACE(prependnamespace##funcname)(p1, p2); \
|
||||
}
|
||||
#define generate_inline_return_func3(funcname, returntype, param1, param2, param3) \
|
||||
inline returntype funcname(param1 p1, param2 p2, param3 p3) \
|
||||
{ \
|
||||
return QT_PREPEND_NAMESPACE(qt_winrt_##funcname)(p1, p2, p3); \
|
||||
}
|
||||
#define generate_inline_return_func4(funcname, returntype, param1, param2, param3, param4) \
|
||||
#define generate_inline_return_func4(funcname, returntype, prependnamespace, param1, param2, param3, param4) \
|
||||
inline returntype funcname(param1 p1, param2 p2, param3 p3, param4 p4) \
|
||||
{ \
|
||||
return QT_PREPEND_NAMESPACE(qt_winrt_##funcname)(p1, p2, p3, p4); \
|
||||
return QT_PREPEND_NAMESPACE(prependnamespace##funcname)(p1, p2, p3, p4); \
|
||||
}
|
||||
#define generate_inline_return_func5(funcname, returntype, param1, param2, param3, param4, param5) \
|
||||
inline returntype funcname(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
|
||||
@ -126,8 +126,8 @@ typedef unsigned (__stdcall *StartAdressExFunc)(void *);
|
||||
typedef void(*StartAdressFunc)(void *);
|
||||
typedef int ( __cdecl *CompareFunc ) (const void *, const void *) ;
|
||||
|
||||
generate_inline_return_func4(getenv_s, errno_t, size_t *, char *, size_t, const char *)
|
||||
generate_inline_return_func2(_putenv_s, errno_t, const char *, const char *)
|
||||
generate_inline_return_func4(getenv_s, errno_t, qt_fake_, size_t *, char *, size_t, const char *)
|
||||
generate_inline_return_func2(_putenv_s, errno_t, qt_fake_, const char *, const char *)
|
||||
generate_inline_return_func0(tzset, void)
|
||||
generate_inline_return_func0(_tzset, void)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user