Re: [Mingw-w64-public] [PATCH] Add __mingw_access() that works the same for all msvcr*/ucrt libs

2019-01-07 Thread Mateusz
W dniu 08.01.2019 o 04:33, Liu Hao pisze:
> 在 2019/1/8 8:32, Mateusz 写道:
>> W dniu 08.01.2019 o 00:49, JonY pisze:
>>> On 1/7/19 5:50 PM, Mateusz wrote:
 Old versions of MSVCRT _access() just ignored X_OK, while the
 version shipped with Vista, returns an error code.
 _access() from msvcr110/120 returns an error code for nul file.

 Signed-off-by: Mateusz Brzostek 
>>>
>>> Patch looks OK.
>>
>> Thanks for review.
>>
>> There is one problem with this patch -- in 32-bit mode #include  
>> implies #include  only if it is set at least -msse2. In 32-bit MSVC 
>> 2015 it is included even with options /arch:IA32 or /arch:SSE (/arch:SSE2 is 
>> default for 32-bit).
>>
>> So it should be added
>> #include 
>> to the patch (or we could fix mingw-w64 to load errno.h unconditionally when 
>> we #include ).
>>
>>
> 
> Pushed to master.
> 
> GCC source code (either of GCC itself or libiberty) still needs patching
> for use of newer MSVCR*.DLL with an old version of mingw-w64, however.
 
Thanks for pushing!

This patch changed mingw-w64-crt/Makefile.am -- can we regenerate makefiles in 
mingw-w64-crt/ ?

Regards,
Mateusz



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] Add __mingw_access() that works the same for all msvcr*/ucrt libs

2019-01-07 Thread Liu Hao
在 2019/1/8 8:32, Mateusz 写道:
> W dniu 08.01.2019 o 00:49, JonY pisze:
>> On 1/7/19 5:50 PM, Mateusz wrote:
>>> Old versions of MSVCRT _access() just ignored X_OK, while the
>>> version shipped with Vista, returns an error code.
>>> _access() from msvcr110/120 returns an error code for nul file.
>>>
>>> Signed-off-by: Mateusz Brzostek 
>>
>> Patch looks OK.
> 
> Thanks for review.
> 
> There is one problem with this patch -- in 32-bit mode #include  
> implies #include  only if it is set at least -msse2. In 32-bit MSVC 
> 2015 it is included even with options /arch:IA32 or /arch:SSE (/arch:SSE2 is 
> default for 32-bit).
> 
> So it should be added
> #include 
> to the patch (or we could fix mingw-w64 to load errno.h unconditionally when 
> we #include ).
> 
>

Pushed to master.

GCC source code (either of GCC itself or libiberty) still needs patching
for use of newer MSVCR*.DLL with an old version of mingw-w64, however.


-- 
Best regards,
LH_Mouse

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] Add __mingw_access() that works the same for all msvcr*/ucrt libs

2019-01-07 Thread Mateusz
W dniu 08.01.2019 o 00:49, JonY pisze:
> On 1/7/19 5:50 PM, Mateusz wrote:
>> Old versions of MSVCRT _access() just ignored X_OK, while the
>> version shipped with Vista, returns an error code.
>> _access() from msvcr110/120 returns an error code for nul file.
>>
>> Signed-off-by: Mateusz Brzostek 
> 
> Patch looks OK.

Thanks for review.

There is one problem with this patch -- in 32-bit mode #include  
implies #include  only if it is set at least -msse2. In 32-bit MSVC 
2015 it is included even with options /arch:IA32 or /arch:SSE (/arch:SSE2 is 
default for 32-bit).

So it should be added
#include 
to the patch (or we could fix mingw-w64 to load errno.h unconditionally when we 
#include ).

Regards,
Mateusz



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] Add __mingw_access() that works the same for all msvcr*/ucrt libs

2019-01-07 Thread JonY via Mingw-w64-public
On 1/7/19 5:50 PM, Mateusz wrote:
> Old versions of MSVCRT _access() just ignored X_OK, while the
> version shipped with Vista, returns an error code.
> _access() from msvcr110/120 returns an error code for nul file.
> 
> Signed-off-by: Mateusz Brzostek 

Patch looks OK.




signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH] Add __mingw_access() that works the same for all msvcr*/ucrt libs

2019-01-07 Thread Mateusz
Old versions of MSVCRT _access() just ignored X_OK, while the
version shipped with Vista, returns an error code.
_access() from msvcr110/120 returns an error code for nul file.

Signed-off-by: Mateusz Brzostek 
---
 mingw-w64-crt/Makefile.am |  2 +-
 mingw-w64-crt/misc/mingw-access.c | 53 +++
 mingw-w64-headers/crt/io.h|  4 +--
 3 files changed, 55 insertions(+), 4 deletions(-)
 create mode 100644 mingw-w64-crt/misc/mingw-access.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index f8b0623c..10f3b04c 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -330,7 +330,7 @@ src_libmingwex=\
   misc/wcstoimax.c   misc/wcstold.c misc/wcstoumax.c
