[2/2] os_support: Use HAVE_UWP instead of manually checking WINAPI_FAMILY

Message ID 1499247742-20813-2-git-send-email-martin@martin.st
State Committed
Commit 4d330da006fe48178a4c8047f06270925eaedf63
Headers show

Commit Message

Martin Storsjö July 5, 2017, 9:42 a.m.
---
 libavformat/os_support.h | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

Comments

wm4 July 5, 2017, 10:15 a.m. | #1
On Wed,  5 Jul 2017 12:42:22 +0300
Martin Storsjö <martin@martin.st> wrote:

> ---
>  libavformat/os_support.h | 14 +-------------
>  1 file changed, 1 insertion(+), 13 deletions(-)
> 
> diff --git a/libavformat/os_support.h b/libavformat/os_support.h
> index 965e16f..55c2fdb 100644
> --- a/libavformat/os_support.h
> +++ b/libavformat/os_support.h
> @@ -129,18 +129,6 @@ int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout);
>  #include <windows.h>
>  #include "libavutil/wchar_filename.h"
>  
> -#ifdef WINAPI_FAMILY
> -#include <winapifamily.h>
> -// If a WINAPI_FAMILY is defined, check that the desktop API subset
> -// is enabled
> -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> -#define USE_MOVEFILEEXA
> -#endif
> -#else
> -// If no WINAPI_FAMILY is defined, assume the full API subset
> -#define USE_MOVEFILEEXA
> -#endif
> -
>  #define DEF_FS_FUNCTION(name, wfunc, afunc)               \
>  static inline int win32_##name(const char *filename_utf8) \
>  {                                                         \
> @@ -192,7 +180,7 @@ static inline int win32_rename(const char *src_utf8, const char *dest_utf8)
>  
>  fallback:
>      /* filename may be be in CP_ACP */
> -#ifdef USE_MOVEFILEEXA
> +#if !HAVE_UWP
>      ret = MoveFileExA(src_utf8, dest_utf8, MOVEFILE_REPLACE_EXISTING);
>      if (ret)
>          errno = EPERM;

OK. (Do we really need those ACP hacks? They're ridiculous.)
Hendrik Leppkes July 5, 2017, 10:18 a.m. | #2
On Wed, Jul 5, 2017 at 12:15 PM, wm4 <nfxjfg@googlemail.com> wrote:
> On Wed,  5 Jul 2017 12:42:22 +0300
> Martin Storsjö <martin@martin.st> wrote:
>
>> ---
>>  libavformat/os_support.h | 14 +-------------
>>  1 file changed, 1 insertion(+), 13 deletions(-)
>>
>> diff --git a/libavformat/os_support.h b/libavformat/os_support.h
>> index 965e16f..55c2fdb 100644
>> --- a/libavformat/os_support.h
>> +++ b/libavformat/os_support.h
>> @@ -129,18 +129,6 @@ int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout);
>>  #include <windows.h>
>>  #include "libavutil/wchar_filename.h"
>>
>> -#ifdef WINAPI_FAMILY
>> -#include <winapifamily.h>
>> -// If a WINAPI_FAMILY is defined, check that the desktop API subset
>> -// is enabled
>> -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
>> -#define USE_MOVEFILEEXA
>> -#endif
>> -#else
>> -// If no WINAPI_FAMILY is defined, assume the full API subset
>> -#define USE_MOVEFILEEXA
>> -#endif
>> -
>>  #define DEF_FS_FUNCTION(name, wfunc, afunc)               \
>>  static inline int win32_##name(const char *filename_utf8) \
>>  {                                                         \
>> @@ -192,7 +180,7 @@ static inline int win32_rename(const char *src_utf8, const char *dest_utf8)
>>
>>  fallback:
>>      /* filename may be be in CP_ACP */
>> -#ifdef USE_MOVEFILEEXA
>> +#if !HAVE_UWP
>>      ret = MoveFileExA(src_utf8, dest_utf8, MOVEFILE_REPLACE_EXISTING);
>>      if (ret)
>>          errno = EPERM;
>
> OK. (Do we really need those ACP hacks? They're ridiculous.)

They are, but some people have non-unicode filenames on their systems
and thats the only way to access them.

- Hendrik
James Ross-Gowan July 5, 2017, 11:49 p.m. | #3
On Wednesday, 5 July 2017 8:18:26 PM, Hendrik Leppkes wrote:
>
> They are, but some people have non-unicode filenames on their systems
> and thats the only way to access them.
>
> - Hendrik

Are you sure? Windows' syscalls use UCS-2/UTF-16, so every filename should 
be
representable with wide characters. Functions like MoveFileExA just convert
their arguments to UTF-16 using MultiByteToWideChar or an equivalent 
function
and delegate to the wide-character variant. If libav wants to avoid linking
directly to MoveFileExA, but has to deal with filenames encoded in the ANSI
codepage, calling MultiByteToWideChar(CP_ACP) on each argument and calling
MoveFileExW should be equivalent.

Patch

diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 965e16f..55c2fdb 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -129,18 +129,6 @@  int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout);
 #include <windows.h>
 #include "libavutil/wchar_filename.h"
 
-#ifdef WINAPI_FAMILY
-#include <winapifamily.h>
-// If a WINAPI_FAMILY is defined, check that the desktop API subset
-// is enabled
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
-#define USE_MOVEFILEEXA
-#endif
-#else
-// If no WINAPI_FAMILY is defined, assume the full API subset
-#define USE_MOVEFILEEXA
-#endif
-
 #define DEF_FS_FUNCTION(name, wfunc, afunc)               \
 static inline int win32_##name(const char *filename_utf8) \
 {                                                         \
@@ -192,7 +180,7 @@  static inline int win32_rename(const char *src_utf8, const char *dest_utf8)
 
 fallback:
     /* filename may be be in CP_ACP */
-#ifdef USE_MOVEFILEEXA
+#if !HAVE_UWP
     ret = MoveFileExA(src_utf8, dest_utf8, MOVEFILE_REPLACE_EXISTING);
     if (ret)
         errno = EPERM;