From patchwork Thu Nov 27 12:08:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 415473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 97E0B1401F6 for ; Thu, 27 Nov 2014 23:09:15 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=QbCR J0eW8pVWboUYOPMJ/PwHH0px7378z6hraF3g9H3BYdNnIaf5Mp7WF8mII4L2ogOy BJVmYq/U46QGfOOErRMGE1siui4LLqQClydRKpHrRKGzLn8HEIvYq9uyzNSyfdkO hWpid00tSFhgUzMpkPpYymZSNEDJPz931D8/iq8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=PjXgSLFrlR kaivtpiF9oggjGjU4=; b=Mu6fhsHIlBgL/DbEsHkXqJ2iv/x0tF9OjFsoHnZ266 /tFQFe6HP6Rzn2EmO/wjdEbruI1XUYd38OkEDDh3yuOFq0QxzcxSExEWnCsWwdNE hSKIQsZtOgaf4ouqeOdZgMkD1rdGJU8jtesf4sEKNsvo10ypv7YkB7hRo/o14eWO 8= Received: (qmail 3025 invoked by alias); 27 Nov 2014 12:09:08 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3014 invoked by uid 89); 27 Nov 2014 12:09:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Thu, 27 Nov 2014 17:38:56 +0530 From: Siddhesh Poyarekar To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: [PATCH v2] tst-ftell-active-handler: Open file with O_TRUNC for w modes Message-ID: <20141127120856.GO25419@spoyarek.pnq.redhat.com> References: <20141127092833.GA5527@spoyarek.pnq.redhat.com> <871toox5l5.fsf@igel.home> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <871toox5l5.fsf@igel.home> User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) On Thu, Nov 27, 2014 at 12:09:42PM +0100, Andreas Schwab wrote: > Siddhesh Poyarekar 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 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} };