From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by sourceware.org (Postfix) with ESMTPS id 20B6A3857C4F for ; Mon, 19 Oct 2020 21:01:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 20B6A3857C4F Received: by mail-qt1-x844.google.com with SMTP id p88so819624qtd.12 for ; Mon, 19 Oct 2020 14:01:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:autocrypt:subject:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ohtGWNFl6D/gGS7vW93PQpwK0N73TpLMvbo6Rh1aWc0=; b=D3tiXC9U4GgmHa4rHoYXKKnz5U4yKm5cxecg1ZGXvKGnwjPMcdhaHY8XxetkogixTW lK49Ac+4rJI765wCaCl0HdolOhdngC/65WndTM7YA4AfHUSThBPBxt/uVKPxftSEXbbb M8WUy8DC6h/MQ2dEe3KcnqUC3kwNVQko3TzppXsEb6a9qUuLT/KhJRXF3JMODhrjRO4V i1LnFkmIszUvgGeSIe9LFarZa+nzANft8nRe/1xI6dS66msg2w/yHKTvFAp2Mf4qGKrL ucQ4+aMfQ/V0pdumRBejiMPdoardgtpQFZJUe2bVVB53G5SBPd668ZpsCAkWIBZmLn4U gmWg== X-Gm-Message-State: AOAM531oIsFF6nNm2s3sy14m+EHyAPYFX2ZJeHeSYNSqa9WYu912HP8u KJ++e8WRI47JTauJMulWiGjcZNB4c1Hy4Q== X-Google-Smtp-Source: ABdhPJzqdw6RdleiZA8mWq5aLxLKrldzzCHZVULTPHs5GToJK6t0EsN4ZQrHZzSOIXABGZIuFMRtKA== X-Received: by 2002:ac8:3ffb:: with SMTP id v56mr1454048qtk.364.1603141289161; Mon, 19 Oct 2020 14:01:29 -0700 (PDT) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id d129sm520981qkg.127.2020.10.19.14.01.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Oct 2020 14:01:28 -0700 (PDT) To: ell1e , libc-help@sourceware.org References: From: Adhemerval Zanella Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= mQINBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABtElBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGxhQGxp bmFyby5vcmc+iQI3BBMBCAAhBQJXFRpKAhsDBQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJ EKqx7B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: Is there a way to use vsnprintf_l? Would it possibly be considered for an addition one day, if missing? Message-ID: Date: Mon, 19 Oct 2020 18:01:25 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2020 21:01:32 -0000 On 17/10/2020 08:33, ell1e wrote: > Hello everyone, I hope I'm sending this to the right place! > > I write C stuff on linux with GLIBC, and I've discovered I prefer to use a locale-independent version of snprintf to avoid issues with third party plugins using a process-wide setlocale() thoughtlessly. While I am aware a uselocale() in the local thread would also help with this, I don't really want to put that everywhere after I call into an external plugin just in case to guarantee this (or every time before I call snprintf). > > The typical choice from what I can see for a locale-independent snprintf would be snprintf_l. However, always specifying that I really want a "C" locale as an additional parameter is tedious, especially since I have no desire to ever use anything else. In addition, this function isn't available on all platforms or might be named differently/have a different argument order (e.g. Windows, or MinGW). Therefore, I wrapped it to have the regular snprintf signature again: > > static int mysnprintf(char *buf, size_t size, const char *format, ...) > > ... as a three line inline header function (to give it a chance of being inlined/optimized away), where the natural function to call inside would now be vsnprintf_l as far as I can tell. > > However, sadly it seems glibc is lacking vsnprintf_l. I grepped the headers, and just couldn't find it. > > Does it happen to be available in some ways I didn't anticipate? If not, is there a possibility to petition for it to be added? GLIBC does not support the printf family with the extra locale as argument, and I think it should be feasible addition. We already implement the one that the standard defines (such as strcasecmp_l), this seems a reasonable addition. > > Right now I'm calling uselocale()+vsnprintf() in a pair every time instead. While I don't anticipate any notable performance problems from the additional call, it still seems needlessly tedious, and vsnprintf_l just feeks like a better match. In addition, vsnprintf_l is available on the popular BSDs, macOS, and even Windows 10! (As a variant with slightly different argument order, _vsnprintf_l.) So I think it would be great to have it on Linux as well for parity. If the idea is to provide a concise support for printf_l family function, I think we should add not only snprintf_l or vsnprintf_l, but rather all the stdio functions for both printf *and* scanf along with the wchar_t family as well. It means to add support for: int fprintf_l (FILE *, locale_t, const char *, ...) int fscanf_l (FILE * , locale_t, const char *, ...) int printf_l (locale_t, const char *, ...) int scanf_l (locale_t, const char *, ...) int sprintf_l (char *, locale_t, const char * , ...) int sscanf_l (const char *, locale_t, const char * , ...) int vfprintf_l (FILE *, locale_t, const char * , __va_list) int vprintf_l (locale_t, const char *, __va_list) int vsprintf_l (char * , locale_t, const char *, __va_list); int snprintf_l (char *, size_t, locale_t, const char * , ...) int vfscanf_l (FILE * , locale_t, const char * , __va_list) int vscanf_l (locale_t, const char *, __va_list) int vsnprintf_l (char *, size_t, locale_t, const char *, va_list) int vsscanf_l (const char *, locale_t, const char *, va_list); int dprintf_l (int, locale_t, const char *, ...) int vdprintf_l (int, locale_t, const char *, __va_list) int asprintf_l (char **, locale_t, const char *, ...) int vasprintf_l (char **, locale_t, const char *, __va_list) int fwprintf_l (FILE *, locale_t, const wchar_t *, ...) int fwscanf_l (FILE * , locale_t, const wchar_t *, ...) int wprintf_l (locale_t, const wchar_t *, ...) int wscanf_l (locale_t, const wchar_t *, ...) int wsprintf_l (char *, locale_t, const wchar_t * , ...) int swscanf_l (const char *, locale_t, const wchar_t * , ...) int vfwprintf_l (FILE *, locale_t, const wchar_t * , __va_list) int vwprintf_l (locale_t, const wchar_t *, __va_list) int vswprintf_l (wchar_t * , locale_t, const wchar_t *, __va_list); int snwprintf_l (wchar_t *, size_t, locale_t, const wchar_t * , ...) int vfwscanf_l (FILE * , locale_t, const wchar_t * , __va_list) int vwscanf_l (locale_t, const char *, __va_list) int vsnwprintf_l (wchar_t *, size_t, locale_t, const wchar_t *, va_list) int vswscanf_l (const wchar_t *, locale_t, const wchar_t *, va_list); int dwprintf_l (int, locale_t, const wchar_t *, ...) int vdwprintf_l (int, locale_t, const wchar_t *, __va_list) int aswprintf_l (wchar_t **, locale_t, const wchar_t *, ...) int vaswprintf_l (wchar_t **, locale_t, const wchar_t *, __va_list) What I am not sure if this would require to add the remaining stdio interfaces that depends on the LC_CTYPE category of the current locale, such as getwc/fgetwc, btowc, etc. I would say it makes sense to add them as well. It would also require to add proper tests to check the added interfaces. > > For a similar reasoning, vprintf_l (in addition to vsnprintf_l) would also be a function I'd really love to use. I already use strtod_l, which thankfully does seem to be available in glibc already. > > Best regards and happy C writing, > > ell1e > > PS: I hope I didn't typo the function names anywhere, I tend to mess up the letters sometimes xD I apologize if that happened at any point I don't know any glibc contributor that had showed interest in this specific task. It is not that simple, but it is also mostly plumbing work on moving the generic implementation to accept the locale_t as argument, create the internal alias and implement the default printf symbol to call the print_l one. If you want to implement it, I can help you with the patch submission, review and testing.