Subject: lib/345: i386 ftruncate() error
To: None <gnats-admin>
From: Robert Dobbs <>
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
"Church of the Subgenius"
>Release:        supped -current
i386 DX/25, netbsd-current, libc
System: NetBSD 1.0-ALPHA NetBSD 1.0-ALPHA (BANSHEE) #0: Mon Jul 11 22:25:01 PDT 1994 i386

	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.

/* make ftruncate fail */
#include <stdio.h>
#include <errno.h>
extern int errno;

        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);