From 9a9374955517bf731f11fd2c4a071b3cc1120526 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 27 Apr 2022 09:10:02 -0400 Subject: drop use of stat operation in temporary file name generation this change serves two purposes: 1. it eliminates one of the few remaining uses of the kernel stat structure which will not be present in future archs, avoiding the need for growing ifdef logic here. 2. it potentially makes the operations less expensive when the candidate exists as a non-symlink by avoiding the need to read the inode (assuming the directory tables suffice to distinguish symlinks). this uses the idiom I discovered while rewriting realpath for commit 29ff7599a448232f2527841c2362643d246cee36 of being able to use the readlink operation as an inexpensive probe for file existence that doesn't following symlinks. --- src/stdio/tempnam.c | 8 +++----- src/stdio/tmpnam.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/stdio/tempnam.c b/src/stdio/tempnam.c index 565df6b6..0c65b1f0 100644 --- a/src/stdio/tempnam.c +++ b/src/stdio/tempnam.c @@ -6,7 +6,6 @@ #include #include #include "syscall.h" -#include "kstat.h" #define MAXTRIES 100 @@ -37,11 +36,10 @@ char *tempnam(const char *dir, const char *pfx) for (try=0; try #include #include "syscall.h" -#include "kstat.h" #define MAXTRIES 100 @@ -17,11 +16,10 @@ char *tmpnam(char *buf) int r; for (try=0; try