From owner-freebsd-bugs@FreeBSD.ORG Mon Jan 3 22:00:52 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D850916A4CF for ; Mon, 3 Jan 2005 22:00:52 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7917F43D45 for ; Mon, 3 Jan 2005 22:00:52 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id j03M0qnD085832 for ; Mon, 3 Jan 2005 22:00:52 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id j03M0qbS085830; Mon, 3 Jan 2005 22:00:52 GMT (envelope-from gnats) Resent-Date: Mon, 3 Jan 2005 22:00:52 GMT Resent-Message-Id: <200501032200.j03M0qbS085830@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Ronald F.Guilmette" Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0404D16A4CE for ; Mon, 3 Jan 2005 21:50:47 +0000 (GMT) Received: from segfault-outgoing-helo.monkeys.com (segfault.monkeys.com [66.60.159.24]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6F03343D1D for ; Mon, 3 Jan 2005 21:50:46 +0000 (GMT) (envelope-from rfg@monkeys.com) Received: by segfault.monkeys.com (Postfix, from userid 1237) id E3B7954A8; Mon, 3 Jan 2005 13:50:45 -0800 (PST) Message-Id: <20050103215045.E3B7954A8@segfault.monkeys.com> Date: Mon, 3 Jan 2005 13:50:45 -0800 (PST) From: "Ronald F.Guilmette" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: rfg@monkeys.com Subject: bin/75767: WANTED: "fdclose" function in libc X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: "Ronald F.Guilmette" List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jan 2005 22:00:53 -0000 >Number: 75767 >Category: bin >Synopsis: WANTED: "fdclose" function in libc >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jan 03 22:00:51 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Ronald F. Guilmette >Release: FreeBSD 4.10-RELEASE i386 >Organization: Infinite Monkeys & Co. >Environment: System: FreeBSD segfault.monkeys.com 4.10-RELEASE FreeBSD 4.10-RELEASE #0: Wed Oct 27 13:02:03 PDT 2004 rfg@segfault.monkeys.com:/usr/src/sys/compile/rfg20041027 i386 >Description: In certain contexts, and when using certain programming styles, it is important to be able to symmetrically "undo" the effects of various calls to various standard library (libc) routines. At present, due to the lack of an "fdclose" primitive in libc, it is not easily possible to symmetrically undo the effects of a call to the "fdopen" function. One may call fclose on an open stdio file pointer, however the fclose function actually has two effects, i.e.: 1) recycling the stdio file descriptor that was allocated by the prior call to fdopen() into the pool of available stdio file descriptors and... 2) calling close(2) on the underlying UNIX file descriptor. Unfortunately, only the first of these two effects actually constitutes a symmetric undo-ing of the actions performed by a call to fdopen. The second effect is an unfortunate (and undesirable) side-effect of fclose in some instances. Thus, it would be useful to have a new function in libc, i.e. an "fdclose" function whose only effect would be to recycle a stdio file descriptor into the pool of free/available stdio file descriptors *without* also closing the underlying UNIX file descriptor. >How-To-Repeat: int fd; FILE *fp; fd = open ("foo", O_RDWR | O_CREAT, 0666); fp = fdopen (fd, "r+"); ... fclose (fp); write (fd, buf, size); /* A problematic error occurs here! */ >Fix: Add a new "fdclose" function to libc. This should have the same effects as fclose, except that it should *not* close the underlying UNIX file descriptor. >Release-Note: >Audit-Trail: >Unformatted: