From owner-freebsd-current@freebsd.org Wed Nov 25 14:06:23 2015 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 00EB9A36D15 for ; Wed, 25 Nov 2015 14:06:23 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: from mail-lf0-f46.google.com (mail-lf0-f46.google.com [209.85.215.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8A7771CF3 for ; Wed, 25 Nov 2015 14:06:22 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: by lfs39 with SMTP id 39so59617252lfs.3 for ; Wed, 25 Nov 2015 06:06:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=gJWhceVmFBXuHe4J8qUGpBiaarZ71G3igtemRCnoq+c=; b=WbzrVAg+6XF85xf3XU7YKCz7/lIISPWWJbEQEcSlogVKhb+rTzEEqTBta6hM2CsXGb UWAKKU8j6QrdjMSSjs5aVbjD3XBpCPcY630QdQjY1sgSJeYxqHjzc8VPqGD5kUshyG3U RLyFab+crZp5Eqa8mUTTogirxwBGzwQ+09R4L+KQ9CStSbO0VDYuDIdL1hJ64SrWB5mS meO2wS+wfthO3nB6NrAjFQROBt7ZA63ObxEfxxL3sm69dEu0lc54lopOnkkAv/RyTt9O 05mH++hQgSo0tbaYdkK8aFyx3szszLwNEjMwmMu7hZRyt5WPLjRWXAUDOWcnHDaR081w NFkQ== X-Gm-Message-State: ALoCoQlbhf3QOeYb8/n8fGV/1F9jBA8A7OQlzOnMMTmnihb7pr4ONxFBC19DN0CNWkt33uA5zAr4 X-Received: by 10.25.30.70 with SMTP id e67mr12948337lfe.132.1448460380196; Wed, 25 Nov 2015 06:06:20 -0800 (PST) Received: from [192.168.1.2] ([89.169.173.68]) by smtp.gmail.com with ESMTPSA id m75sm3349461lfg.15.2015.11.25.06.06.18 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Nov 2015 06:06:18 -0800 (PST) Subject: Re: /bin/ls formatting broken for non-C(?) locales To: Baptiste Daroussin References: <20151120104253.GA21071@ivaldir.etoilebsd.net> <20151120110212.GB21071@ivaldir.etoilebsd.net> <20151120122352.GA5751@stack.nl> <20151121003541.GF21071@ivaldir.etoilebsd.net> <5650DACA.2090501@freebsd.org> <20151125001513.GC70014@ivaldir.etoilebsd.net> <56550F69.8050609@freebsd.org> <20151125125325.GB77370@ivaldir.etoilebsd.net> <5655B8D9.8060805@freebsd.org> <20151125135059.GC77370@ivaldir.etoilebsd.net> Cc: Ed Schouten , Jilles Tjoelker , "Sergey V. Dyatko" , FreeBSD Current From: Andrey Chernov Message-ID: <5655C059.8010701@freebsd.org> Date: Wed, 25 Nov 2015 17:06:17 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151125135059.GC77370@ivaldir.etoilebsd.net> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2015 14:06:23 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 25.11.2015 16:51, Baptiste Daroussin wrote: > wcslcat works like strlcat: > to quote the manpage: > "It will append at most dstsize - strlen(dst) - 1 characters." > So here with your version it will be n - wcslen(wab_months[i]) -1 > which won't fit what we want to do. >=20 > btw that makes me figure out that what I want is wcsncat because we do = care to > make sure we have appended the right number of spaces at the end of the= > abbreviated month based on character width, not the on the len of the w= ide > string >=20 > so I changed it >=20 > if ((n =3D max_month_width - wab_months_width[i]) > 0) > wcsncat(wab_months[i], L" "/* MAX_ABMON_WIDTH */, n); Sorry, I initially mean wcsncat() functionality here, wcslcat() is sneaked in due to wrong memorizing. About width counting and fallback... Without attempt to nicely truncate data damaged by unknown way the code will be simpler. Instead all that loop adding width one by one wchar, jus= t: width =3D wcswidth(wab_months[i], MAX_ABMON_WIDTH); if (width =3D=3D -1) { max_month_width =3D -1; return; } wab_months_width[i] =3D width; About /* NULL terminate to simplify padding later */ wab_months[i][j] =3D L'\0'; You don't need it, mbstowcs() null-terminates result, if there is a room.= BTW, array size looks suspicious: static wchar_t wab_months[12][MAX_ABMON_WIDTH * 2 * MB_LEN_MAX]; what MB_LEN_MAX doing here? This constant is for multiple-bytes encoded, not for wide chars. --=20 http://ache.vniz.net/ --KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJWVcBaAAoJEKUckv0MjfbKjU8IAJLLiGS1ox6gxL80Dj0EWHw4 jXd1mywrMK2uy9mM37X42Wfdp026djIbnsAHdcG9uYlvEDJ6XciHbZqKSrttbWKA vFfaguvtJ5QAbphllRSF5CqX8o/V6XcgLnldcBOWArQvjQ4hnIBz3Uh1EdGIJSDu /4u2YLBW2GC3lG0+KqvL/C4QSzFfUUIB+ScyiruK/5eRO4PCOB8/ZAbAiyp7Jq8S l1J8QED//28UUIKb7EEE8aeOWsf+Kv6EjaZu5tfTfCn73gi9EmqDgLyJiPeRlOce HNmNo13UXhMrXB8e1L4cieq23NgS4g9zD2AmIjrRmyEnSxgaX1xEu7qXbHbin6w= =wvIN -----END PGP SIGNATURE----- --KtN2d2mgJj9oEFl65Wthe7ha4Eg9s1gQf--