1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2018 Nexenta Systems, Inc. 14 */ 15 16 /* 17 * Note that this file is easiest edited with a UTF-8 capable editor, 18 * as there are embedded UTF-8 symbols in some of the strings. 19 */ 20 21 #include <err.h> 22 #include <locale.h> 23 #include <stdio.h> 24 #include <string.h> 25 26 struct { 27 const char *locale; 28 const char *convspec; 29 const float fp; 30 const char *expected; 31 } fpconv[] = { 32 "C", "%a", 3.2, "0x1.99999a0000000p+1", 33 "C", "%e", 3.2, "3.200000e+00", 34 "C", "%f", 3.2, "3.200000", 35 "C", "%g", 3.2, "3.2", 36 "ar_AE.UTF-8", "%a", 3.2, "0x1٫99999a0000000p+1", 37 "ar_AE.UTF-8", "%e", 3.2, "3٫200000e+00", 38 "ar_AE.UTF-8", "%f", 3.2, "3٫200000", 39 "ar_AE.UTF-8", "%g", 3.2, "3٫2", 40 "en_US.UTF-8", "%a", 3.2, "0x1.99999a0000000p+1", 41 "en_US.UTF-8", "%e", 3.2, "3.200000e+00", 42 "en_US.UTF-8", "%f", 3.2, "3.200000", 43 "en_US.UTF-8", "%g", 3.2, "3.2", 44 "ru_RU.UTF-8", "%a", 3.2, "0x1,99999a0000000p+1", 45 "ru_RU.UTF-8", "%e", 3.2, "3,200000e+00", 46 "ru_RU.UTF-8", "%f", 3.2, "3,200000", 47 "ru_RU.UTF-8", "%g", 3.2, "3,2", 48 NULL, NULL, 0, NULL 49 }; 50 51 int 52 main(void) 53 { 54 char buf[100]; 55 int i; 56 57 for (i = 0; fpconv[i].locale != NULL; i++) { 58 if (setlocale(LC_ALL, fpconv[i].locale) == NULL) 59 err(1, "failed to set locale to %s", fpconv[i].locale); 60 61 (void) sprintf(buf, fpconv[i].convspec, fpconv[i].fp); 62 if (strcmp(fpconv[i].expected, buf) != 0) { 63 errx(1, "locale=%s, convspec=%s, expected=%s, got=%s", 64 fpconv[i].locale, fpconv[i].convspec, 65 fpconv[i].expected, buf); 66 } 67 } 68 69 return (0); 70 } 71