Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120898 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83309 invoked from network); 14 Aug 2023 17:21:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Aug 2023 17:21:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ED6B31804BE for ; Mon, 14 Aug 2023 10:21:39 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 14 Aug 2023 10:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1692033697; bh=QYApu1/bQvnXy18cUyXeONCjY7XtyctFY1DE2F8Jkow=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=fc2sH8Fxcmp4ssBv88YIPixz9vb5zARhWARGRTspkpZNsWrkRFnkfoSz35DZodkZZ Fd7YzOejRL2Fh/xDcEZ3ZBD54INRFyiydhXtHH658Nijqxl1E1Cq+8pmw6XbBp1lN0 hAl87gt3a8jca+rian+yf4Gdw9kejfAiglcG7YmYD+i3DSXgENOIjsI7ychM6aHRg7 MysgwJVyPJ7gcflFyP9NPD78oz6MhfsODtQLdWVaBFQExyqkoZUxnwyXpOCKur6eD+ nzL/jBOAKURCySBlNuzc7Phsdyp6iVhoBZc7rmb5+rceLZlHDPHEd1R2mV66un4MP3 8CD1sQhzfGBdw== Message-ID: Date: Mon, 14 Aug 2023 19:21:35 +0200 MIME-Version: 1.0 Content-Language: en-US To: =?UTF-8?Q?C=c3=b4me_Chilliet?= , internals@lists.php.net References: <2446443.ElGaqSPkdT@come-prox15amd> In-Reply-To: <2446443.ElGaqSPkdT@come-prox15amd> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Support optional suffix parameter in tempnam From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 8/14/23 17:57, Côme Chilliet wrote: > The RFC does not explain what benefits brings using tempnam($directory, $prefix, $suffix) over using tempnam($directory, $prefix).$suffix , which you can already use? As per the documentation of tempnam: > Creates a file with a unique filename, with access permission set to 0600, in the specified directory. The function does not just generate a filename, but also creates the file itself (with strict permissions) to "reserve" it and thus *guarantees* that there won't be a conflict. Manually appending a suffix does not have that property [1]. Best regards Tim Düsterhus [1] Though I'd like to note that using `$prefix . bin2hex(random_bytes(16)) . $suffix` as the filename will almost certainly [2] give you a conflict-free filename and doesn't have OS-specific behavior. That's why I personally don't bother with tempnam(). [2] Collision chance is less than 10^(-7) for 2^52 files.