Subject: lib/345: i386 ftruncate() error
To: None <gnats-admin>
From: Robert Dobbs <banshee@gabriella.resort.com>
List: netbsd-bugs
Date: 07/19/1994 00:50:05
>Number:         345
>Category:       lib
>Synopsis:       ftruncate() fails in several scenarios
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 19 00:50:04 1994
>Originator:     Robert Dobbs
>Organization:
"Church of the Subgenius"
>Release:        supped -current
>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:
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------