winpr: initial port to Universal Windows Platform (UWP)

This commit is contained in:
Marc-André Moreau 2016-02-05 16:28:45 -05:00
parent bfca674f2d
commit d0f413db12
34 changed files with 332 additions and 198 deletions

View File

@ -138,7 +138,7 @@ extern "C" {
#define BitStream_GetRemainingLength(_bs) \
(_bs->length - _bs->position)
WINPR_API void BitDump(const char* tag, int level, const BYTE* buffer, UINT32 length, UINT32 flags);
WINPR_API void BitDump(const char* tag, UINT32 level, const BYTE* buffer, UINT32 length, UINT32 flags);
WINPR_API UINT32 ReverseBits32(UINT32 bits, UINT32 nbits);
WINPR_API void BitStream_Attach(wBitStream* bs, const BYTE* buffer, UINT32 capacity);

View File

@ -46,6 +46,32 @@ WINPR_API LPWSTR GetCommandLineW(VOID);
WINPR_API BOOL NeedCurrentDirectoryForExePathA(LPCSTR ExeName);
WINPR_API BOOL NeedCurrentDirectoryForExePathW(LPCWSTR ExeName);
#ifdef __cplusplus
}
#endif
#ifdef UNICODE
#define GetCurrentDirectory GetCurrentDirectoryW
#define SetCurrentDirectory SetCurrentDirectoryW
#define SearchPath SearchPathW
#define GetCommandLine GetCommandLineW
#define NeedCurrentDirectoryForExePath NeedCurrentDirectoryForExePathW
#else
#define GetCurrentDirectory GetCurrentDirectoryA
#define SetCurrentDirectory SetCurrentDirectoryA
#define SearchPath SearchPathA
#define GetCommandLine GetCommandLineA
#define NeedCurrentDirectoryForExePath NeedCurrentDirectoryForExePathA
#endif
#endif
#if !defined(_WIN32) || defined(_UWP)
#ifdef __cplusplus
extern "C" {
#endif
WINPR_API DWORD GetEnvironmentVariableA(LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);
WINPR_API DWORD GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, DWORD nSize);
@ -74,11 +100,6 @@ WINPR_API BOOL FreeEnvironmentStringsW(LPWCH lpszEnvironmentBlock);
#endif
#ifdef UNICODE
#define GetCurrentDirectory GetCurrentDirectoryW
#define SetCurrentDirectory SetCurrentDirectoryW
#define SearchPath SearchPathW
#define GetCommandLine GetCommandLineW
#define NeedCurrentDirectoryForExePath NeedCurrentDirectoryForExePathW
#define GetEnvironmentVariable GetEnvironmentVariableW
#define SetEnvironmentVariable SetEnvironmentVariableW
#define GetEnvironmentStrings GetEnvironmentStringsW
@ -86,11 +107,6 @@ WINPR_API BOOL FreeEnvironmentStringsW(LPWCH lpszEnvironmentBlock);
#define ExpandEnvironmentStrings ExpandEnvironmentStringsW
#define FreeEnvironmentStrings FreeEnvironmentStringsW
#else
#define GetCurrentDirectory GetCurrentDirectoryA
#define SetCurrentDirectory SetCurrentDirectoryA
#define SearchPath SearchPathA
#define GetCommandLine GetCommandLineA
#define NeedCurrentDirectoryForExePath NeedCurrentDirectoryForExePathA
#define GetEnvironmentVariable GetEnvironmentVariableA
#define SetEnvironmentVariable SetEnvironmentVariableA
#define GetEnvironmentStringsA GetEnvironmentStrings

View File

@ -23,7 +23,7 @@
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#ifndef _WIN32
#if !defined(_WIN32) || defined(_UWP)
typedef HANDLE DLL_DIRECTORY_COOKIE;
@ -46,24 +46,32 @@ WINPR_API HMODULE LoadLibraryW(LPCWSTR lpLibFileName);
WINPR_API HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
WINPR_API HMODULE LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
#ifdef __cplusplus
}
#endif
#ifdef UNICODE
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
#else
#define LoadLibrary LoadLibraryA
#define LoadLibraryEx LoadLibraryExA
#endif
#endif
#ifndef _WIN32
#ifdef __cplusplus
extern "C" {
#endif
WINPR_API HMODULE GetModuleHandleA(LPCSTR lpModuleName);
WINPR_API HMODULE GetModuleHandleW(LPCWSTR lpModuleName);
WINPR_API DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
WINPR_API DWORD GetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize);
#ifdef UNICODE
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
#define GetModuleHandle GetModuleHandleW
#define GetModuleFileName GetModuleFileNameW
#else
#define LoadLibrary LoadLibraryA
#define LoadLibraryEx LoadLibraryExA
#define GetModuleHandle GetModuleHandleA
#define GetModuleFileName GetModuleFileNameA
#endif
WINPR_API FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
WINPR_API BOOL FreeLibrary(HMODULE hLibModule);
@ -72,6 +80,14 @@ WINPR_API BOOL FreeLibrary(HMODULE hLibModule);
}
#endif
#ifdef UNICODE
#define GetModuleHandle GetModuleHandleW
#define GetModuleFileName GetModuleFileNameW
#else
#define GetModuleHandle GetModuleHandleA
#define GetModuleFileName GetModuleFileNameA
#endif
#endif
#endif /* WINPR_LIBRARY_H */

View File

@ -122,21 +122,6 @@
#define FACILITY_ACPI_ERROR_CODE 0x14
#define FACILITY_SXS_ERROR_CODE 0x15
//#define DBG_EXCEPTION_HANDLED ((NTSTATUS)0x00010001)
//#define DBG_CONTINUE ((NTSTATUS)0x00010002)
#define DBG_REPLY_LATER ((NTSTATUS)0x40010001)
#define DBG_UNABLE_TO_PROVIDE_HANDLE ((NTSTATUS)0x40010002)
//#define DBG_TERMINATE_THREAD ((NTSTATUS)0x40010003)
//#define DBG_TERMINATE_PROCESS ((NTSTATUS)0x40010004)
//#define DBG_CONTROL_C ((NTSTATUS)0x40010005)
//#define DBG_PRINTEXCEPTION_C ((NTSTATUS)0x40010006)
//#define DBG_RIPEXCEPTION ((NTSTATUS)0x40010007)
//#define DBG_CONTROL_BREAK ((NTSTATUS)0x40010008)
//#define DBG_COMMAND_EXCEPTION ((NTSTATUS)0x40010009)
//#define DBG_EXCEPTION_NOT_HANDLED ((NTSTATUS)0x80010001)
#define DBG_NO_STATE_CHANGE ((NTSTATUS)0xC0010001)
#define DBG_APP_NOT_IDLE ((NTSTATUS)0xC0010002)
/**
* NTSTATUS codes
*/
@ -1336,7 +1321,7 @@ typedef enum _FILE_INFORMATION_CLASS
FileShortNameInformation
} FILE_INFORMATION_CLASS;
#ifndef _WIN32
#if !defined(_WIN32) || defined(_UWP)
#define FILE_SUPERSEDE 0x00000000
#define FILE_OPEN 0x00000001
@ -1443,6 +1428,10 @@ typedef struct _IO_STATUS_BLOCK
typedef VOID (*PIO_APC_ROUTINE)(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
#endif
#if !defined(_WIN32)
typedef struct _PEB PEB;
typedef struct _PEB* PPEB;

View File

@ -33,8 +33,8 @@
extern "C" {
#endif
WINPR_API void winpr_HexDump(const char* tag, int lvl, const BYTE* data, int length);
WINPR_API void winpr_CArrayDump(const char* tag, int lvl, const BYTE* data, int length, int width);
WINPR_API void winpr_HexDump(const char* tag, UINT32 lvl, const BYTE* data, int length);
WINPR_API void winpr_CArrayDump(const char* tag, UINT32 lvl, const BYTE* data, int length, int width);
WINPR_API char* winpr_BinToHexString(const BYTE* data, int length, BOOL space);

View File

@ -62,6 +62,16 @@ WINPR_API WCHAR* _wcschr(const WCHAR* str, WCHAR c);
WINPR_API char* strtok_s(char* strToken, const char* strDelimit, char** context);
WINPR_API WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context);
#else
#define _wcscmp wcscmp
#define _wcslen wcslen
#define _wcschr wcschr
#endif
#if !defined(_WIN32) || defined(_UWP)
WINPR_API LPSTR CharUpperA(LPSTR lpsz);
WINPR_API LPWSTR CharUpperW(LPWSTR lpsz);
@ -152,6 +162,10 @@ WINPR_API int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2);
#define lstrcmp lstrcmpA
#endif
#endif
#ifndef _WIN32
#define sprintf_s snprintf
#define _snprintf snprintf
#define _scprintf(_fmt, ...) snprintf(NULL, 0, _fmt, ## __VA_ARGS__)
@ -166,12 +180,6 @@ WINPR_API int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiBy
WINPR_API int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar,
LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
#else
#define _wcscmp wcscmp
#define _wcslen wcslen
#define _wcschr wcschr
#endif
/* Extended API */

View File

@ -99,28 +99,6 @@ typedef struct _SYSTEM_INFO
WINPR_API void GetSystemInfo(LPSYSTEM_INFO lpSystemInfo);
WINPR_API void GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo);
typedef enum _COMPUTER_NAME_FORMAT
{
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
} COMPUTER_NAME_FORMAT;
WINPR_API BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD lpnSize);
WINPR_API BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD lpnSize);
#ifdef UNICODE
#define GetComputerNameEx GetComputerNameExW
#else
#define GetComputerNameEx GetComputerNameExA
#endif
typedef struct _OSVERSIONINFOA
{
DWORD dwOSVersionInfoSize;
@ -224,8 +202,6 @@ WINPR_API BOOL SetLocalTime(CONST SYSTEMTIME* lpSystemTime);
WINPR_API VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime);
WINPR_API BOOL GetSystemTimeAdjustment(PDWORD lpTimeAdjustment, PDWORD lpTimeIncrement, PBOOL lpTimeAdjustmentDisabled);
WINPR_API DWORD GetTickCount(void);
WINPR_API BOOL IsProcessorFeaturePresent(DWORD ProcessorFeature);
#define PF_FLOATING_POINT_PRECISION_ERRATA 0
@ -291,6 +267,34 @@ WINPR_API BOOL IsProcessorFeaturePresent(DWORD ProcessorFeature);
#endif
#if !defined(_WIN32) || defined(_UWP)
WINPR_API DWORD GetTickCount(void);
typedef enum _COMPUTER_NAME_FORMAT
{
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
} COMPUTER_NAME_FORMAT;
WINPR_API BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD lpnSize);
WINPR_API BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD lpnSize);
#ifdef UNICODE
#define GetComputerNameEx GetComputerNameExW
#else
#define GetComputerNameEx GetComputerNameExA
#endif
#endif
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
WINPR_API ULONGLONG GetTickCount64(void);

