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.4 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 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 E71621F55B for ; Fri, 29 May 2020 20:29:34 +0000 (UTC) Received: from localhost ([::1]:50036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeldF-0002XM-KS for normalperson@yhbt.net; Fri, 29 May 2020 16:29:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeld9-0002Wu-SI for bug-gnulib@gnu.org; Fri, 29 May 2020 16:29:27 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.160]:13115) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeld7-00016Y-9q for bug-gnulib@gnu.org; Fri, 29 May 2020 16:29:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1590784162; 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=TUnMfnfVfEvF6c5E1hxaPS9PF/iyID5nGXlSbjuPH4Q=; b=qeV+2VIoQ+uvRClKChTh46MA7NUzrp0fllVKfSpnGRKLnKcRZepJR3l96lNOTQ/32x MRYRcO0BLrgTJ+ENMu7th9dXqT3a73EkfA4h5F19z25bGOr6Q8wXCeV5us5wD7GfPd6z 8DfWjyrfbUklPS25Yyyfw2bg2teyhAWhuk9aEYD79EBEIb/b1GEfZQBpGC944WbGsEdy 4s6G2ZzuBRsi2jdqWi5OMErXDNM2UTQ3n9DPRwlSWekCIgluafzLPLGxmsdxIMYBubuy BWKCjfji0FzGfg9r/Dk7I2lvRvwwVtexBJ9XLQkNzY1JzZtddVB9iux2QWO1D5apGFQ+ SnbQ== 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 j03713w4TKTK9tN (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 22:29:20 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: do not use GetModuleHandle when built for Windows Store apps Date: Fri, 29 May 2020 22:29:19 +0200 Message-ID: <1600734.iN3N4LOiM7@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <8510036.Z2lXjDNy1T@omega> References: <20200519062424.8282-1-robux4@ycbcr.xyz> <8510036.Z2lXjDNy1T@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.160; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/29 16:29:22 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_H2=-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" GetModuleHandle is like LoadLibrary: it is used for dynamic lookup of Windows API functions. And Windows Store apps can't use it. This patch fixes some of the issues. The other ones, in poll.c and select.c, are harder to fix, because it's not easy to link directly against ntdll.dll [1]. [1] https://stackoverflow.com/questions/35509388/link-to-ntdll-lib-and-call-functions-inside-ntdll-dll 2020-05-29 Bruno Haible Avoid dynamic lookup of Windows API functions when possible. * lib/getaddrinfo.c (GetProcAddress, getaddrinfo_func, freeaddrinfo_func, getnameinfo_func, getaddrinfo_ptr, freeaddrinfo_ptr, getnameinfo_ptr): Don't define in a build for Windows XP or higher. (use_win32_p): Define differently. * lib/link.c (GetProcAddress, CreateHardLinkFuncType, CreateHardLinkFunc, initialized, initialize): Don't define in a build for Windows XP or higher. diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 99cb709..1db9be8 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -86,9 +86,11 @@ freeaddrinfo (struct addrinfo *ai) # ifdef WINDOWS_NATIVE +# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP) + /* Avoid warnings from gcc -Wcast-function-type. */ -# define GetProcAddress \ - (void *) GetProcAddress +# define GetProcAddress \ + (void *) GetProcAddress typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, const struct addrinfo*, @@ -135,6 +137,29 @@ use_win32_p (void) return 1; } + +# else + +static int +use_win32_p (void) +{ + static int done = 0; + + if (!done) + { + done = 1; + + gl_sockets_startup (SOCKETS_1_1); + } + + return 1; +} + +# define getaddrinfo_ptr getaddrinfo +# define freeaddrinfo_ptr freeaddrinfo +# define getnameinfo_ptr getnameinfo + +# endif # endif static bool @@ -161,6 +186,7 @@ getaddrinfo (const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints, struct addrinfo **restrict res) +#undef getaddrinfo { struct addrinfo *tmp; int port = 0; @@ -362,6 +388,7 @@ getaddrinfo (const char *restrict nodename, /* Free 'addrinfo' structure AI including associated storage. */ void freeaddrinfo (struct addrinfo *ai) +#undef freeaddrinfo { # ifdef WINDOWS_NATIVE if (use_win32_p ()) @@ -388,6 +415,7 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags) +#undef getnameinfo { # ifdef WINDOWS_NATIVE if (use_win32_p ()) diff --git a/lib/link.c b/lib/link.c index 8e079d2..8680e3e 100644 --- a/lib/link.c +++ b/lib/link.c @@ -30,9 +30,11 @@ # define WIN32_LEAN_AND_MEAN # include +# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP) + /* Avoid warnings from gcc -Wcast-function-type. */ -# define GetProcAddress \ - (void *) GetProcAddress +# define GetProcAddress \ + (void *) GetProcAddress /* CreateHardLink was introduced only in Windows 2000. */ typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCSTR lpFileName, @@ -53,14 +55,24 @@ initialize (void) initialized = TRUE; } +# else + +# define CreateHardLinkFunc CreateHardLink + +# endif + int link (const char *file1, const char *file2) { char *dir; size_t len1 = strlen (file1); size_t len2 = strlen (file2); + +# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP) if (!initialized) initialize (); +# endif + if (CreateHardLinkFunc == NULL) { /* System does not support hard links. */