From owner-cvs-all Fri Sep 7 11:53:13 2001 Delivered-To: cvs-all@freebsd.org Received: from nagual.pp.ru (pobrecita.freebsd.ru [194.87.13.42]) by hub.freebsd.org (Postfix) with ESMTP id B4FFF37B405; Fri, 7 Sep 2001 11:53:03 -0700 (PDT) Received: (from ache@localhost) by nagual.pp.ru (8.11.6/8.11.6) id f87Iqs806453; Fri, 7 Sep 2001 22:52:54 +0400 (MSD) (envelope-from ache) Date: Fri, 7 Sep 2001 22:52:53 +0400 From: "Andrey A. Chernov" To: Brian Somers Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/lib/libc/stdio stdio.c Message-ID: <20010907225253.A6238@nagual.pp.ru> References: <200109071716.f87HG3a05025@freefall.freebsd.org> <200109071826.f87IQtJ20155@hak.lan.Awfulhak.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200109071826.f87IQtJ20155@hak.lan.Awfulhak.org> User-Agent: Mutt/1.3.21i Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, Sep 07, 2001 at 19:26:55 +0100, Brian Somers wrote: > Will the following code work ? > > fd = socket(blah); > connect(fd, blah); > dup2(fd, STDIN_FILENO); > fp = fopen(fd, "a+"); > fputc('x', fp); > close(STDIN_FILENO); > open("myfile", O_RDWR|O_APPEND); /* file contains data */ > fseek(fp, 0, SEEK_SET); > fputs("hello world\n", fp); > > or will it end up not attempting to seek to the end of the file and > overwriting from offset 0 ? Short answer: it ends up to seek to the end and overwriting from the offset 0. Long answer: yes, in this particular case old code sense file handle changing on the fly because it not cache result, but this is not true in too many other places in stdio. In general stdio NOT works with file handle changing on the fly because it cache too many data it sense once (file offset, file type, etc.), so your example code is incorrect, you need separate fdopen() for each new file handle. -- Andrey A. Chernov http://ache.pp.ru/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message