View File

@ -23,6 +23,7 @@
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#include <winpr/platform.h>
/**
* Standard Clipboard Formats
@ -102,7 +103,7 @@
* Bitmap Definitions
*/
#ifndef _WIN32
#if !defined(_WIN32)
#pragma pack(push, 1)
@ -165,15 +166,6 @@ typedef RGBQUAD FAR* LPRGBQUAD;
#define PROFILE_LINKED 'LINK'
#define PROFILE_EMBEDDED 'MBED'
typedef struct tagBITMAPCOREHEADER
{
DWORD bcSize;
WORD bcWidth;
WORD bcHeight;
WORD bcPlanes;
WORD bcBitCount;
} BITMAPCOREHEADER, FAR *LPBITMAPCOREHEADER, *PBITMAPCOREHEADER;
typedef struct tagBITMAPINFOHEADER
{
DWORD biSize;
@ -189,6 +181,39 @@ typedef struct tagBITMAPINFOHEADER
DWORD biClrImportant;
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
typedef struct tagBITMAPINFO
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, FAR *LPBITMAPINFO, *PBITMAPINFO;
typedef enum _ORIENTATION_PREFERENCE
{
ORIENTATION_PREFERENCE_NONE = 0x0,
ORIENTATION_PREFERENCE_LANDSCAPE = 0x1,
ORIENTATION_PREFERENCE_PORTRAIT = 0x2,
ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4,
ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8
} ORIENTATION_PREFERENCE;
#pragma pack(pop)
#endif
#if !defined(_WIN32) || defined(_UWP)
#pragma pack(push, 1)
typedef struct tagBITMAPCOREHEADER
{
DWORD bcSize;
WORD bcWidth;
WORD bcHeight;
WORD bcPlanes;
WORD bcBitCount;
} BITMAPCOREHEADER, FAR *LPBITMAPCOREHEADER, *PBITMAPCOREHEADER;
typedef struct
{
DWORD bV4Size;
@ -241,12 +266,6 @@ typedef struct
DWORD bV5Reserved;
} BITMAPV5HEADER, FAR *LPBITMAPV5HEADER, *PBITMAPV5HEADER;
typedef struct tagBITMAPINFO
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, FAR *LPBITMAPINFO, *PBITMAPINFO;
typedef struct tagBITMAPCOREINFO
{
BITMAPCOREHEADER bmciHeader;
@ -262,16 +281,6 @@ typedef struct tagBITMAPFILEHEADER
DWORD bfOffBits;
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
typedef enum _ORIENTATION_PREFERENCE
{
ORIENTATION_PREFERENCE_NONE = 0x0,
ORIENTATION_PREFERENCE_LANDSCAPE = 0x1,
ORIENTATION_PREFERENCE_PORTRAIT = 0x2,
ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4,
ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8
} ORIENTATION_PREFERENCE;
#pragma pack(pop)
#endif

View File

@ -22,6 +22,7 @@
#endif
#include <winpr/crt.h>
#include <winpr/user.h>
#include "clipboard.h"

View File

@ -28,13 +28,11 @@
/* String Manipulation (CRT): http://msdn.microsoft.com/en-us/library/f0151s4x.aspx */
#ifndef _WIN32
#include "casing.c"
#include "../log.h"
#define TAG WINPR_TAG("crt")
#ifndef _WIN32
char* _strdup(const char* strSource)
{
char* strDestination;
@ -153,10 +151,16 @@ WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context)
return nextToken;
}
#endif
#if !defined(_WIN32) || defined(_UWP)
/* Windows API Sets - api-ms-win-core-string-l2-1-0.dll
* http://msdn.microsoft.com/en-us/library/hh802935/
*/
#include "casing.c"
LPSTR CharUpperA(LPSTR lpsz)
{
int i;
@ -165,7 +169,7 @@ LPSTR CharUpperA(LPSTR lpsz)
if (!lpsz)
return NULL;
length = strlen(lpsz);
length = (int) strlen(lpsz);
if (length < 1)
return (LPSTR) NULL;
@ -198,7 +202,7 @@ LPWSTR CharUpperW(LPWSTR lpsz)
DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength)
{
int i;
DWORD i;
if (cchLength < 1)
return 0;
@ -232,7 +236,7 @@ LPSTR CharLowerA(LPSTR lpsz)
if (!lpsz)
return (LPSTR) NULL;
length = strlen(lpsz);
length = (int) strlen(lpsz);
if (length < 1)
return (LPSTR) NULL;
@ -265,7 +269,7 @@ LPWSTR CharLowerW(LPWSTR lpsz)
DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength)
{
int i;
DWORD i;
if (cchLength < 1)
return 0;
@ -350,7 +354,7 @@ BOOL IsCharLowerW(WCHAR ch)
int lstrlenA(LPCSTR lpString)
{
return strlen(lpString);
return (int) strlen(lpString);
}
int lstrlenW(LPCWSTR lpString)
@ -365,7 +369,7 @@ int lstrlenW(LPCWSTR lpString)
while (*p)
p++;
return p - lpString;
return (int) (p - lpString);
}
int lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
@ -409,7 +413,7 @@ int ConvertLineEndingToLF(char* str, int size)
}
}
status = pOutput - str;
status = (int) (pOutput - str);
return status;
}
@ -458,7 +462,7 @@ char* ConvertLineEndingToCRLF(const char* str, int* size)
pInput++;
}
*size = pOutput - newStr;
*size = (int) (pOutput - newStr);
return newStr;
}

