From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86708 invoked by alias); 2 Feb 2016 04:33:00 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 86694 invoked by uid 89); 2 Feb 2016 04:32:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=BAYES_20,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=mars, H*F:U*tony, 9699919799, pubs.opengroup.org X-HELO: mars.tony.develop-help.com Received: from develop-help.com (HELO mars.tony.develop-help.com) (14.200.49.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 02 Feb 2016 04:32:54 +0000 Received: from mars.tony.develop-help.com (localhost [127.0.0.1]) by mars.tony.develop-help.com (8.14.4/8.14.4/Debian-8) with ESMTP id u124Wm6S027163 for ; Tue, 2 Feb 2016 15:32:48 +1100 Received: (from tony@localhost) by mars.tony.develop-help.com (8.14.4/8.14.4/Submit) id u124Wlnb027162 for cygwin@cygwin.com; Tue, 2 Feb 2016 15:32:47 +1100 Date: Tue, 02 Feb 2016 04:33:00 -0000 From: Tony Cook To: cygwin@cygwin.com Subject: cygwin 2.4.1: broken ps_AF and ps_AF.utf8 locales Message-ID: <20160202043247.GP31193@mars.tony.develop-help.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2016-02/txt/msg00014.txt.bz2 Hi list, Simplified to a C program below, calls to sprintf() under the ps_AF and ps_AF.utf8 locales are returning a value that doesn't match the length of the formatted string: tony@phobos ~ $ cat ps_AF.c #include #include #include int main(int argc, char **argv) { char buf[100]; char *loc = argc > 1 ? argv[1] : "ps_AF"; const char *real_loc; if (!(real_loc = setlocale(LC_NUMERIC, loc))) { perror("setlocale"); return 1; } printf("locale %s\n", real_loc); size_t len = sprintf(buf, "%g", 2.34); printf("len %zu\n", len); printf("strlen %zu\n", strlen(buf)); return 0; } tony@phobos ~ $ gcc -ops_AF.exe ps_AF.c tony@phobos ~ $ ./ps_AF locale ps_AF len 4 strlen 5 tony@phobos ~ $ ./ps_AF ps_AF.utf8 locale ps_AF.utf8 len 4 strlen 5 tony@phobos ~ $ ./ps_AF en_US.utf8 locale en_US.utf8 len 4 strlen 4 tony@phobos ~ $ uname -a CYGWIN_NT-6.1-WOW phobos 2.4.1(0.293/5/3) 2016-01-24 11:24 i686 Cygwin The man pages and C standard could be read as sprintf() returning the number of multi-byte characters, but if cygwin is intended to follow Linux behaviour: tony@mars:~/play$ gcc -ops_AF ps_AF.c tony@mars:~/play$ ./ps_AF locale ps_AF len 5 strlen 5 tony@mars:~/play$ ./ps_AF ps_AF.utf8 locale ps_AF.utf8 len 5 strlen 5 tony@mars:~/play$ ./ps_AF en_AU.utf8 locale en_AU.utf8 len 4 strlen 4 tony@mars:~/play$ uname -a Linux mars 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux (and the decimal point under ps_AF on Linux is multi-byte, character 0x66b or ARABIC DECIMAL SEPARATOR.) POSIX is less confusing and specifies: Upon successful completion, the sprintf() function shall return the number of bytes written to s, excluding the terminating null byte. (http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html) Tony -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple