From owner-cvs-all Thu Nov 14 16:33:27 2002 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2411037B401; Thu, 14 Nov 2002 16:33:26 -0800 (PST) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6356943E6E; Thu, 14 Nov 2002 16:33:25 -0800 (PST) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (fledge.pr.watson.org [192.0.2.3]) by fledge.watson.org (8.12.4/8.12.4) with SMTP id gAF0WlOo015317; Thu, 14 Nov 2002 19:32:47 -0500 (EST) (envelope-from robert@fledge.watson.org) Date: Thu, 14 Nov 2002 19:32:46 -0500 (EST) From: Robert Watson X-Sender: robert@fledge.watson.org To: "Bruce A. Mah" Cc: John Baldwin , cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org Subject: Re: cvs commit: src/usr.sbin/pkg_install/lib file.c In-Reply-To: <200211150024.gAF0Oo3A066723@intruder.bmah.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Thu, 14 Nov 2002, Bruce A. Mah wrote: > > Ugh, can't we look at the file header and figure out based on that > > instead? > > I don't like this either, but real autodetection is harder than I wanted > to tackle. My goal was to get a snapshot build that can install > packages. > > After having hacked on unpack() for a while, it's harder than I first > thought. Looking at the first byte of the file is enough to distinguish > the two...if it's '\037', it's gzip; 'B' means bzip2, according to the > source code for file(1). > > You need to peek at the first byte of the file and then put the byte > back (remember this is for a package on stdin). I tried fgetc()/ > ungetc()) for this. I suspect that the character that I put back > doesn't get read by the forked-off gzip or bzip process. Yeah, ungetc() acts on the FILE* libc buffered streams, which means that the character has been read out of the file descriptor and into per-process memory buffering, so is no longer available to other processes. In practice, I think you end up having to create a new pipe and manually buffer the data from the source to gzip/bzip2. Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Network Associates Laboratories To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message