diff --git a/channels/printer/client/cups/printer_cups.c b/channels/printer/client/cups/printer_cups.c index 56cbacecf..baa46e5d2 100644 --- a/channels/printer/client/cups/printer_cups.c +++ b/channels/printer/client/cups/printer_cups.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -92,7 +93,7 @@ static UINT printer_cups_write_printjob(rdpPrintJob* printjob, const BYTE* data, { FILE* fp; - fp = fopen((const char*)cups_printjob->printjob_object, "a+b"); + fp = winpr_fopen((const char*)cups_printjob->printjob_object, "a+b"); if (!fp) return ERROR_INTERNAL_ERROR; diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index 170ecb15b..80199683a 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -82,9 +82,9 @@ static char* get_printer_config_path(const rdpSettings* settings, const WCHAR* n char* bname = crypto_base64_encode((const BYTE*)name, (int)length); char* config = GetCombinedPath(dir, bname); - if (config && !PathFileExistsA(config)) + if (config && !winpr_PathFileExists(config)) { - if (!PathMakePathA(config, NULL)) + if (!winpr_PathMakePath(config, NULL)) { free(config); config = NULL; @@ -145,7 +145,7 @@ static BOOL printer_config_valid(const char* path) if (!path) return FALSE; - if (!PathFileExistsA(path)) + if (!winpr_PathFileExists(path)) return FALSE; return TRUE; @@ -261,7 +261,7 @@ static BOOL printer_remove_config(const rdpSettings* settings, const WCHAR* name if (!printer_config_valid(path)) goto fail; - rc = RemoveDirectoryA(path); + rc = winpr_RemoveDirectory(path); fail: free(path); return rc; @@ -275,7 +275,7 @@ static BOOL printer_move_config(const rdpSettings* settings, const WCHAR* oldNam char* newPath = get_printer_config_path(settings, newName, newLength); if (printer_config_valid(oldPath)) - rc = MoveFileA(oldPath, newPath); + rc = winpr_MoveFile(oldPath, newPath); free(oldPath); free(newPath); diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index 4b22edd38..e08048f88 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -1034,7 +1034,8 @@ static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard, if (!delayRespond) { - union { + union + { XEvent* ev; XSelectionEvent* sev; } conv; @@ -1614,7 +1615,8 @@ xf_cliprdr_server_format_data_response(CliprdrClientContext* context, xf_cliprdr_provide_data(clipboard, clipboard->respond, pDstData, DstSize); { - union { + union + { XEvent* ev; XSelectionEvent* sev; } conv; diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 4c05e80ae..26a1fd2e5 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -60,7 +60,7 @@ static BOOL xf_keyboard_action_script_init(xfContext* xfc) char* keyCombination; char buffer[1024] = { 0 }; char command[1024] = { 0 }; - xfc->actionScriptExists = PathFileExistsA(xfc->context.settings->ActionScript); + xfc->actionScriptExists = winpr_PathFileExists(xfc->context.settings->ActionScript); if (!xfc->actionScriptExists) return FALSE; diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 9610c07b8..6982eefe3 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -93,7 +93,7 @@ static BOOL freerdp_path_valid(const char* path, BOOL* special) ? TRUE : FALSE; if (!isSpecial) - isPath = PathFileExistsA(path); + isPath = winpr_PathFileExists(path); if (special) *special = isSpecial; @@ -151,9 +151,9 @@ static BOOL freerdp_client_add_drive(rdpSettings* settings, const char* path, co if (name) { /* Path was entered as secondary argument, swap */ - if (PathFileExistsA(name)) + if (winpr_PathFileExists(name)) { - if (!PathFileExistsA(path) || (!PathIsRelativeA(name) && PathIsRelativeA(path))) + if (!winpr_PathFileExists(path) || (!PathIsRelativeA(name) && PathIsRelativeA(path))) { const char* tmp = path; path = name; diff --git a/client/common/file.c b/client/common/file.c index 77679aec7..b56fe6f06 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -791,7 +793,7 @@ BOOL freerdp_client_parse_rdp_file_ex(rdpFile* file, const char* name, rdp_file_ FILE* fp = NULL; size_t read_size; INT64 file_size; - fp = fopen(name, "r"); + fp = winpr_fopen(name, "r"); if (!fp) { @@ -944,7 +946,7 @@ BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, BOOL u return FALSE; } - fp = fopen(name, "w+b"); + fp = winpr_fopen(name, "w+b"); if (fp) { diff --git a/client/common/test/TestClientRdpFile.c b/client/common/test/TestClientRdpFile.c index ca4a79499..f28fc0b9d 100644 --- a/client/common/test/TestClientRdpFile.c +++ b/client/common/test/TestClientRdpFile.c @@ -420,11 +420,11 @@ int TestClientRdpFile(int argc, char* argv[]) rc = 0; fail: if (utfname) - DeleteFileA(utfname); + winpr_DeleteFile(utfname); if (uniname) - DeleteFileA(uniname); + winpr_DeleteFile(uniname); if (base) - RemoveDirectoryA(base); + winpr_RemoveDirectory(base); free(utfname); free(uniname); free(base); diff --git a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c index 5621b8e3e..1348c07e3 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -278,7 +279,7 @@ static BYTE* test_progressive_load_file(const char* path, const char* file, size if (!filename) return NULL; - fp = fopen(filename, "r"); + fp = winpr_fopen(filename, "r"); free(filename); if (!fp) @@ -1142,7 +1143,7 @@ int TestFreeRDPCodecProgressive(int argc, char* argv[]) goto fail; } - if (PathFileExistsA(ms_sample_path)) + if (winpr_PathFileExists(ms_sample_path)) { /* if (test_progressive_ms_sample(ms_sample_path) < 0) diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index f5b5d621e..c136dbb67 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1177,7 +1178,7 @@ int freerdp_assistance_parse_file(rdpAssistanceFile* file, const char* name, con free(file->filename); file->filename = _strdup(name); - fp = fopen(name, "r"); + fp = winpr_fopen(name, "r"); if (!fp) { diff --git a/libfreerdp/core/certificate.c b/libfreerdp/core/certificate.c index acbcb63ef..b73678ec6 100644 --- a/libfreerdp/core/certificate.c +++ b/libfreerdp/core/certificate.c @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -789,7 +790,7 @@ rdpRsaKey* key_new(const char* keyfile) INT64 length; char* buffer = NULL; rdpRsaKey* key = NULL; - fp = fopen(keyfile, "rb"); + fp = winpr_fopen(keyfile, "rb"); if (!fp) { diff --git a/libfreerdp/core/license.c b/libfreerdp/core/license.c index 097107b70..dda76aaf9 100644 --- a/libfreerdp/core/license.c +++ b/libfreerdp/core/license.c @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -188,19 +189,21 @@ out: return ret; } -static BOOL saveCal(rdpSettings* settings, const BYTE* data, int length, char* hostname) +static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, const char* hostname) { char hash[41]; FILE* fp; char* licenseStorePath = NULL; char filename[MAX_PATH], filenameNew[MAX_PATH]; char *filepath = NULL, *filepathNew = NULL; + WCHAR* wFilepathNew = NULL; + WCHAR* wFilepath = NULL; size_t written; BOOL ret = FALSE; - if (!PathFileExistsA(settings->ConfigPath)) + if (!winpr_PathFileExists(settings->ConfigPath)) { - if (!PathMakePathA(settings->ConfigPath, 0)) + if (!winpr_PathMakePath(settings->ConfigPath, 0)) { WLog_ERR(TAG, "error creating directory '%s'", settings->ConfigPath); goto out; @@ -211,9 +214,9 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, int length, char* h if (!(licenseStorePath = GetCombinedPath(settings->ConfigPath, licenseStore))) goto out; - if (!PathFileExistsA(licenseStorePath)) + if (!winpr_PathFileExists(licenseStorePath)) { - if (!PathMakePathA(licenseStorePath, 0)) + if (!winpr_PathMakePath(licenseStorePath, 0)) { WLog_ERR(TAG, "error creating directory '%s'", licenseStorePath); goto out; @@ -231,8 +234,12 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, int length, char* h if (!(filepathNew = GetCombinedPath(licenseStorePath, filenameNew))) goto out; + if (ConvertToUnicode(CP_UTF8, 0, filepathNew, -1, &wFilepathNew, 0) <= 0) + goto out; + if (ConvertToUnicode(CP_UTF8, 0, filepath, -1, &wFilepath, 0) <= 0) + goto out; - fp = fopen(filepathNew, "wb"); + fp = winpr_fopen(filepathNew, "wb"); if (!fp) goto out; @@ -241,25 +248,28 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, int length, char* h if (written != 1) { - DeleteFile(filepathNew); + DeleteFileW(wFilepathNew); goto out; } - ret = MoveFileEx(filepathNew, filepath, MOVEFILE_REPLACE_EXISTING); + ret = MoveFileExW(wFilepathNew, wFilepath, MOVEFILE_REPLACE_EXISTING); out: + free(wFilepathNew); free(filepathNew); + free(wFilepath); free(filepath); free(licenseStorePath); return ret; } -static BYTE* loadCalFile(rdpSettings* settings, const char* hostname, int* dataLen) +static BYTE* loadCalFile(rdpSettings* settings, const char* hostname, size_t* dataLen) { char *licenseStorePath = NULL, *calPath = NULL; char calFilename[MAX_PATH]; char hash[41]; - int length, status; + size_t length; + int status; FILE* fp; BYTE* ret = NULL; @@ -277,7 +287,7 @@ static BYTE* loadCalFile(rdpSettings* settings, const char* hostname, int* dataL if (!(calPath = GetCombinedPath(licenseStorePath, calFilename))) goto error_path; - fp = fopen(calPath, "rb"); + fp = winpr_fopen(calPath, "rb"); if (!fp) goto error_open; @@ -683,9 +693,14 @@ BOOL license_encrypt_premaster_secret(rdpLicense* license) license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB; license->EncryptedPremasterSecret->length = PREMASTER_SECRET_LENGTH; #ifndef LICENSE_NULL_PREMASTER_SECRET - license->EncryptedPremasterSecret->length = crypto_rsa_public_encrypt( - license->PremasterSecret, PREMASTER_SECRET_LENGTH, license->ModulusLength, license->Modulus, - license->Exponent, EncryptedPremasterSecret); + { + SSIZE_T length = crypto_rsa_public_encrypt( + license->PremasterSecret, PREMASTER_SECRET_LENGTH, license->ModulusLength, + license->Modulus, license->Exponent, EncryptedPremasterSecret); + if ((length < 0) || (length > UINT16_MAX)) + return FALSE; + license->EncryptedPremasterSecret->length = (UINT16)length; + } #endif license->EncryptedPremasterSecret->data = EncryptedPremasterSecret; return TRUE; @@ -1417,7 +1432,7 @@ BOOL license_answer_license_request(rdpLicense* license) { wStream* s; BYTE* license_data = NULL; - int license_size = 0; + size_t license_size = 0; BOOL status; char* username; diff --git a/libfreerdp/core/test/TestConnect.c b/libfreerdp/core/test/TestConnect.c index 7bf196951..ae46eeddd 100644 --- a/libfreerdp/core/test/TestConnect.c +++ b/libfreerdp/core/test/TestConnect.c @@ -194,7 +194,7 @@ static int testSuccess(int port) printf("Sample Server: %s\n", exe); printf("Workspace: %s\n", wpath); - if (!PathFileExistsA(exe)) + if (!winpr_PathFileExists(exe)) goto fail; // Start sample server locally. diff --git a/libfreerdp/crypto/test/TestKnownHosts.c b/libfreerdp/crypto/test/TestKnownHosts.c index 68c5c0e59..19a0a94ce 100644 --- a/libfreerdp/crypto/test/TestKnownHosts.c +++ b/libfreerdp/crypto/test/TestKnownHosts.c @@ -34,12 +34,12 @@ static int prepare(const char* currentFileV2, const char* legacyFileV2, const ch FILE* fl = NULL; FILE* fc = NULL; size_t i; - fc = fopen(currentFileV2, "w+"); + fc = winpr_fopen(currentFileV2, "w+"); if (!fc) goto finish; - fl = fopen(legacyFileV2, "w+"); + fl = winpr_fopen(legacyFileV2, "w+"); if (!fl) goto finish; @@ -55,7 +55,7 @@ static int prepare(const char* currentFileV2, const char* legacyFileV2, const ch fc = NULL; fclose(fl); fl = NULL; - fl = fopen(legacyFile, "w+"); + fl = winpr_fopen(legacyFile, "w+"); if (!fl) goto finish; diff --git a/libfreerdp/crypto/test/Test_x509_cert_info.c b/libfreerdp/crypto/test/Test_x509_cert_info.c index 35e679099..3089bc829 100644 --- a/libfreerdp/crypto/test/Test_x509_cert_info.c +++ b/libfreerdp/crypto/test/Test_x509_cert_info.c @@ -1,3 +1,4 @@ +#include #include typedef char* (*get_field_pr)(X509*); @@ -87,7 +88,7 @@ static int TestCertificateFile(const char* certificate_path, const certificate_test_t* certificate_tests, int count) { X509* certificate; - FILE* certificate_file = fopen(certificate_path, "r"); + FILE* certificate_file = winpr_fopen(certificate_path, "r"); int success = 0; int i; diff --git a/libfreerdp/utils/pcap.c b/libfreerdp/utils/pcap.c index 923391023..520f49e22 100644 --- a/libfreerdp/utils/pcap.c +++ b/libfreerdp/utils/pcap.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -177,7 +178,7 @@ rdpPcap* pcap_open(char* name, BOOL write) pcap->name = name; pcap->write = write; pcap->record_count = 0; - pcap->fp = fopen(name, write ? "w+b" : "rb"); + pcap->fp = winpr_fopen(name, write ? "w+b" : "rb"); if (pcap->fp == NULL) goto fail; diff --git a/rdtk/librdtk/rdtk_font.c b/rdtk/librdtk/rdtk_font.c index 32325fa5f..f248d8e5c 100644 --- a/rdtk/librdtk/rdtk_font.c +++ b/rdtk/librdtk/rdtk_font.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "rdtk_engine.h" @@ -154,7 +155,7 @@ static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize) FILE* fp = NULL; size_t readSize; size_t fileSize; - fp = fopen(filename, "r"); + fp = winpr_fopen(filename, "r"); if (!fp) return NULL; @@ -611,10 +612,10 @@ rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file) sprintf_s(fontDescriptorFile, length + 8, "%s.xml", fontBaseFile); - if (!PathFileExistsA(fontImageFile)) + if (!winpr_PathFileExists(fontImageFile)) goto cleanup; - if (!PathFileExistsA(fontDescriptorFile)) + if (!winpr_PathFileExists(fontDescriptorFile)) goto cleanup; font = (rdtkFont*)calloc(1, sizeof(rdtkFont)); diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index bb9cc2de6..1328509b4 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -254,7 +255,7 @@ static BOOL test_peer_load_icon(freerdp_peer* client) return FALSE; } - if ((fp = fopen("test_icon.ppm", "r")) == NULL) + if ((fp = winpr_fopen("test_icon.ppm", "r")) == NULL) { WLog_ERR(TAG, "Unable to open test icon"); return FALSE; diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index 4a8aab156..e6a67b15d 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -140,7 +140,7 @@ static BOOL x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info) const char* hint = hints[x]; _snprintf(path, sizeof(path), "%s/%s", base, hint); - if (PathFileExistsA(path)) + if (winpr_PathFileExists(path)) { info->service_name = _strdup(hint); diff --git a/server/shadow/shadow_server.c b/server/shadow/shadow_server.c index 259f22ecd..649724206 100644 --- a/server/shadow/shadow_server.c +++ b/server/shadow/shadow_server.c @@ -680,7 +680,7 @@ static int shadow_server_init_config_path(rdpShadowServer* server) if (userLibraryPath) { - if (!PathFileExistsA(userLibraryPath) && !PathMakePathA(userLibraryPath, 0)) + if (!winpr_PathFileExists(userLibraryPath) && !winpr_PathMakePath(userLibraryPath, 0)) { WLog_ERR(TAG, "Failed to create directory '%s'", userLibraryPath); free(userLibraryPath); @@ -691,8 +691,8 @@ static int shadow_server_init_config_path(rdpShadowServer* server) if (userApplicationSupportPath) { - if (!PathFileExistsA(userApplicationSupportPath) && - !PathMakePathA(userApplicationSupportPath, 0)) + if (!winpr_PathFileExists(userApplicationSupportPath) && + !winpr_PathMakePath(userApplicationSupportPath, 0)) { WLog_ERR(TAG, "Failed to create directory '%s'", userApplicationSupportPath); free(userLibraryPath); @@ -717,7 +717,7 @@ static int shadow_server_init_config_path(rdpShadowServer* server) if (configHome) { - if (!PathFileExistsA(configHome) && !PathMakePathA(configHome, 0)) + if (!winpr_PathFileExists(configHome) && !winpr_PathMakePath(configHome, 0)) { WLog_ERR(TAG, "Failed to create directory '%s'", configHome); free(configHome); @@ -743,7 +743,7 @@ static BOOL shadow_server_init_certificate(rdpShadowServer* server) const char* makecert_argv[6] = { "makecert", "-rdp", "-live", "-silent", "-y", "5" }; int makecert_argc = (sizeof(makecert_argv) / sizeof(char*)); - if (!PathFileExistsA(server->ConfigPath) && !PathMakePathA(server->ConfigPath, 0)) + if (!winpr_PathFileExists(server->ConfigPath) && !winpr_PathMakePath(server->ConfigPath, 0)) { WLog_ERR(TAG, "Failed to create directory '%s'", server->ConfigPath); return FALSE; @@ -752,7 +752,7 @@ static BOOL shadow_server_init_certificate(rdpShadowServer* server) if (!(filepath = GetCombinedPath(server->ConfigPath, "shadow"))) return FALSE; - if (!PathFileExistsA(filepath) && !PathMakePathA(filepath, 0)) + if (!winpr_PathFileExists(filepath) && !winpr_PathMakePath(filepath, 0)) { if (!CreateDirectoryA(filepath, 0)) { @@ -767,7 +767,8 @@ static BOOL shadow_server_init_certificate(rdpShadowServer* server) if (!server->CertificateFile || !server->PrivateKeyFile) goto out_fail; - if ((!PathFileExistsA(server->CertificateFile)) || (!PathFileExistsA(server->PrivateKeyFile))) + if ((!winpr_PathFileExists(server->CertificateFile)) || + (!winpr_PathFileExists(server->PrivateKeyFile))) { makecert = makecert_context_new(); @@ -780,13 +781,13 @@ static BOOL shadow_server_init_certificate(rdpShadowServer* server) if (makecert_context_set_output_file_name(makecert, "shadow") != 1) goto out_fail; - if (!PathFileExistsA(server->CertificateFile)) + if (!winpr_PathFileExists(server->CertificateFile)) { if (makecert_context_output_certificate_file(makecert, filepath) != 1) goto out_fail; } - if (!PathFileExistsA(server->PrivateKeyFile)) + if (!winpr_PathFileExists(server->PrivateKeyFile)) { if (makecert_context_output_private_key_file(makecert, filepath) != 1) goto out_fail; diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 06a03783e..670387b89 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -766,7 +766,7 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw } } - fp = fopen(pFile->lpFileName, "ab"); + fp = winpr_fopen(pFile->lpFileName, "ab"); if (!fp) { SetLastError(map_posix_err(errno)); @@ -800,7 +800,7 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw } if (NULL == fp) - fp = fopen(pFile->lpFileName, mode); + fp = winpr_fopen(pFile->lpFileName, mode); pFile->fp = fp; if (!pFile->fp) diff --git a/winpr/libwinpr/file/test/TestFileCreateFile.c b/winpr/libwinpr/file/test/TestFileCreateFile.c index e6656a9cc..493a07534 100644 --- a/winpr/libwinpr/file/test/TestFileCreateFile.c +++ b/winpr/libwinpr/file/test/TestFileCreateFile.c @@ -45,7 +45,7 @@ int TestFileCreateFile(int argc, char* argv[]) return -1; } - if (!PathFileExistsA(name)) + if (!winpr_PathFileExists(name)) rc = -1; if (!WriteFile(handle, buffer, sizeof(buffer), &written, NULL)) @@ -81,10 +81,10 @@ int TestFileCreateFile(int argc, char* argv[]) if (!CloseHandle(handle)) rc = -1; - if (!DeleteFileA(name)) + if (!winpr_DeleteFile(name)) rc = -1; - if (PathFileExistsA(name)) + if (winpr_PathFileExists(name)) rc = -1; free(name); diff --git a/winpr/libwinpr/io/device.c b/winpr/libwinpr/io/device.c index e333c4544..c4db5187d 100644 --- a/winpr/libwinpr/io/device.c +++ b/winpr/libwinpr/io/device.c @@ -135,7 +135,7 @@ NTSTATUS _IoCreateDeviceEx(PDRIVER_OBJECT_EX DriverObject, ULONG DeviceExtension if (!DeviceBasePath) return STATUS_NO_MEMORY; - if (!PathFileExistsA(DeviceBasePath)) + if (!winpr_PathFileExists(DeviceBasePath)) { if (mkdir(DeviceBasePath, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { @@ -169,7 +169,7 @@ NTSTATUS _IoCreateDeviceEx(PDRIVER_OBJECT_EX DriverObject, ULONG DeviceExtension return STATUS_NO_MEMORY; } - if (PathFileExistsA(pDeviceObjectEx->DeviceFileName)) + if (winpr_PathFileExists(pDeviceObjectEx->DeviceFileName)) { if (unlink(pDeviceObjectEx->DeviceFileName) == -1) { diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index 8d9906e83..4bba4eca0 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -221,7 +221,7 @@ static char* GetPath_XDG_CACHE_HOME(void) { path = GetCombinedPath(home, "cache"); - if (!PathFileExistsA(path)) + if (!winpr_PathFileExists(path)) if (!CreateDirectoryA(path, NULL)) path = NULL; } @@ -567,7 +567,7 @@ BOOL PathFileExistsW(LPCWSTR pszPath) if (ConvertFromUnicode(CP_UTF8, 0, pszPath, -1, &lpFileNameA, 0, NULL, NULL) < 1) return FALSE; - ret = PathFileExistsA(lpFileNameA); + ret = winpr_PathFileExists(lpFileNameA); free(lpFileNameA); return ret; } diff --git a/winpr/libwinpr/path/test/TestPathMakePath.c b/winpr/libwinpr/path/test/TestPathMakePath.c index a82e10e4f..39b480777 100644 --- a/winpr/libwinpr/path/test/TestPathMakePath.c +++ b/winpr/libwinpr/path/test/TestPathMakePath.c @@ -42,7 +42,7 @@ int TestPathMakePath(int argc, char* argv[]) } printf("Creating path %s\n", path); - success = PathMakePathA(path, NULL); + success = winpr_PathMakePath(path, NULL); if (!success) { @@ -51,7 +51,7 @@ int TestPathMakePath(int argc, char* argv[]) return -1; } - success = PathFileExistsA(path); + success = winpr_PathFileExists(path); if (!success) { @@ -62,9 +62,9 @@ int TestPathMakePath(int argc, char* argv[]) while (strlen(path) > baseLen) { - if (!RemoveDirectoryA(path)) + if (!winpr_RemoveDirectory(path)) { - fprintf(stderr, "RemoveDirectoryA %s failed!\n", path); + fprintf(stderr, "winpr_RemoveDirectory %s failed!\n", path); free(path); return -1; } diff --git a/winpr/libwinpr/pipe/pipe.c b/winpr/libwinpr/pipe/pipe.c index 9e3f61978..147f42e69 100644 --- a/winpr/libwinpr/pipe/pipe.c +++ b/winpr/libwinpr/pipe/pipe.c @@ -630,7 +630,7 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD if (!(lpPipePath = GetNamedPipeUnixDomainSocketBaseFilePathA())) goto out; - if (!PathFileExistsA(lpPipePath)) + if (!winpr_PathFileExists(lpPipePath)) { if (!CreateDirectoryA(lpPipePath, 0)) { @@ -643,8 +643,8 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD free(lpPipePath); - if (PathFileExistsA(pNamedPipe->lpFilePath)) - DeleteFileA(pNamedPipe->lpFilePath); + if (winpr_PathFileExists(pNamedPipe->lpFilePath)) + winpr_DeleteFile(pNamedPipe->lpFilePath); if ((serverfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { @@ -836,7 +836,7 @@ BOOL WaitNamedPipeA(LPCSTR lpNamedPipeName, DWORD nTimeOut) status = TRUE; dwSleepInterval = 10; - while (!PathFileExistsA(lpFilePath)) + while (!winpr_PathFileExists(lpFilePath)) { Sleep(dwSleepInterval); nWaitTime += dwSleepInterval; diff --git a/winpr/libwinpr/registry/registry_reg.c b/winpr/libwinpr/registry/registry_reg.c index 4a1fd10c5..353e490c1 100644 --- a/winpr/libwinpr/registry/registry_reg.c +++ b/winpr/libwinpr/registry/registry_reg.c @@ -28,6 +28,7 @@ #include #include +#include #include "registry_reg.h" @@ -414,14 +415,14 @@ Reg* reg_open(BOOL read_only) if (reg->read_only) { - reg->fp = fopen(reg->filename, "r"); + reg->fp = winpr_fopen(reg->filename, "r"); } else { - reg->fp = fopen(reg->filename, "r+"); + reg->fp = winpr_fopen(reg->filename, "r+"); if (!reg->fp) - reg->fp = fopen(reg->filename, "w+"); + reg->fp = winpr_fopen(reg->filename, "w+"); } if (!reg->fp) diff --git a/winpr/libwinpr/sspi/test/TestSchannel.c b/winpr/libwinpr/sspi/test/TestSchannel.c index b7ead9c2a..047fa7b82 100644 --- a/winpr/libwinpr/sspi/test/TestSchannel.c +++ b/winpr/libwinpr/sspi/test/TestSchannel.c @@ -562,7 +562,7 @@ static int dump_test_certificate_files(void) if (!fullpath) return -1; - fp = fopen(fullpath, "w+"); + fp = winpr_fopen(fullpath, "w+"); if (fp) { if (fwrite((void*)test_localhost_crt, sizeof(test_localhost_crt), 1, fp) != 1) @@ -578,7 +578,7 @@ static int dump_test_certificate_files(void) fullpath = GetCombinedPath("/tmp", "localhost.key"); if (!fullpath) return -1; - fp = fopen(fullpath, "w+"); + fp = winpr_fopen(fullpath, "w+"); if (fp && fwrite((void*)test_localhost_key, sizeof(test_localhost_key), 1, fp) != 1) goto out_fail; diff --git a/winpr/libwinpr/thread/process.c b/winpr/libwinpr/thread/process.c index 317ac7ab7..ec02d1405 100644 --- a/winpr/libwinpr/thread/process.c +++ b/winpr/libwinpr/thread/process.c @@ -126,7 +126,7 @@ static char* FindApplicationPath(char* application) { filename = GetCombinedPath(path, application); - if (PathFileExistsA(filename)) + if (winpr_PathFileExists(filename)) { break; } diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index d8e33e019..a2c8a48c0 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "../log.h" #define TAG WINPR_TAG("timezone") @@ -230,9 +231,9 @@ static char* winpr_get_unix_timezone_identifier_from_file(void) FILE* fp; char* tzid = NULL; #if defined(__FreeBSD__) || defined(__OpenBSD__) - fp = fopen("/var/db/zoneinfo", "r"); + fp = winpr_fopen("/var/db/zoneinfo", "r"); #else - fp = fopen("/etc/timezone", "r"); + fp = winpr_fopen("/etc/timezone", "r"); #endif if (NULL == fp) diff --git a/winpr/libwinpr/utils/image.c b/winpr/libwinpr/utils/image.c index 78f1c38c3..8d304e115 100644 --- a/winpr/libwinpr/utils/image.c +++ b/winpr/libwinpr/utils/image.c @@ -154,7 +154,7 @@ int winpr_bitmap_write(const char* filename, const BYTE* data, int width, int he UINT32 img_size = width * height * (bpp / 8); int ret = -1; - fp = fopen(filename, "w+b"); + fp = winpr_fopen(filename, "w+b"); if (!fp) { diff --git a/winpr/libwinpr/utils/lodepng/lodepng.c b/winpr/libwinpr/utils/lodepng/lodepng.c index 89878e074..2dd526a2c 100644 --- a/winpr/libwinpr/utils/lodepng/lodepng.c +++ b/winpr/libwinpr/utils/lodepng/lodepng.c @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "lodepng.h" #include +#include #include #include @@ -367,7 +368,7 @@ unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* fil *out = 0; *outsize = 0; - file = fopen(filename, "rb"); + file = winpr_fopen(filename, "rb"); if (!file) return 78; @@ -397,7 +398,7 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const { FILE* file; int ret = 0; - file = fopen(filename, "wb"); + file = winpr_fopen(filename, "wb"); if (!file) return 79; if (fwrite((char*)buffer, 1, buffersize, file) != buffersize) diff --git a/winpr/libwinpr/utils/sam.c b/winpr/libwinpr/utils/sam.c index 5c0cfe93e..094475fe9 100644 --- a/winpr/libwinpr/utils/sam.c +++ b/winpr/libwinpr/utils/sam.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "../log.h" @@ -89,13 +90,13 @@ WINPR_SAM* SamOpen(const char* filename, BOOL readOnly) filename = WINPR_SAM_FILE; if (readOnly) - fp = fopen(filename, "r"); + fp = winpr_fopen(filename, "r"); else { - fp = fopen(filename, "r+"); + fp = winpr_fopen(filename, "r+"); if (!fp) - fp = fopen(filename, "w+"); + fp = winpr_fopen(filename, "w+"); } if (fp) diff --git a/winpr/libwinpr/utils/test/TestImage.c b/winpr/libwinpr/utils/test/TestImage.c index e606641ce..bad7fba22 100644 --- a/winpr/libwinpr/utils/test/TestImage.c +++ b/winpr/libwinpr/utils/test/TestImage.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -14,7 +15,7 @@ static void* read_image(const char* src, size_t* size) int success = 0; void* a = NULL; INT64 src_size; - FILE* fsrc = fopen(src, "rb"); + FILE* fsrc = winpr_fopen(src, "rb"); if (!fsrc) { @@ -155,7 +156,7 @@ static int create_test(const char* src, const char* dst_png, const char* dst_bmp void* buffer = NULL; wImage *image = NULL, *image2 = NULL, *image3 = NULL, *image4 = NULL; - if (!PathFileExistsA(src)) + if (!winpr_PathFileExists(src)) { fprintf(stderr, "File %s does not exist!", src); return -1; diff --git a/winpr/libwinpr/utils/test/TestWLog.c b/winpr/libwinpr/utils/test/TestWLog.c index bd2d3c608..28b2fcf65 100644 --- a/winpr/libwinpr/utils/test/TestWLog.c +++ b/winpr/libwinpr/utils/test/TestWLog.c @@ -55,7 +55,7 @@ int TestWLog(int argc, char* argv[]) WLog_CloseAppender(root); if ((wlog_file = GetCombinedPath(tmp_path, "test_w.log"))) - DeleteFileA(wlog_file); + winpr_DeleteFile(wlog_file); result = 0; out: diff --git a/winpr/tools/makecert/makecert.c b/winpr/tools/makecert/makecert.c index 2f2300524..769335f1b 100644 --- a/winpr/tools/makecert/makecert.c +++ b/winpr/tools/makecert/makecert.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef WITH_OPENSSL #include @@ -474,7 +475,7 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa if (!fullpath) goto out_fail; - fp = fopen(fullpath, "w+"); + fp = winpr_fopen(fullpath, "w+"); if (fp) { @@ -632,7 +633,7 @@ int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* pa if (!fullpath) goto out_fail; - fp = fopen(fullpath, "w+"); + fp = winpr_fopen(fullpath, "w+"); if (!fp) goto out_fail; @@ -1052,7 +1053,7 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv) if (!context->live) { - if (!PathFileExistsA(context->output_path)) + if (!winpr_PathFileExists(context->output_path)) { if (!CreateDirectoryA(context->output_path, NULL)) return -1;