View File

@ -289,7 +289,7 @@ int ConvertToUnicode(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
return 0;
if (cbMultiByte == -1)
cbMultiByte = strlen(lpMultiByteStr) + 1;
cbMultiByte = (int) (strlen(lpMultiByteStr) + 1);
if (cchWideChar == 0)
{
@ -335,7 +335,7 @@ int ConvertFromUnicode(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int
return 0;
if (cchWideChar == -1)
cchWideChar = _wcslen(lpWideCharStr) + 1;
cchWideChar = (int) (_wcslen(lpWideCharStr) + 1);
if (cbMultiByte == 0)
{

View File

@ -49,7 +49,7 @@ void winpr_RC4_Init(WINPR_RC4_CTX* ctx, const BYTE* key, size_t keylen)
RC4_set_key((RC4_KEY*) ctx, keylen, key);
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_ARC4_C)
mbedtls_arc4_init((mbedtls_arc4_context*) ctx);
mbedtls_arc4_setup((mbedtls_arc4_context*) ctx, key, keylen);
mbedtls_arc4_setup((mbedtls_arc4_context*) ctx, key, (unsigned int) keylen);
#endif
}

View File

@ -131,8 +131,13 @@ BOOL NeedCurrentDirectoryForExePathW(LPCWSTR ExeName)
return TRUE;
}
#endif
#if !defined(_WIN32) || defined(_UWP)
DWORD GetEnvironmentVariableA(LPCSTR lpName, LPSTR lpBuffer, DWORD nSize)
{
#if !defined(_UWP)
int length;
char* env = NULL;
@ -152,15 +157,21 @@ DWORD GetEnvironmentVariableA(LPCSTR lpName, LPSTR lpBuffer, DWORD nSize)
CopyMemory(lpBuffer, env, length + 1);
return length;
#else
SetLastError(ERROR_ENVVAR_NOT_FOUND);
return 0;
#endif
}
DWORD GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, DWORD nSize)
{
SetLastError(ERROR_ENVVAR_NOT_FOUND);
return 0;
}
BOOL SetEnvironmentVariableA(LPCSTR lpName, LPCSTR lpValue)
{
#if !defined(_UWP)
if (!lpName)
return FALSE;
@ -176,11 +187,14 @@ BOOL SetEnvironmentVariableA(LPCSTR lpName, LPCSTR lpValue)
}
return TRUE;
#else
return FALSE;
#endif
}
BOOL SetEnvironmentVariableW(LPCWSTR lpName, LPCWSTR lpValue)
{
return TRUE;
return FALSE;
}
/**
@ -201,8 +215,9 @@ BOOL SetEnvironmentVariableW(LPCWSTR lpName, LPCWSTR lpValue)
extern char** environ;
LPCH GetEnvironmentStrings(VOID)
LPCH GetEnvironmentStringsA(VOID)
{
#if !defined(_UWP)
char* p;
int offset;
int length;
@ -220,9 +235,9 @@ LPCH GetEnvironmentStrings(VOID)
while (*envp)
{
length = strlen(*envp);
length = (int) strlen(*envp);
while ((offset + length + 8) > cchEnvironmentBlock)
while ((offset + length + 8) > (int) cchEnvironmentBlock)
{
DWORD new_size;
LPCH new_blk;
@ -251,6 +266,9 @@ LPCH GetEnvironmentStrings(VOID)
lpszEnvironmentBlock[offset] = '\0';
return lpszEnvironmentBlock;
#else
return NULL;
#endif
}
LPWCH GetEnvironmentStringsW(VOID)
@ -320,7 +338,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
while (*cp && *(cp + 1))
{
length = strlen(cp);
length = (int) strlen(cp);
if (mergeStringLength == mergeArraySize)
{
@ -331,7 +349,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!new_str)
{
free(mergeStrings);
free((void*) mergeStrings);
return NULL;
}
mergeStrings = new_str;
@ -349,7 +367,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!lpszEnvironmentBlock)
{
free (mergeStrings);
free((void*) mergeStrings);
return NULL;
}
@ -358,9 +376,9 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
while ((original != NULL) && (*envp && *(envp+1)))
{
ULONG old_offset = offset;
length = strlen(envp);
length = (int) strlen(envp);
while ((offset + length + 8) > cchEnvironmentBlock)
while ((offset + length + 8) > (int) cchEnvironmentBlock)
{
LPCH tmp;
cchEnvironmentBlock *= 2;
@ -368,8 +386,8 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!tmp)
{
free (lpszEnvironmentBlock);
free (mergeStrings);
free((void*) lpszEnvironmentBlock);
free((void*) mergeStrings);
return NULL;
}
lpszEnvironmentBlock = tmp;
@ -384,7 +402,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!mergeStrings[run])
continue;
mergeLength = strlen(mergeStrings[run]);
mergeLength = (int) strlen(mergeStrings[run]);
foundEquals = strstr(mergeStrings[run], "=");
if (!foundEquals)
@ -400,7 +418,7 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
}
else
{
while ((offset + mergeLength + 8) > cchEnvironmentBlock)
while ((offset + mergeLength + 8) > (int) cchEnvironmentBlock)
{
LPCH tmp;
cchEnvironmentBlock *= 2;
@ -408,8 +426,8 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!tmp)
{
free(lpszEnvironmentBlock);
free (mergeStrings);
free((void*) lpszEnvironmentBlock);
free((void*) mergeStrings);
return NULL;
}
lpszEnvironmentBlock = tmp;
@ -441,9 +459,9 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!mergeStrings[run])
continue;
mergeLength = strlen(mergeStrings[run]);
mergeLength = (int) strlen(mergeStrings[run]);
while ((offset + mergeLength + 8) > cchEnvironmentBlock)
while ((offset + mergeLength + 8) > (int) cchEnvironmentBlock)
{
LPCH tmp;
cchEnvironmentBlock *= 2;
@ -451,8 +469,8 @@ LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge)
if (!tmp)
{
free(lpszEnvironmentBlock);
free (mergeStrings);
free((void*) lpszEnvironmentBlock);
free((void*) mergeStrings);
return NULL;
}
@ -485,14 +503,14 @@ DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer,
if (!lpName || NULL == envBlock)
return 0;
lpNameLength = strlen(lpName);
lpNameLength = (int) strlen(lpName);
if (lpNameLength < 1)
return 0;
while (*penvb && *(penvb + 1))
{
fLength = strlen(penvb);
fLength = (int) strlen(penvb);
foundEquals = strstr(penvb,"=");
if (!foundEquals)
@ -501,7 +519,7 @@ DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer,
return 0;
}
nLength = foundEquals - penvb;
nLength = (int) (foundEquals - penvb);
if (nLength != lpNameLength)
{
@ -521,9 +539,9 @@ DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer,
if (!env)
return 0;
vLength = strlen(env);
vLength = (int) strlen(env);
if ((vLength + 1 > nSize) || (!lpBuffer))
if ((vLength + 1 > (int) nSize) || (!lpBuffer))
return vLength + 1;
CopyMemory(lpBuffer, env, vLength + 1);
@ -542,7 +560,7 @@ BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue)
if (lpValue)
{
length = strlen(lpName) + strlen(lpValue) + 2; /* +2 because of = and \0 */
length = (int) (strlen(lpName) + strlen(lpValue) + 2); /* +2 because of = and \0 */
envstr = (char*) malloc(length + 1); /* +1 because of closing \0 */
if (!envstr)
@ -552,7 +570,7 @@ BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue)
}
else
{
length = strlen(lpName) + 2; /* +2 because of = and \0 */
length = (int) strlen(lpName) + 2; /* +2 because of = and \0 */
envstr = (char*) malloc(length + 1); /* +1 because of closing \0 */
if (!envstr)
@ -589,7 +607,7 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
while (p[0] && p[1])
{
length = strlen(p);
length = (int) strlen(p);
p += (length + 1);
count++;
}
@ -604,7 +622,7 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
while (p[0] && p[1])
{
length = strlen(p);
length = (int) strlen(p);
envp[index] = _strdup(p);
if (!envp[index])
{

View File

@ -64,6 +64,8 @@
* SizeofResource
*/
#if !defined(_WIN32) || defined(_UWP)
#ifndef _WIN32
#include <dlfcn.h>
@ -77,6 +79,8 @@
#include <mach-o/dyld.h>
#endif
#endif
DLL_DIRECTORY_COOKIE AddDllDirectory(PCWSTR NewDirectory)
{
return NULL;
@ -94,7 +98,27 @@ BOOL SetDefaultDllDirectories(DWORD DirectoryFlags)
HMODULE LoadLibraryA(LPCSTR lpLibFileName)
{
#if defined(_UWP)
int status;
HMODULE hModule = NULL;
WCHAR* filenameW = NULL;
if (!lpLibFileName)
return NULL;
status = ConvertToUnicode(CP_UTF8, 0, lpLibFileName, -1, &filenameW, 0);
if (status < 1)
return NULL;
hModule = LoadPackagedLibrary(filenameW, 0);
free(filenameW);
return hModule;
#else
HMODULE library;
library = dlopen(lpLibFileName, RTLD_LOCAL | RTLD_LAZY);
if (!library)
@ -104,16 +128,23 @@ HMODULE LoadLibraryA(LPCSTR lpLibFileName)
}
return library;
#endif
}
HMODULE LoadLibraryW(LPCWSTR lpLibFileName)
{
#if defined(_UWP)
return LoadPackagedLibrary(lpLibFileName, 0);
#else
return (HMODULE) NULL;
#endif
}
HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
#if !defined(_UWP)
HMODULE library;
library = dlopen(lpLibFileName, RTLD_LOCAL | RTLD_LAZY);
if (!library)
@ -123,6 +154,9 @@ HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
}
return library;
#else
return (HMODULE)NULL;
#endif
}
HMODULE LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
@ -130,6 +164,10 @@ HMODULE LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
return (HMODULE) NULL;
}
#endif
#ifndef _WIN32
FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
{
FARPROC proc;

View File

@ -42,7 +42,7 @@ VOID _InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes,
PUNICODE_STRING ObjectName, ULONG Attributes, HANDLE RootDirectory,
PSECURITY_DESCRIPTOR SecurityDescriptor)
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_UWP)
InitializeObjectAttributes(InitializedAttributes, ObjectName,
Attributes, RootDirectory, SecurityDescriptor);
#else

