From d3aa30455697084af654c23c0f62676c52634540 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 18 Jun 2023 15:35:21 +0200 Subject: [PATCH] Fix MSW and OSX kiplatform io libs Takes fixes from master branch. Includes ff072feeb4acdbec7af12010de635596e0ee6292 --- libs/kiplatform/msw/io.cpp | 17 ++++++++++++----- libs/kiplatform/osx/io.mm | 10 +++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libs/kiplatform/msw/io.cpp b/libs/kiplatform/msw/io.cpp index 4ec06b2161..c0554651db 100644 --- a/libs/kiplatform/msw/io.cpp +++ b/libs/kiplatform/msw/io.cpp @@ -73,20 +73,27 @@ FILE* KIPLATFORM::IO::SeqFOpen( const wxString& aPath, const wxString& aMode ) bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString &aDest ) { bool retval = false; - PSECURITY_DESCRIPTOR pSD = nullptr; DWORD dwSize = 0; // Retrieve the security descriptor from the source file - if( GetFileSecurity( sourceFilePath.wc_str(), + if( GetFileSecurity( aSrc.wc_str(), OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, NULL, 0, &dwSize ) ) { - pSD = static_cast( new BYTE[dwSize] ); + #ifdef __MINGW32__ + // pSD is used as PSECURITY_DESCRIPTOR, aka void* pointer + // it create an annoying warning on gcc with "delete[] pSD;" : + // "warning: deleting 'PSECURITY_DESCRIPTOR' {aka 'void*'} is undefined" + // so use a BYTE* pointer (do not cast it to a void pointer) + BYTE* pSD = new BYTE[dwSize]; + #else + PSECURITY_DESCRIPTOR pSD = static_cast( new BYTE[dwSize] ); + #endif if( !pSD ) return false; - if( !GetFileSecurity( sourceFilePath.wc_str(), + if( !GetFileSecurity( aSrc.wc_str(), OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, pSD, dwSize, &dwSize ) ) { @@ -95,7 +102,7 @@ bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString } // Assign the retrieved security descriptor to the destination file - if( !SetFileSecurity( destFilePath.wc_str(), + if( !SetFileSecurity( aDest.wc_str(), OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, pSD ) ) { diff --git a/libs/kiplatform/osx/io.mm b/libs/kiplatform/osx/io.mm index 3e24ade364..41dac282a7 100644 --- a/libs/kiplatform/osx/io.mm +++ b/libs/kiplatform/osx/io.mm @@ -29,7 +29,7 @@ FILE* KIPLATFORM::IO::SeqFOpen( const wxString& aPath, const wxString& aMode ) return wxFopen( aPath, aMode ); } -bool AssignPermissions(const wxString& sourceFilePath, const wxString& destFilePath) +bool KIPLATFORM::IO::DuplicatePermissions(const wxString& sourceFilePath, const wxString& destFilePath) { NSString *sourcePath = [NSString stringWithUTF8String:sourceFilePath.utf8_str()]; NSString *destPath = [NSString stringWithUTF8String:destFilePath.utf8_str()]; @@ -47,16 +47,16 @@ bool AssignPermissions(const wxString& sourceFilePath, const wxString& destFileP NSNumber *permissions = sourceAttributes[NSFilePosixPermissions]; - if (permissions == nil) + if (permissions == nil) { return false; } - if ([fileManager setAttributes:@{NSFilePosixPermissions: permissions} ofItemAtPath:destPath error:&error]) + if ([fileManager setAttributes:@{NSFilePosixPermissions: permissions} ofItemAtPath:destPath error:&error]) { return true; - } - else + } + else { NSLog(@"Error assigning permissions: %@", error); return false;