[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <ce614760ad99dfd4817ce52c90d17d2ea4174f36.1688078605.git.falcon@tinylab.org>
Date: Fri, 30 Jun 2023 07:54:35 +0800
From: Zhangjin Wu <falcon@...ylab.org>
To: thomas@...ch.de, w@....eu
Cc: falcon@...ylab.org, arnd@...db.de, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org
Subject: [PATCH v2 12/15] selftests/nolibc: add common get_tmpfile()
allow create and get a temporary file from tmpfs.
Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
---
tools/testing/selftests/nolibc/nolibc-test.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 8e3e2792f5e3..1002e0267515 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -54,6 +54,23 @@ struct test {
int (*func)(int min, int max); /* handler */
};
+static const char *get_tmpfile(const char *tmpfile)
+{
+ struct stat stat_buf;
+ int fd;
+
+ if (stat(tmpfile, &stat_buf) == 0)
+ return tmpfile;
+
+ fd = open(tmpfile, O_CREAT, 0600);
+ if (fd != -1) {
+ close(fd);
+ return tmpfile;
+ }
+
+ return NULL;
+}
+
#ifndef _NOLIBC_STDLIB_H
char *itoa(int i)
{
--
2.25.1
Powered by blists - more mailing lists