misc/wctob.c misc/wctrans.c \
   misc/wctype.c  misc/wdirent.c misc/winbs_uint64.c 
misc/winbs_ulong.c   misc/winbs_ushort.c\
   misc/wmemchr.c misc/wmemcmp.c misc/wmemcpy.c  
misc/wmemmove.c  misc/wmempcpy.c\
-  misc/wmemset.c misc/ftw.c misc/ftw64.c  \
+  misc/wmemset.c misc/ftw.c misc/ftw64.c
misc/mingw-access.c  \
   \
   stdio/mingw_pformat.h\
   stdio/vfscanf2.S stdio/vfwscanf2.S stdio/vscanf2.S  
stdio/vsscanf2.S  stdio/vswscanf2.S \
diff --git a/mingw-w64-crt/misc/mingw-access.c 
b/mingw-w64-crt/misc/mingw-access.c
new file mode 100644
index ..98fe734d
--- /dev/null
+++ b/mingw-w64-crt/misc/mingw-access.c
@@ -0,0 +1,53 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include 
+#include 
+
+int __cdecl __mingw_access(const char *fname, int mode);
+
+int __cdecl __mingw_access(const char *fname, int mode)
+{
+  DWORD attr;
+
+  if (fname == NULL || (mode & ~(F_OK | X_OK | W_OK | R_OK)))
+  {
+errno = EINVAL;
+return -1;
+  }
+
+  attr = GetFileAttributesA(fname);
+  if (attr == INVALID_FILE_ATTRIBUTES)
+  {
+switch (GetLastError())
+{
+  case ERROR_FILE_NOT_FOUND:
+  case ERROR_PATH_NOT_FOUND:
+errno = ENOENT;
+break;
+  case ERROR_ACCESS_DENIED:
+errno = EACCES;
+break;
+  default:
+errno = EINVAL;
+}
+return -1;
+  }
+
+  if (attr & FILE_ATTRIBUTE_DIRECTORY)
+  {
+/* All directories have read & write access */
+return 0;
+  }
+
+  if ((attr & FILE_ATTRIBUTE_READONLY) && (mode & W_OK))
+  {
+/* no write permission on file */
+errno = EACCES;
+return -1;
+  }
+  else
+return 0;
+}
diff --git a/mingw-w64-headers/crt/io.h b/mingw-w64-headers/crt/io.h
index a7cc5fc4..4a5b08ba 100644
--- a/mingw-w64-headers/crt/io.h
+++ b/mingw-w64-headers/crt/io.h
@@ -365,9 +365,7 @@ unsigned int alarm(unsigned int seconds);
 /*  Old versions of MSVCRT access() just ignored X_OK, while the version
 shipped with Vista, returns an error code.  This will restore the
 old behaviour  */
-static inline int __mingw_access (const char *__fname, int __mode) {
-  return  _access (__fname, __mode & ~X_OK);
-}
+int __cdecl __mingw_access (const char *__fname, int __mode);
 
 #define access(__f,__m)  __mingw_access (__f, __m)
 #endif
-- 
2.20.1.windows.1



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] GCC: Introduce xaccess function in libiberty

2019-01-07 Thread Liu Hao
在 2019/1/7 5:06, Mateusz 写道:
> W dniu 06.01.2019 o 16:17, Liu Hao pisze:
>> 在 2019/1/6 9:19, Mateusz 写道:
>>> W dniu 05.01.2019 o 20:59, Johannes Pfau pisze:
>>> Maybe it would make sense to add this in crt/io.h? There's already a 
>>> __USE_MINGW_ACCESS guarded __mingw_access wrapper function which could be 
>>> extended. And as far as I can see, GCC already sets the __USE_MINGW_ACCESS 
>>> define, so it likely wouldn't need any changes.
>>> I've attached patch to mingw-w64 that replaces _access in msvcr110/120 and 
>>> ucrtbase with Liu Hao version (for me it is too big for inline).
>>>
>>
>> This looks bad to be, as it breaks code which expects the MSVC behavior.
> 
> We could add __mingw_access to msvcr110/120 + ucrtbase libs and change a 
> little bit io.h for case if __USE_MINGW_ACCESS is defined (check for 
> __MSVCRT_VERSION__).
> 
> Or we could add __mingw_access to libmingwex and use exact the same version 
> for all msvcrt/msvcr*/ucrt if __USE_MINGW_ACCESS is defined.
> 
> Or we could add __mingw_access to libmingwex and use it only when 
> __MSVCRT_VERSION__ >= 0x1100 && defined(__USE_MINGW_ACCESS) and leave as is 
> now for __MSVCRT_VERSION__ < 0x1100.
> 

The second one sounds appropriate to me, as it is just we deal with
stdio functions.

> I've attached access from MSVC 2010 -- if we agree that mingw-w64 should be 
> patched in some way we could choose detail for _access/__mingw_access.
> 

PLEASE STOP COPYING CODE FROM MICROSOFT SDKS.

We are not willing to receive lawyer's letters. Publishing this code for
others to copy probably already violates its license.


-- 
Best regards,
LH_Mouse

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public