POSIX fixes for native and crossplatform utils

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6427 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-01-21 14:13:00 +00:00
parent 859b5d3d07
commit 52a8b320ef
16 changed files with 66 additions and 46 deletions

View file

@ -22,8 +22,8 @@
// some definitions for non Win32 platforms were taken from MinGW's free Win32 library
#if defined(__cplusplus) && defined(MAKENSIS) && !defined(_MSC_VER)
template<class T> class NSISCHARTYPE{ T _c; public: NSISCHARTYPE(){} NSISCHARTYPE(T c):_c(c){} operator T()const{ return _c; } operator int()const{ return (int) _c; } operator bool()const{ return _c != 0; } };
#if defined(__cplusplus) && defined(MAKENSIS) && (!defined(_MSC_VER) || _MSC_VER > 1200)
template<class T> class NSISCHARTYPE{ T _c; public: NSISCHARTYPE(){} NSISCHARTYPE(T c):_c(c){} operator T()const{ return _c; } };
typedef NSISCHARTYPE<unsigned short> WINWCHAR; // WINWCHAR is always UTF16LE and should not be passed to wcs* functions
#else
typedef unsigned short WINWCHAR;

View file

@ -222,11 +222,10 @@ bool CResourceEditor::UpdateResourceW(const WINWCHAR* szType, WINWCHAR* szName,
#ifndef _UNICODE
static WINWCHAR* ResStringToUnicode(const char *szString) {
if (IS_INTRESOURCE(szString)) return MAKEINTRESOURCEWINW((ULONG_PTR)szString);
WINWCHAR *s = WinWStrDupFromTChar(szString, CP_ACP);
WINWCHAR *s = WinWStrDupFromTChar(szString);
if (!s) throw std::bad_alloc();
return s;
}
static void FreeUnicodeResString(WINWCHAR* szwString) {
if (!IS_INTRESOURCE(szwString)) free(szwString);
}

View file

@ -1109,7 +1109,7 @@ static INT_PTR CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // available_set is checked first so available is initialized
#pragma GCC diagnostic ignored "-Wuninitialized" // available_set is checked first so available is initialized
#endif
if (available_set && available < total)
error = NSIS_INSTDIR_NOT_ENOUGH_SPACE;

View file

@ -183,10 +183,15 @@ typedef unsigned char _TUCHAR;
// string comparisons
#define _tcscmp strcmp
#define _tcsicmp _stricmp
#define _tcsncmp strncmp
#define _tcsncicmp _strnicmp
#ifdef _WIN32
#define _tcsicmp _stricmp
#define _tcsnicmp _strnicmp
#else
#define _tcsicmp strcasecmp
#define _tcsnicmp strncasecmp
#endif
// upper / lower
#define _tcslwr _strlwr

View file

@ -22,10 +22,7 @@
UINT StrLenUTF16(const void*str)
{
unsigned short *p = (unsigned short *) str;
UINT cch = 0;
for(;p[cch];) ++cch;
return cch;
return sizeof(wchar_t) == 2 ? wcslen((wchar_t*)str) : InlineStrLenUTF16(str);
}
bool StrSetUTF16LE(tstring&dest, const void*src)

View file

@ -73,6 +73,14 @@ inline bool UTF8_GetTrailCount(unsigned char chFirst, unsigned char &cb)
return true;
}
inline UINT InlineStrLenUTF16(const void*str)
{
unsigned short *p = (unsigned short *) str;
UINT cch = 0;
for(;p[cch];) ++cch;
return cch;
}
#ifdef MAKENSIS
#include <stdlib.h>
#include <stdio.h>

View file

@ -406,6 +406,7 @@ int _wstat(const wchar_t *Path, struct stat *pS)
return retval;
}
#ifdef _UNICODE
static int NSISRT_wsystem(const wchar_t *wcmd)
{
if (!wcmd) return system(NULL);
@ -416,6 +417,7 @@ static int NSISRT_wsystem(const wchar_t *wcmd)
NSISRT_free(cmd);
return retval;
}
#endif
const char* nsis_iconv_get_host_endian_ucs4_code()
{
@ -945,8 +947,9 @@ int sane_system(const TCHAR *command)
#endif // ~_UNICODE
#else // !_WIN32
#ifndef _UNICODE
PATH_CONVERT(command);
return _tsystem(command);
TCHAR* cmd = const_cast<TCHAR*>(command);
PATH_CONVERT(cmd);
return _tsystem(cmd);
#else
return NSISRT_wsystem(command);
#endif

View file

@ -46,7 +46,11 @@ int WinWStrNICmpASCII(const WINWCHAR *a, const char *b, size_t n)
#ifndef _WIN32
size_t WinWStrLen(const WINWCHAR *s)
{
#ifdef MAKENSIS // Only makensis implements all the functions in utf.cpp
return StrLenUTF16(s);
#else
return sizeof(wchar_t) == 2 ? wcslen((wchar_t*)str) : InlineStrLenUTF16(str);
#endif
}
WINWCHAR* WinWStrCpy(WINWCHAR *d, const WINWCHAR *s)
@ -84,9 +88,17 @@ WINWCHAR* WinWStrDupFromWinWStr(const WINWCHAR *s)
WINWCHAR* WinWStrDupFromTChar(const TCHAR *s)
{
#ifdef MAKENSIS
WCToUTF16LEHlpr cnv;
if (!cnv.Create(s)) throw runtime_error("Unicode conversion failed");
return (WINWCHAR*) cnv.Detach();
#else
// NOTE: Anything outside the ASCII range will not convert correctly!
size_t cch = strlen(s);
WINWCHAR* p = (WINWCHAR*) malloc(++cch * 2);
if (p) for (size_t i = 0; i < cch; ++i) p[i] = s[i];
return p;
#endif
}
int WinWStrToInt(const WINWCHAR *s)
@ -102,17 +114,3 @@ int WinWStrToInt(const WINWCHAR *s)
return ((int)v) * sign;
}
#endif // ~!_WIN32
#if 0
WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage/* = CP_ACP*/)
{
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
if (l == 0)
throw runtime_error("Unicode conversion failed");
WCHAR *ws = new WCHAR[l + 1];
if (MultiByteToWideChar(codepage, 0, s, -1, ws, l + 1) == 0)
throw runtime_error("Unicode conversion failed");
return ws;
}
#endif

View file

@ -44,13 +44,4 @@ int WinWStrToInt(const WINWCHAR *s);
inline WINWCHAR* WinWStrDupFromTChar(const TCHAR *s, unsigned int codepage) { return WinWStrDupFromTChar(s); }
#endif
#if 0
WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage = CP_ACP);
#ifdef _UNICODE
#define wcsdup_fromTchar(s, codepage) _wcsdup(s) // codepage is not used in this mode
#else
#define wcsdup_fromTchar(s, codepage) wcsdup_fromansi(s, codepage)
#endif
#endif
#endif // ~INC_NSIS_WINCHAR