* [PATCH] tst-ftell-active-handler: Open file with O_TRUNC for w+ mode
@ 2014-11-27 9:28 Siddhesh Poyarekar
2014-11-27 11:09 ` Andreas Schwab
0 siblings, 1 reply; 4+ messages in thread
From: Siddhesh Poyarekar @ 2014-11-27 9:28 UTC (permalink / raw)
To: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 1963 bytes --]
The test case fails to truncate the file when a file is intended to be
opened in w+ mode. Add O_TRUNC to fix this. The test still succeeds
with this change.
OK to commit?
Siddhesh
* libio/tst-ftell-active-handler.c (do_ftruncate_test): Add
O_TRUNC flag for w+ mode.
(do_rewind_test): Likewise.
(do_ftell_test): Likewise.
(do_write_test): Likewise.
---
libio/tst-ftell-active-handler.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libio/tst-ftell-active-handler.c b/libio/tst-ftell-active-handler.c
index 9f23c55..5922bb5 100644
--- a/libio/tst-ftell-active-handler.c
+++ b/libio/tst-ftell-active-handler.c
@@ -105,7 +105,7 @@ do_ftruncate_test (const char *filename)
} test_modes[] = {
{"r+", O_RDWR},
{"w", O_WRONLY},
- {"w+", O_RDWR},
+ {"w+", O_RDWR | O_TRUNC},
{"a", O_WRONLY},
{"a+", O_RDWR}
};
@@ -190,7 +190,7 @@ do_rewind_test (const char *filename)
size_t new_off;
} test_modes[] = {
{"w", O_WRONLY, 0, data_len},
- {"w+", O_RDWR, 0, data_len},
+ {"w+", O_RDWR | O_TRUNC, 0, data_len},
{"r+", O_RDWR, 0, data_len},
/* The new offsets for 'a' and 'a+' modes have to factor in the
previous writes since they always append to the end of the
@@ -295,7 +295,7 @@ do_ftell_test (const char *filename)
beginning of the file. After the write, the offset should be
updated to data_len. */
{"w", O_WRONLY, 0, data_len},
- {"w+", O_RDWR, 0, data_len},
+ {"w+", O_RDWR | O_TRUNC, 0, data_len},
{"r+", O_RDWR, 0, data_len},
/* For the 'a' mode, the initial file position should be the
current end of file. After the write, the offset has data_len
@@ -376,7 +376,7 @@ do_write_test (const char *filename)
int fd_mode;
} test_modes[] = {
{"w", O_WRONLY},
- {"w+", O_RDWR},
+ {"w+", O_RDWR | O_TRUNC},
{"r+", O_RDWR}
};
--
1.9.3
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tst-ftell-active-handler: Open file with O_TRUNC for w+ mode
2014-11-27 9:28 [PATCH] tst-ftell-active-handler: Open file with O_TRUNC for w+ mode Siddhesh Poyarekar
@ 2014-11-27 11:09 ` Andreas Schwab
2014-11-27 12:09 ` [PATCH v2] tst-ftell-active-handler: Open file with O_TRUNC for w modes Siddhesh Poyarekar
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2014-11-27 11:09 UTC (permalink / raw)
To: Siddhesh Poyarekar; +Cc: libc-alpha
Siddhesh Poyarekar <siddhesh@redhat.com> writes:
> The test case fails to truncate the file when a file is intended to be
> opened in w+ mode. Add O_TRUNC to fix this. The test still succeeds
> with this change.
What about the w mode?
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] tst-ftell-active-handler: Open file with O_TRUNC for w modes
2014-11-27 11:09 ` Andreas Schwab
@ 2014-11-27 12:09 ` Siddhesh Poyarekar
2014-11-27 15:28 ` Andreas Schwab
0 siblings, 1 reply; 4+ messages in thread
From: Siddhesh Poyarekar @ 2014-11-27 12:09 UTC (permalink / raw)
To: Andreas Schwab; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 2812 bytes --]
On Thu, Nov 27, 2014 at 12:09:42PM +0100, Andreas Schwab wrote:
> Siddhesh Poyarekar <siddhesh@redhat.com> writes:
>
> > The test case fails to truncate the file when a file is intended to be
> > opened in w+ mode. Add O_TRUNC to fix this. The test still succeeds
> > with this change.
>
> What about the w mode?
Ugh, I assumed O_WRONLY truncates, which is obviously wrong. Updated
patch, tested to verify that it doesn't break the test.
Siddhesh
* libio/tst-ftell-active-handler.c (do_ftruncate_test): Add
O_TRUNC flag for w and w+ modes.
(do_rewind_test): Likewise.
(do_ftell_test): Likewise.
(do_write_test): Likewise.
commit a4585b19a10994b7462bf21f945966a270a18140
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Thu Nov 27 17:31:58 2014 +0530
tst-ftell-active-handler: Open file with O_TRUNC for w modes
The test case fails to truncate the file when a file is intended to be
opened in w or w+ mode. Add O_TRUNC to fix this. The test still
succeeds with this change.
diff --git a/libio/tst-ftell-active-handler.c b/libio/tst-ftell-active-handler.c
index 9f23c55..72066b4 100644
--- a/libio/tst-ftell-active-handler.c
+++ b/libio/tst-ftell-active-handler.c
@@ -104,8 +104,8 @@ do_ftruncate_test (const char *filename)
int fd_mode;
} test_modes[] = {
{"r+", O_RDWR},
- {"w", O_WRONLY},
- {"w+", O_RDWR},
+ {"w", O_WRONLY | O_TRUNC},
+ {"w+", O_RDWR | O_TRUNC},
{"a", O_WRONLY},
{"a+", O_RDWR}
};
@@ -189,8 +189,8 @@ do_rewind_test (const char *filename)
size_t old_off;
size_t new_off;
} test_modes[] = {
- {"w", O_WRONLY, 0, data_len},
- {"w+", O_RDWR, 0, data_len},
+ {"w", O_WRONLY | O_TRUNC, 0, data_len},
+ {"w+", O_RDWR | O_TRUNC, 0, data_len},
{"r+", O_RDWR, 0, data_len},
/* The new offsets for 'a' and 'a+' modes have to factor in the
previous writes since they always append to the end of the
@@ -294,8 +294,8 @@ do_ftell_test (const char *filename)
/* In w, w+ and r+ modes, the file position should be at the
beginning of the file. After the write, the offset should be
updated to data_len. */
- {"w", O_WRONLY, 0, data_len},
- {"w+", O_RDWR, 0, data_len},
+ {"w", O_WRONLY | O_TRUNC, 0, data_len},
+ {"w+", O_RDWR | O_TRUNC, 0, data_len},
{"r+", O_RDWR, 0, data_len},
/* For the 'a' mode, the initial file position should be the
current end of file. After the write, the offset has data_len
@@ -375,8 +375,8 @@ do_write_test (const char *filename)
const char *mode;
int fd_mode;
} test_modes[] = {
- {"w", O_WRONLY},
- {"w+", O_RDWR},
+ {"w", O_WRONLY | O_TRUNC},
+ {"w+", O_RDWR | O_TRUNC},
{"r+", O_RDWR}
};
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] tst-ftell-active-handler: Open file with O_TRUNC for w modes
2014-11-27 12:09 ` [PATCH v2] tst-ftell-active-handler: Open file with O_TRUNC for w modes Siddhesh Poyarekar
@ 2014-11-27 15:28 ` Andreas Schwab
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2014-11-27 15:28 UTC (permalink / raw)
To: Siddhesh Poyarekar; +Cc: libc-alpha
Ok.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-27 15:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-27 9:28 [PATCH] tst-ftell-active-handler: Open file with O_TRUNC for w+ mode Siddhesh Poyarekar
2014-11-27 11:09 ` Andreas Schwab
2014-11-27 12:09 ` [PATCH v2] tst-ftell-active-handler: Open file with O_TRUNC for w modes Siddhesh Poyarekar
2014-11-27 15:28 ` Andreas Schwab
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).