Date: Wed, 12 Mar 1997 14:58:08 -0500 (EST) From: Rick Ace <rick@softport.nyc.ny.us> To: FreeBSD-gnats-submit@freebsd.org Subject: kern/2966: ftruncate() problem in FreeBSD 2.1.7-RELEASE i386 Message-ID: <199703121958.OAA16037@softport.nyc.ny.us> Resent-Message-ID: <199703122010.MAA08541@freefall.freebsd.org>
index | next in thread | raw e-mail
>Number: 2966
>Category: kern
>Synopsis: ftruncate() fails unexpectedly
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Mar 12 12:10:01 PST 1997
>Last-Modified:
>Originator: Rick Ace
>Organization:
Softport Systems Inc. New York, NY 10016
>Release: FreeBSD 2.1.7-RELEASE i386
>Environment:
486/50
nonprivileged user application
>Description:
ftruncate() fails with error (EINVAL) when called to truncate
a file whose descriptor is open for read and write.
It should succeed.
>How-To-Repeat:
/*
* demonstrate ftruncate() bug in freebsd
* (this same code runs without problems on both Solaris 2.5 and HP-UX 10)
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
static char tmp_path[] = "/tmp/tbug";
static void try_truncate();
int main()
{
int fd;
(void) unlink(tmp_path);
/* create new, empty file open for read/write */
if ((fd = open(tmp_path, O_RDWR | O_CREAT, 0600)) < 0) {
perror("open");
return 1;
}
try_truncate(fd); /* try on empty file */
printf("write() returns %d\n", write(fd, "xxx", 3));
try_truncate(fd); /* try on non-empty file */
(void) unlink(tmp_path);
return 0;
}
static void try_truncate(fd)
int fd;
{
int e;
e = ftruncate(fd, 0);
if (e < 0) {
fprintf(stderr, "[errno=%d] ", errno);
perror("ftruncate");
}
else {
fprintf(stderr, "ok\n");
}
}
>Fix:
None reported.
>Audit-Trail:
>Unformatted:
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199703121958.OAA16037>
