NetBSD Problem Report #345
From gnats Tue Jul 19 00:36:53 1994
Received: from gabriella.resort.com (root@[165.227.14.70]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id AAA23930 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Tue, 19 Jul 1994 00:36:51 -0700
Message-Id: <199407190740.AAA03556@gabriella.resort.com>
Date: Tue, 19 Jul 1994 00:40:50 -0700
From: banshee@gabriella.resort.com (Robert Dobbs)
Reply-To: banshee@gabriella.resort.com
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: i386 ftruncate() error
X-Send-Pr-Version: 3.2
>Number: 345
>Category: lib
>Synopsis: ftruncate() fails in several scenarios
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: gnats-admin
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jul 19 00:50:04 +0000 1994
>Closed-Date: Wed Jul 20 07:16:40 +0000 1994
>Last-Modified:
>Originator: Robert Dobbs
>Release: supped -current
>Organization:
"Church of the Subgenius"
>Environment:
i386 DX/25, netbsd-current, libc
System: NetBSD gabriella.resort.com 1.0-ALPHA NetBSD 1.0-ALPHA (BANSHEE) #0: Mon Jul 11 22:25:01 PDT 1994 banshee@cooltech.resort.com:/usr/src/sys/arch/i386/compile/BANSHEE i386
>Description:
ftruncate(fileno(fp),0) fails to truncate the file referenced by
fp if:
fp has been written to with fprintf()
fp was opened in "a" or "r+" mode
Always returns -1 and sets errno, even in the "w" no write case
where it truncates the file.
>How-To-Repeat:
/* make ftruncate fail */
#include <stdio.h>
#include <errno.h>
extern int errno;
main()
{
FILE *fp;
fp = fopen("foo","w");
/* comment out fprintf line to make ftruncate work
but it still returns -1 and sets errno. */
fprintf(fp,"Mom loves you");
printf("%d\n", errno);
printf("trunc: %d\n",ftruncate(fileno(fp),10));
printf("%d\n", errno);
fflush(fp);
}
>Fix:
This is a bug in the supplied program. The second argument to
ftruncate() must be an off_t. Therea are several ways to accomplish
this:
* Have a prototype for ftruncate() in scope.
* Cast the argument to off_t explicitly.
* Use a variable or expression which evaluates to an off_t.
At any rate, the supplied program is in error. This is not a bug in
NetBSD. - mycroft
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: mycroft
State-Changed-When: Wed Jul 20 00:16:40 PDT 1994
State-Changed-Why:
This is not a bug in NetBSD; it is a bug in the supplied program.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.