View File

@ -142,13 +142,12 @@ static char* GetPath_XDG_CONFIG_HOME(void)
{
char* path = NULL;
#if defined(WIN32)
#if defined(WIN32) && !defined(_UWP)
path = calloc(MAX_PATH, sizeof(char));
if (!path)
return NULL;
if (FAILED(SHGetFolderPathA(0, CSIDL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, path)))
if (FAILED(SHGetFolderPathA(0, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)))
{
free(path);
return NULL;
@ -240,13 +239,13 @@ static char* GetPath_XDG_CACHE_HOME(void)
char* GetPath_XDG_RUNTIME_DIR(void)
{
char* path = NULL;
#if defined(WIN32)
#if defined(WIN32) && !defined(_UWP)
path = calloc(MAX_PATH, sizeof(char));
if (!path)
return NULL;
if (FAILED(SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, path)))
if (FAILED(SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)))
{
free(path);
return NULL;
@ -389,9 +388,9 @@ char* GetCombinedPath(const char* basePath, const char* subPath)
int subPathLength = 0;
if (basePath)
basePathLength = strlen(basePath);
basePathLength = (int) strlen(basePath);
if (subPath)
subPathLength = strlen(subPath);
subPathLength = (int) strlen(subPath);
length = basePathLength + subPathLength + 1;
path = (char*) malloc(length + 1);

View File

@ -23,6 +23,7 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
#ifdef _WIN32

View File

@ -23,6 +23,7 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
#include "pool.h"

View File

@ -23,6 +23,7 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
#include "pool.h"

View File

@ -23,6 +23,7 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
#include "pool.h"

View File

@ -23,6 +23,7 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
#include "pool.h"

View File

@ -23,6 +23,7 @@
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
#include "pool.h"
#include "../log.h"

View File

@ -389,6 +389,15 @@ DWORD GetTickCount(void)
}
#endif // _WIN32
#if defined(_UWP)
DWORD GetTickCount(void)
{
return (DWORD) GetTickCount64();
}
#endif
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
ULONGLONG GetTickCount64(void)

View File

@ -113,7 +113,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
pArgs = NULL;
numArgs = 0;
lpEscapedCmdLine = NULL;
cmdLineLength = strlen(lpCmdLine);
cmdLineLength = (int) strlen(lpCmdLine);
lpEscapedChars = (BOOL*) calloc(1, (cmdLineLength + 1) * sizeof(BOOL));
if (!lpEscapedChars)
return NULL;
@ -138,7 +138,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
if (!pBeg)
{
length = strlen(p);
length = (int) strlen(p);
CopyMemory(pOutput, p, length);
pOutput += length;
p += length;
@ -158,8 +158,8 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
pBeg--;
}
n = (pEnd - pBeg) - 1;
length = (pBeg - pLastEnd);
n = (int) ((pEnd - pBeg) - 1);
length = (int) (pBeg - pLastEnd);
CopyMemory(pOutput, p, length);
pOutput += length;
p += length;
@ -178,7 +178,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
*pOutput++ = '\0';
lpCmdLine = (LPCSTR) lpEscapedCmdLine;
cmdLineLength = strlen(lpCmdLine);
cmdLineLength = (int) strlen(lpCmdLine);
}
maxNumArgs = 2;
@ -217,7 +217,7 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
if (*p != '"')
{
/* no whitespace escaped with double quotes */
length = p - pBeg;
length = (int) (p - pBeg);
CopyMemory(pOutput, pBeg, length);
pOutput[length] = '\0';
pArgs[numArgs++] = pOutput;

View File

@ -115,7 +115,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
sigil_index = 0;
sigil_length = 0;
sigil = (char*) &argv[i][sigil_index];
length = strlen(argv[i]);
length = (int) strlen(argv[i]);
if ((sigil[0] == '/') && (flags & COMMAND_LINE_SIGIL_SLASH))
{
@ -198,9 +198,9 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
if (separator)
{
separator_length = 1;
separator_index = (separator - argv[i]);
separator_index = (int) (separator - argv[i]);
keyword_length = (separator - keyword);
keyword_length = (int) (separator - keyword);
value_index = separator_index + separator_length;
value = (char*) &argv[i][value_index];
@ -278,7 +278,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
{
i++;
value_index = 0;
length = strlen(argv[i]);
length = (int) strlen(argv[i]);
value = (char*) &argv[i][value_index];
value_length = (length - value_index);

View File

@ -207,7 +207,7 @@ void ArrayList_Clear(wArrayList *arrayList)
BOOL ArrayList_Contains(wArrayList *arrayList, void *obj)
{
DWORD index;
int index;
BOOL rc = FALSE;
if (arrayList->synchronized)

View File

@ -260,7 +260,7 @@ int BipBuffer_Write(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(block, &data[status], writeSize);
BipBuffer_WriteCommit(bb, writeSize);
status += writeSize;
status += (int) writeSize;
if ((status == size) || (writeSize < blockSize))
return status;
@ -277,7 +277,7 @@ int BipBuffer_Write(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(block, &data[status], writeSize);
BipBuffer_WriteCommit(bb, writeSize);
status += writeSize;
status += (int) writeSize;
if ((status == size) || (writeSize < blockSize))
return status;
@ -370,7 +370,7 @@ int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(&data[status], block, readSize);
BipBuffer_ReadCommit(bb, readSize);
status += readSize;
status += (int) readSize;
if ((status == size) || (readSize < blockSize))
return status;
@ -387,7 +387,7 @@ int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(&data[status], block, readSize);
BipBuffer_ReadCommit(bb, readSize);
status += readSize;
status += (int) readSize;
if ((status == size) || (readSize < blockSize))
return status;

View File

@ -161,7 +161,7 @@ const char* BYTE_BIT_STRINGS_MSB[256] =
"00111111", "10111111", "01111111", "11111111"
};
void BitDump(const char* tag, int level, const BYTE* buffer, UINT32 length, UINT32 flags)
void BitDump(const char* tag, UINT32 level, const BYTE* buffer, UINT32 length, UINT32 flags)
{
DWORD i;
int nbits;

View File

@ -293,7 +293,7 @@ void* winpr_backtrace(DWORD size)
data->max = size;
data->used = fkt->unwind_backtrace(data->buffer, 0, size);
return data;
#elif defined(_WIN32) || defined(_WIN64)
#elif (defined(_WIN32) || defined(_WIN64)) && !defined(_UWP)
HANDLE process = GetCurrentProcess();
t_win_stack* data = calloc(1, sizeof(t_win_stack));
@ -390,7 +390,7 @@ char** winpr_backtrace_symbols(void* buffer, size_t* used)
return (char**) lines;
}
#elif defined(_WIN32) || defined(_WIN64)
#elif (defined(_WIN32) || defined(_WIN64)) && !defined(_UWP)
{
size_t i;
size_t line_len = 1024;
@ -509,15 +509,27 @@ void winpr_log_backtrace(const char* tag, DWORD level, DWORD size)
winpr_backtrace_free(stack);
}
char* winpr_strerror(DWORD dw, char* dmsg, size_t size) {
char* winpr_strerror(DWORD dw, char* dmsg, size_t size)
{
#if defined(_WIN32)
LPTSTR msg = NULL;
DWORD rc;
DWORD nSize = 0;
DWORD dwFlags = 0;
LPTSTR msg = NULL;
BOOL alloc = FALSE;
dwFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
#ifdef FORMAT_MESSAGE_ALLOCATE_BUFFER
alloc = TRUE;
dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER;
#else
nSize = (DWORD) (size * 2);
msg = (LPTSTR) calloc(nSize, sizeof(TCHAR));
#endif
rc = FormatMessage(dwFlags, NULL, dw, 0, alloc ? (LPTSTR) &msg : msg, nSize, NULL);
rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dw, 0, (LPTSTR)&msg, 0, NULL);
if (rc) {
#if defined(UNICODE)
WideCharToMultiByte(CP_ACP, 0, msg, rc, dmsg, size - 1, NULL, NULL);
@ -525,7 +537,12 @@ char* winpr_strerror(DWORD dw, char* dmsg, size_t size) {
memcpy(dmsg, msg, min(rc, size - 1));
#endif /* defined(UNICODE) */
dmsg[min(rc, size - 1)] = 0;
#ifdef FORMAT_MESSAGE_ALLOCATE_BUFFER
LocalFree(msg);
#else
free(msg);
#endif
} else {
_snprintf(dmsg, size, "FAILURE: %08X", GetLastError());
}

View File

@ -37,7 +37,7 @@ int IniFile_Load_String(wIniFile* ini, const char* iniString)
ini->nextLine = NULL;
ini->buffer = NULL;
fileSize = strlen(iniString);
fileSize = (long int) strlen(iniString);
if (fileSize < 1)
return -1;
@ -146,7 +146,7 @@ char* IniFile_Load_GetNextLine(wIniFile* ini)
ini->line = ini->nextLine;
ini->nextLine = strtok(NULL, "\n");
ini->lineLength = strlen(ini->line);
ini->lineLength = (int) strlen(ini->line);
return ini->line;
}
@ -459,7 +459,7 @@ char** IniFile_GetSectionNames(wIniFile* ini, int* count)
for (index = 0; index < ini->nSections; index++)
{
section = ini->sections[index];
nameLength = strlen(section->name);
nameLength = (int) strlen(section->name);
length += (nameLength + 1);
}
@ -473,7 +473,7 @@ char** IniFile_GetSectionNames(wIniFile* ini, int* count)
{
sectionNames[index] = p;
section = ini->sections[index];
nameLength = strlen(section->name);
nameLength = (int) strlen(section->name);
CopyMemory(p, section->name, nameLength + 1);
p += (nameLength + 1);
}
@ -505,7 +505,7 @@ char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count
for (index = 0; index < pSection->nKeys; index++)
{
pKey = pSection->keys[index];
nameLength = strlen(pKey->name);
nameLength = (int) strlen(pKey->name);
length += (nameLength + 1);
}
@ -519,7 +519,7 @@ char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count
{
keyNames[index] = p;
pKey = pSection->keys[index];
nameLength = strlen(pKey->name);
nameLength = (int) strlen(pKey->name);
CopyMemory(p, pKey->name, nameLength + 1);
p += (nameLength + 1);
}
@ -632,12 +632,12 @@ char* IniFile_WriteBuffer(wIniFile* ini)
for (i = 0; i < ini->nSections; i++)
{
section = ini->sections[i];
size += strlen(section->name) + 3;
size += (int) (strlen(section->name) + 3);
for (j = 0; j < section->nKeys; j++)
{
key = section->keys[j];
size += strlen(key->name) + strlen(key->value) + 2;
size += (int) (strlen(key->name) + strlen(key->value) + 2);
}
size += 1;
@ -656,13 +656,13 @@ char* IniFile_WriteBuffer(wIniFile* ini)
{
section = ini->sections[i];
sprintf_s(&buffer[offset], size - offset, "[%s]\n", section->name);
offset += strlen(section->name) + 3;
offset += (int) (strlen(section->name) + 3);
for (j = 0; j < section->nKeys; j++)
{
key = section->keys[j];
sprintf_s(&buffer[offset], size - offset, "%s=%s\n", key->name, key->value);
offset += strlen(key->name) + strlen(key->value) + 2;
offset += (int) (strlen(key->name) + strlen(key->value) + 2);
}
sprintf_s(&buffer[offset], size - offset, "\n");
@ -686,7 +686,7 @@ int IniFile_WriteFile(wIniFile* ini, const char* filename)
if (!buffer)
return -1;
length = strlen(buffer);
length = (int) strlen(buffer);
ini->readOnly = FALSE;

View File

@ -33,7 +33,7 @@
#include "../log.h"
void winpr_HexDump(const char* tag, int level, const BYTE* data, int length)
void winpr_HexDump(const char* tag, UINT32 level, const BYTE* data, int length)
{
const BYTE* p = data;
int i, line, offset = 0;
@ -74,7 +74,7 @@ void winpr_HexDump(const char* tag, int level, const BYTE* data, int length)
free(buffer);
}
void winpr_CArrayDump(const char* tag, int level, const BYTE* data, int length, int width)
void winpr_CArrayDump(const char* tag, UINT32 level, const BYTE* data, int length, int width)
{
const BYTE* p = data;
int i, line, offset = 0;

View File

@ -124,9 +124,9 @@ static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender,
if (!fp)
return FALSE;
FileNameLength = strlen(message->FileName);
FunctionNameLength = strlen(message->FunctionName);
TextStringLength = strlen(message->TextString);
FileNameLength = (int) strlen(message->FileName);
FunctionNameLength = (int) strlen(message->FunctionName);
TextStringLength = (int) strlen(message->TextString);
MessageLength = 16 +
(4 + FileNameLength + 1) +

View File

@ -60,7 +60,7 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
colonPos = strchr(udpAppender->host, ':');
if (!colonPos)
return FALSE;
addrLen = colonPos - udpAppender->host;
addrLen = (int) (colonPos - udpAppender->host);
memcpy(addressString, udpAppender->host, addrLen);
addressString[addrLen] = '\0';
@ -79,7 +79,7 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
}
memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen);
udpAppender->targetAddrLen = result->ai_addrlen;
udpAppender->targetAddrLen = (int) result->ai_addrlen;
return TRUE;
}

View File

@ -492,7 +492,7 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
while ((p = strchr(p, '.')) != NULL)
{
if (count < filter->NameCount)
if (count < (int) filter->NameCount)
filter->Names[count++] = p + 1;
*p = '\0';
p++;
@ -602,7 +602,7 @@ BOOL WLog_ParseName(wLog* log, LPCSTR name)
while ((p = strchr(p, '.')) != NULL)
{
if (count < log->NameCount)
if (count < (int) log->NameCount)
log->Names[count++] = p + 1;
*p = '\0';
p++;