This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] linux: Implement tmpfile with O_TMPFILE (BZ#21530)
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 1 Sep 2017 09:53:53 -0300
- Subject: Re: [PATCH] linux: Implement tmpfile with O_TMPFILE (BZ#21530)
- Authentication-results: sourceware.org; auth=none
- References: <1504211656-9263-1-git-send-email-adhemerval.zanella@linaro.org> <20170901003910.GA24513@altlinux.org>
On 31/08/2017 21:39, Dmitry V. Levin wrote:
> On Thu, Aug 31, 2017 at 05:34:16PM -0300, Adhemerval Zanella wrote:
>> This patch adds support to use O_TMPFILE on tmpfile on Linux. This is
>
> ... adds O_TMPFILE support to tmpfile on Linux.
Ack.
>
>> similar previous suggestion by Andreas Schwab [1] with the difference
>
> similar to the previous ... with the difference that
Ack.
>
>> the file descriptor creation is parameterized to compartmentalize Linux
>> only open flags (O_TMPFILE) on sysdep folder.
>
> ... into sysdeps.
Ack.
>
> [...]
>> diff --git a/stdio-common/tmpfile.c b/stdio-common/tmpfile.c
>> index e6030be..3e35345 100644
>> --- a/stdio-common/tmpfile.c
>> +++ b/stdio-common/tmpfile.c
>> @@ -34,23 +34,34 @@
>> FILE *
>> tmpfile (void)
>> {
>> - char buf[FILENAME_MAX];
>> int fd;
>> FILE *f;
>> -
>> - if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
>> - return NULL;
>> int flags = 0;
>> #ifdef FLAGS
>> flags = FLAGS;
>> #endif
>> - fd = __gen_tempname (buf, 0, flags, __GT_FILE);
>> +
>> + /* First try a system specific method. */
>> + fd = __gen_tempfd (flags);
>> +
>> if (fd < 0)
>> - return NULL;
>> + {
>> + char buf[FILENAME_MAX];
>>
>> - /* Note that this relies on the Unix semantics that
>> - a file is not really removed until it is closed. */
>> - (void) __unlink (buf);
>> + if (__path_search (buf, sizeof buf, NULL, "tmpf", 0))
>> + return NULL;
>> +
>> + fd = __gen_tempname (buf, 0, flags, __GT_FILE);
>> + if (fd < 0)
>> + return NULL;
>> +
>> + /* Note that this relies on the Unix semantics that
>> + a file is not really removed until it is closed. */
>> + (void) __unlink (buf);
>> + }
>> +
>> + if (fd < 0)
>> + return NULL;
>
> The last "if (fd < 0)" check is redundant.
Ack. I fixed the commit wording and removed the redundant tests, thanks.