From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from thiem.email (elliethiem.com [116.203.31.83]) by sourceware.org (Postfix) with ESMTPS id CBDBA3857C4E for ; Sat, 17 Oct 2020 11:33:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CBDBA3857C4E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=wobble.ninja Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kittens@wobble.ninja Received: from [192.168.178.183] (pd9e156b4.dip0.t-ipconnect.de [217.225.86.180]) by thiem.email (Postfix) with ESMTPSA id 61AF2121DC5 for ; Sat, 17 Oct 2020 11:33:54 +0000 (UTC) To: libc-help@sourceware.org From: ell1e Subject: Is there a way to use vsnprintf_l? Would it possibly be considered for an addition one day, if missing? Message-ID: Date: Sat, 17 Oct 2020 13:33:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * 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: Sat, 17 Oct 2020 11:33:57 -0000 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? 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. 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