[PATCH] linux: Implement tmpfile with O_TMPFILE (BZ#21530)
Dmitry V. Levin
ldv@altlinux.org
Fri Sep 1 00:39:00 GMT 2017
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.
> similar previous suggestion by Andreas Schwab [1] with the difference
similar to the previous ... with the difference that
> the file descriptor creation is parameterized to compartmentalize Linux
> only open flags (O_TMPFILE) on sysdep folder.
... into sysdeps.
[...]
> 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.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20170901/7025b798/attachment.sig>
More information about the Libc-alpha
mailing list