From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5850 invoked by alias); 9 Nov 2011 17:07:49 -0000 Received: (qmail 5800 invoked by uid 22791); 9 Nov 2011 17:07:27 -0000 X-Spam-Check-By: sourceware.org Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.83/v0.83-20-g38e4449) with ESMTP; Wed, 09 Nov 2011 17:07:14 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id 0638E2C0486; Wed, 9 Nov 2011 18:06:53 +0100 (CET) Date: Wed, 09 Nov 2011 17:07:00 -0000 From: Corinna Vinschen To: gdb-patches@sourceware.org Subject: Re: [PATCH] windows-nat: Decode system error numbers Message-ID: <20111109170652.GM15154@calimero.vinschen.de> Reply-To: gdb-patches@sourceware.org Mail-Followup-To: gdb-patches@sourceware.org References: <83obwlgsc5.fsf@gnu.org> <201111091658.00913.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <201111091658.00913.pedro@codesourcery.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-11/txt/msg00237.txt.bz2 On Nov 9 16:58, Pedro Alves wrote: > On Wednesday 09 November 2011 16:42:50, Eli Zaretskii wrote: > > > Date: Wed, 9 Nov 2011 12:02:40 +0000 > > > From: "Maciej W. Rozycki" > > > > > > + const char *msg = "Unspecified error."; > > > + unsigned long err; > > > + char buf[1025]; > > > + size_t size; > > > + > > > + if (ok) > > > + return; > > > + > > > + err = GetLastError(); > > > + size = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM > > > + | FORMAT_MESSAGE_IGNORE_INSERTS, > > > + NULL, > > > + err, > > > + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), > > > + buf, (sizeof (buf) - 1) / sizeof (TCHAR), NULL); > > > > Will this DTRT with Cygwin, which AFAIK wants the wide versions of the > > APIs? Is, for example, "char buf[1025];" appropriate in that case? > > Yeah, if UNICODE is defined, FormatMessage maps to FormatMessageW and > buf will be filled with a wide string, though I'm not sure > if __USEWIDE implies UNICODE. Then again, buf is defined as char, not wchar_t or WCHAR. It would be better to make buf a wchar_t, always call FormatMessageW, and then call printf_filtered with %ls as string format. That should work on all supported platforms. Corinna -- Corinna Vinschen Cygwin Project Co-Leader Red Hat