From 14192f5767b3388d9f6a1cdc8cadfb047b7a1f6a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 11 Apr 2017 16:31:27 +0200 Subject: Close files before renaming or unlinking them On windows we cannot rename or unlink open files. Change-Id: Ieae8712266a3e65217580d4936219767c5f26f21 Reviewed-by: Christian Kandeler --- tests/ChangeLog | 9 +++++++++ tests/newfile.c | 7 +++++-- tests/newscn.c | 3 ++- tests/update1.c | 1 + tests/update2.c | 1 + tests/update3.c | 1 + tests/update4.c | 1 + 7 files changed, 20 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index 5e29f821..b8de1386 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2017-05-04 Ulf Hermann + + * newfile.c: Close the file when we're done and unlink it afterwards. + * newscn.c: Likewise. + * update1.c: Likewise. + * update2.c: Likewise. + * update3.c: Likewise. + * update4.c: Likewise. + 2017-05-04 Ulf Hermann * asm-tst4.c: Don't assume unix file system conventions. diff --git a/tests/newfile.c b/tests/newfile.c index 5eabdcb7..a2793171 100644 --- a/tests/newfile.c +++ b/tests/newfile.c @@ -63,8 +63,6 @@ main (int argc, char *argv[] __attribute__ ((unused))) printf ("cannot create temporary file: %m\n"); exit (1); } - /* Remove the file when we exit. */ - unlink (fname); elf_version (EV_CURRENT); elf = elf_begin (fd, ELF_C_WRITE, NULL); @@ -166,5 +164,10 @@ main (int argc, char *argv[] __attribute__ ((unused))) (void) elf_end (elf); } + close (fd); + + /* Remove the file when we exit. */ + unlink (fname); + return result; } diff --git a/tests/newscn.c b/tests/newscn.c index 466f2f68..de8951df 100644 --- a/tests/newscn.c +++ b/tests/newscn.c @@ -46,7 +46,6 @@ main (void) fprintf (stderr, "Failed to open fdput file: %s\n", name); exit (1); } - unlink (name); elf = elf_begin (fd, ELF_C_WRITE, NULL); if (elf == NULL) @@ -62,5 +61,7 @@ main (void) elf_end (elf); close (fd); + unlink (name); + return 0; } diff --git a/tests/update1.c b/tests/update1.c index a5716185..548c6d8a 100644 --- a/tests/update1.c +++ b/tests/update1.c @@ -121,6 +121,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) exit (1); } + close (fd); unlink (fname); return 0; diff --git a/tests/update2.c b/tests/update2.c index 3e228796..1dcff3fc 100644 --- a/tests/update2.c +++ b/tests/update2.c @@ -144,6 +144,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) exit (1); } + close (fd); unlink (fname); return 0; diff --git a/tests/update3.c b/tests/update3.c index d619bed0..9d4f8809 100644 --- a/tests/update3.c +++ b/tests/update3.c @@ -199,6 +199,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) exit (1); } + close (fd); unlink (fname); return 0; diff --git a/tests/update4.c b/tests/update4.c index 8196b8c8..a762e0a0 100644 --- a/tests/update4.c +++ b/tests/update4.c @@ -351,6 +351,7 @@ main (int argc, char *argv[] __attribute__ ((unused))) exit (1); } + close (fd); unlink (fname); return 0; -- cgit v1.2.3