Regarding the code, below -- perhaps I'm missing something, but why not
use fseek?  There should be no problem fseeking *forward* in either a file
or a pipe.  It's seeking *backward* which is a problem, and there is no
way to solve that problem without buffering the file from the start.

fseek is pretty much guaranteed to be more efficient than the combination
of malloc/fread/free, below.  As demonstrated, it's also less prone to
bugs.

Am I completely missing the point?

Tim.

On Thu, 28 Oct 1999, Kimmo Mustonen wrote:

> On Wed, 27 Oct 1999, Ilana Rudnik wrote:
> 
> > > int fskip(FILE *sf,long num_bytes,int dummy)
> > > {
> > > char *data = (char *) malloc(num_bytes);
> > > return (num_bytes != fread(data,(size_t)1,(size_t)num_bytes,sf));
> > > free(data);
> > > }
> > > =======
> > I don't know if this is the literal code, or just a snip...
> > If it is literal, you'll have to do this a little differently cause you are
> > returning before you free the malloced space.  Memory leak!
> 
> ...and using the allocated memory without bothering to check whether the
> allocation was successful or not.
> 
> Well as this was only a quick fix this just might be acceptable but
> checking it really isn't too much work.
> 
> Regards,
> Kimmo Mustonen
> 
> 
> --
> MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )
> 

--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to