* [PATCH] support_create_temp_directory: Align behavior with create_temp_file
@ 2017-11-17 14:55 Florian Weimer
2017-11-17 17:22 ` Jonathan Nieder
0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2017-11-17 14:55 UTC (permalink / raw)
To: libc-alpha
create_temp_file automatically supplies the test directory and the
XXXXXX suffix. support_create_temp_directory required the caller to
specify them, which was confusing.
2017-11-17 Florian Weimer <fweimer@redhat.com>
* support/temp_file.c (support_create_temp_directory): Use
test_dir and do not rely on the presence of the XXXXXX suffix.
* support/temp_file.h (support_create_temp_directory): Update
comment.
* support/tst-xreadlink.c (do_test): Adjust.
diff --git a/support/temp_file.c b/support/temp_file.c
index cbd54e2e17..547263a3e4 100644
--- a/support/temp_file.c
+++ b/support/temp_file.c
@@ -89,14 +89,14 @@ create_temp_file (const char *base, char **filename)
char *
support_create_temp_directory (const char *base)
{
- char *base_copy = xstrdup (base);
- if (mkdtemp (base_copy) == NULL)
+ char *path = xasprintf ("%s/%sXXXXXX", test_dir, base);
+ if (mkdtemp (path) == NULL)
{
- printf ("error: mkdtemp (\"%s\"): %m", base);
+ printf ("error: mkdtemp (\"%s\"): %m", path);
exit (1);
}
- add_temp_file (base_copy);
- return base_copy;
+ add_temp_file (path);
+ return path;
}
/* Helper functions called by the test skeleton follow. */
diff --git a/support/temp_file.h b/support/temp_file.h
index dfefe585de..3b8563e115 100644
--- a/support/temp_file.h
+++ b/support/temp_file.h
@@ -32,9 +32,9 @@ void add_temp_file (const char *name);
*FILENAME. */
int create_temp_file (const char *base, char **filename);
-/* Create a temporary directory and schedule it for deletion. BASE
- must end with the six characters "XXXXXX". Return the name of the
- temporary directory. The caller should free the string. */
+/* Create a temporary directory and schedule it for deletion. BASE is
+ used as a prefix for the unique directory name, which the function
+ returns. The caller should free this string. */
char *support_create_temp_directory (const char *base);
__END_DECLS
diff --git a/support/tst-xreadlink.c b/support/tst-xreadlink.c
index cb2c12a888..a4a22812c1 100644
--- a/support/tst-xreadlink.c
+++ b/support/tst-xreadlink.c
@@ -29,7 +29,7 @@
static int
do_test (void)
{
- char *dir = support_create_temp_directory ("/tmp/tst-xreadlink-XXXXXX");
+ char *dir = support_create_temp_directory ("tst-xreadlink-");
char *symlink_name = xasprintf ("%s/symlink", dir);
add_temp_file (symlink_name);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] support_create_temp_directory: Align behavior with create_temp_file
2017-11-17 14:55 [PATCH] support_create_temp_directory: Align behavior with create_temp_file Florian Weimer
@ 2017-11-17 17:22 ` Jonathan Nieder
2017-11-18 12:38 ` Florian Weimer
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Nieder @ 2017-11-17 17:22 UTC (permalink / raw)
To: Florian Weimer; +Cc: libc-alpha
Florian Weimer wrote:
> create_temp_file automatically supplies the test directory and the
> XXXXXX suffix. support_create_temp_directory required the caller to
> specify them, which was confusing.
>
> 2017-11-17 Florian Weimer <fweimer@redhat.com>
>
> * support/temp_file.c (support_create_temp_directory): Use
> test_dir and do not rely on the presence of the XXXXXX suffix.
> * support/temp_file.h (support_create_temp_directory): Update
> comment.
> * support/tst-xreadlink.c (do_test): Adjust.
Makes sense.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] support_create_temp_directory: Align behavior with create_temp_file
2017-11-17 17:22 ` Jonathan Nieder
@ 2017-11-18 12:38 ` Florian Weimer
0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2017-11-18 12:38 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 704 bytes --]
On 11/17/2017 06:22 PM, Jonathan Nieder wrote:
> Florian Weimer wrote:
>
>> create_temp_file automatically supplies the test directory and the
>> XXXXXX suffix. support_create_temp_directory required the caller to
>> specify them, which was confusing.
>>
>> 2017-11-17 Florian Weimer <fweimer@redhat.com>
>>
>> * support/temp_file.c (support_create_temp_directory): Use
>> test_dir and do not rely on the presence of the XXXXXX suffix.
>> * support/temp_file.h (support_create_temp_directory): Update
>> comment.
>> * support/tst-xreadlink.c (do_test): Adjust.
>
> Makes sense.
I missed another call in support_chroot_create, so I'm checking in the
attached version instead.
Thanks,
Florian
[-- Attachment #2: tempdir.patch --]
[-- Type: text/x-patch, Size: 3300 bytes --]
Subject: [PATCH] support_create_temp_directory: Align behavior with create_temp_file
To: libc-alpha@sourceware.org
create_temp_file automatically supplies the test directory and the
XXXXXX suffix. support_create_temp_directory required the caller to
specify them, which was confusing.
2017-11-18 Florian Weimer <fweimer@redhat.com>
* support/temp_file.c (support_create_temp_directory): Use
test_dir and do not rely on the presence of the XXXXXX suffix.
* support/temp_file.h (support_create_temp_directory): Update
comment.
* support/tst-xreadlink.c (do_test): Adjust.
* support/support_chroot.c (support_chroot_create): Likewise.
diff --git a/support/support_chroot.c b/support/support_chroot.c
index f6fad18f33..693813f694 100644
--- a/support/support_chroot.c
+++ b/support/support_chroot.c
@@ -45,12 +45,7 @@ struct support_chroot *
support_chroot_create (struct support_chroot_configuration conf)
{
struct support_chroot *chroot = xmalloc (sizeof (*chroot));
-
- {
- char *template = xasprintf ("%s/tst-resolv-res_init-XXXXXX", test_dir);
- chroot->path_chroot = support_create_temp_directory (template);
- free (template);
- }
+ chroot->path_chroot = support_create_temp_directory ("tst-resolv-res_init-");
/* Create the /etc directory in the chroot environment. */
char *path_etc = xasprintf ("%s/etc", chroot->path_chroot);
diff --git a/support/temp_file.c b/support/temp_file.c
index cbd54e2e17..547263a3e4 100644
--- a/support/temp_file.c
+++ b/support/temp_file.c
@@ -89,14 +89,14 @@ create_temp_file (const char *base, char **filename)
char *
support_create_temp_directory (const char *base)
{
- char *base_copy = xstrdup (base);
- if (mkdtemp (base_copy) == NULL)
+ char *path = xasprintf ("%s/%sXXXXXX", test_dir, base);
+ if (mkdtemp (path) == NULL)
{
- printf ("error: mkdtemp (\"%s\"): %m", base);
+ printf ("error: mkdtemp (\"%s\"): %m", path);
exit (1);
}
- add_temp_file (base_copy);
- return base_copy;
+ add_temp_file (path);
+ return path;
}
/* Helper functions called by the test skeleton follow. */
diff --git a/support/temp_file.h b/support/temp_file.h
index dfefe585de..3b8563e115 100644
--- a/support/temp_file.h
+++ b/support/temp_file.h
@@ -32,9 +32,9 @@ void add_temp_file (const char *name);
*FILENAME. */
int create_temp_file (const char *base, char **filename);
-/* Create a temporary directory and schedule it for deletion. BASE
- must end with the six characters "XXXXXX". Return the name of the
- temporary directory. The caller should free the string. */
+/* Create a temporary directory and schedule it for deletion. BASE is
+ used as a prefix for the unique directory name, which the function
+ returns. The caller should free this string. */
char *support_create_temp_directory (const char *base);
__END_DECLS
diff --git a/support/tst-xreadlink.c b/support/tst-xreadlink.c
index cb2c12a888..a4a22812c1 100644
--- a/support/tst-xreadlink.c
+++ b/support/tst-xreadlink.c
@@ -29,7 +29,7 @@
static int
do_test (void)
{
- char *dir = support_create_temp_directory ("/tmp/tst-xreadlink-XXXXXX");
+ char *dir = support_create_temp_directory ("tst-xreadlink-");
char *symlink_name = xasprintf ("%s/symlink", dir);
add_temp_file (symlink_name);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-18 12:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-17 14:55 [PATCH] support_create_temp_directory: Align behavior with create_temp_file Florian Weimer
2017-11-17 17:22 ` Jonathan Nieder
2017-11-18 12:38 ` Florian Weimer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).