From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_PDS_OTHER_BAD_TLD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 22BD91F55B for ; Fri, 29 May 2020 00:05:17 +0000 (UTC) Received: from localhost ([::1]:43606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeSWR-0003yN-R5 for normalperson@yhbt.net; Thu, 28 May 2020 20:05:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeSWO-0003yD-5t for bug-gnulib@gnu.org; Thu, 28 May 2020 20:05:12 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.23]:32891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeSWL-00057j-9k for bug-gnulib@gnu.org; Thu, 28 May 2020 20:05:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1590710706; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=xWn1sgISN9YUr0313DcLLt+gdNUu866Y7DsXVUnJEOw=; b=L+C9Fqd928+m0KuOKQtoaFL0A8ZMIbCrnBr218Wyvm4yvR2AIRMRRiFr3ZGgDap74J kOoVP3fR/rWv4Zinw6EKYiRIe2O+PWXyX+BalBItztRe74+RXXnSGb0sT9VueVCBGnGi ov2uzGxvCaEdMGXG0yNQExkwVDCtDzWBzMNHKuJH73cV2TKWelJiJ9CqxECM280PR8eh jteAWX43DdDX3QmPIiv07MkO3n/xvvIest5Y+K4jGsakyT+XxoihgVI3WmTtJ/ortsbZ Wn03KoQCEkrcPgHPob5+5akhjsOWY2HmBsAuPq6O3M+llMEsStYVf/t4JJc2nggGqn10 evnw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6fzxfs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.9.0 DYNA|AUTH) with ESMTPSA id j03713w4T04x4gh (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Fri, 29 May 2020 02:04:59 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: Re: [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps Date: Fri, 29 May 2020 02:04:57 +0200 Message-ID: <8510036.Z2lXjDNy1T@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <20200519062424.8282-1-robux4@ycbcr.xyz> References: <20200519062424.8282-1-robux4@ycbcr.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=85.215.255.23; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 20:05:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Steve Lhomme Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hi, Steve Lhomme wrote: > LoadLibrary is forbidden in such apps (can only load DLLs from within the app > package). > The API entries are available to all apps linking with the Windows API as found > here: > https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis Thanks for these infos. > +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */ The GetSystemTimePreciseAsFileTime function is available starting with Windows 8, therefore - the condition with WINAPI_FAMILY_PARTITION is not necessary, - the condition _WIN32_WINNT >= 0x0A00 is overly restrictive; _WIN32_WINNT >= _WIN32_WINNT_WIN8 will work just as well. I have added a page about the native Windows APIs at https://gitlab.com/ghwiki/gnow-how/-/wikis/Platforms/Native_Windows Then here is a patch to avoid LoadLibrary when possible. 2020-05-28 Bruno Haible Avoid dynamic loading of Windows API functions when possible. Reported by Steve Lhomme in . * lib/gettimeofday.c (GetProcAddress, GetSystemTimePreciseAsFileTimeFuncType, GetSystemTimePreciseAsFileTimeFunc, initialized, initialize): Don't define in a build for Windows 8 or higher. * lib/isatty.c (GetProcAddress, GetNamedPipeClientProcessIdFuncType, GetNamedPipeClientProcessIdFunc, QueryFullProcessImageNameFuncType, QueryFullProcessImageNameFunc, initialized, initialize): Don't define in a build for Windows Vista or higher. * lib/stat-w32.c (GetProcAddress, GetFileInformationByHandleExFuncType, GetFileInformationByHandleExFunc, GetFinalPathNameByHandleFuncType, GetFinalPathNameByHandleFunc, initialized, initialize): Likewise. diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c index 1980479..3d53115 100644 --- a/lib/gettimeofday.c +++ b/lib/gettimeofday.c @@ -33,9 +33,11 @@ #ifdef WINDOWS_NATIVE +# if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8) + /* Avoid warnings from gcc -Wcast-function-type. */ -# define GetProcAddress \ - (void *) GetProcAddress +# define GetProcAddress \ + (void *) GetProcAddress /* GetSystemTimePreciseAsFileTime was introduced only in Windows 8. */ typedef void (WINAPI * GetSystemTimePreciseAsFileTimeFuncType) (FILETIME *lpTime); @@ -54,6 +56,8 @@ initialize (void) initialized = TRUE; } +# endif + #endif /* This is a wrapper for gettimeofday. It is used only on systems @@ -84,8 +88,10 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz) . */ FILETIME current_time; +# if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8) if (!initialized) initialize (); +# endif if (GetSystemTimePreciseAsFileTimeFunc != NULL) GetSystemTimePreciseAsFileTimeFunc (¤t_time); else diff --git a/lib/isatty.c b/lib/isatty.c index 6cdc0fb..fc771d1 100644 --- a/lib/isatty.c +++ b/lib/isatty.c @@ -39,9 +39,11 @@ # include #endif +#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) + /* Avoid warnings from gcc -Wcast-function-type. */ -#define GetProcAddress \ - (void *) GetProcAddress +# define GetProcAddress \ + (void *) GetProcAddress /* GetNamedPipeClientProcessId was introduced only in Windows Vista. */ typedef BOOL (WINAPI * GetNamedPipeClientProcessIdFuncType) (HANDLE hPipe, @@ -69,6 +71,8 @@ initialize (void) initialized = TRUE; } +#endif + static BOOL IsConsoleHandle (HANDLE h) { DWORD mode; @@ -84,8 +88,10 @@ static BOOL IsCygwinConsoleHandle (HANDLE h) BOOL result = FALSE; ULONG processId; +#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) if (!initialized) initialize (); +#endif /* GetNamedPipeClientProcessId diff --git a/lib/stat-w32.c b/lib/stat-w32.c index b9163f5..02ad9ab 100644 --- a/lib/stat-w32.c +++ b/lib/stat-w32.c @@ -40,18 +40,20 @@ #include "pathmax.h" #include "verify.h" +#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) + /* Avoid warnings from gcc -Wcast-function-type. */ -#define GetProcAddress \ - (void *) GetProcAddress +# define GetProcAddress \ + (void *) GetProcAddress -#if _GL_WINDOWS_STAT_INODES == 2 +# if _GL_WINDOWS_STAT_INODES == 2 /* GetFileInformationByHandleEx was introduced only in Windows Vista. */ typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS fiClass, LPVOID lpBuffer, DWORD dwBufferSize); static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL; -#endif +# endif /* GetFinalPathNameByHandle was introduced only in Windows Vista. */ typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile, LPSTR lpFilePath, @@ -66,16 +68,18 @@ initialize (void) HMODULE kernel32 = LoadLibrary ("kernel32.dll"); if (kernel32 != NULL) { -#if _GL_WINDOWS_STAT_INODES == 2 +# if _GL_WINDOWS_STAT_INODES == 2 GetFileInformationByHandleExFunc = (GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx"); -#endif +# endif GetFinalPathNameByHandleFunc = (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA"); } initialized = TRUE; } +#endif + /* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */ #if _GL_WINDOWS_STAT_TIMESPEC struct timespec @@ -134,8 +138,10 @@ _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf) DWORD type = GetFileType (h); if (type == FILE_TYPE_DISK) { +#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA) if (!initialized) initialize (); +#endif /* st_mode can be determined through GetFileAttributesEx