From owner-freebsd-bugs Wed Mar 12 12:10:08 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id MAA08557 for bugs-outgoing; Wed, 12 Mar 1997 12:10:08 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id MAA08541; Wed, 12 Mar 1997 12:10:03 -0800 (PST) Resent-Date: Wed, 12 Mar 1997 12:10:03 -0800 (PST) Resent-Message-Id: <199703122010.MAA08541@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, Received:"from news2.panix.com (news2.panix.com [166.84.0.221]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id MAA08192 for" ; Wed, 12 Mar 1997 12:01:15.-0800 (PST) Received: (from uucp@localhost) by news2.panix.com (8.6.10/8.6.12+PanixU1.1) with UUCP id PAA27479 for FreeBSD-gnats-submit@freebsd.org; Wed, 12 Mar 1997 15:01:08 -0500 Received: (from rick@localhost) by softport.nyc.ny.us (8.8.5/8.8.5) id OAA16037; Wed, 12 Mar 1997 14:58:08 -0500 (EST) Message-Id: <199703121958.OAA16037@softport.nyc.ny.us> Date: Wed, 12 Mar 1997 14:58:08 -0500 (EST) From: Rick Ace To: FreeBSD-gnats-submit@freebsd.org Subject: kern/2966: ftruncate() problem in FreeBSD 2.1.7-RELEASE i386 Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >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 #include #include #include #include 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: