Need efficient way to read file in reverse

Dave Jenks jetfuel at csusac.csus.edu
Wed Sep 19 15:58:46 AEST 1990


In article <1990Sep18.152818.1303 at phri.nyu.edu> roy at alanine.phri.nyu.edu (Roy Smith) writes:
>	Is there a standard, portable, efficient way to read a file in
>reverse?  I'm doing random seeks in a file and occassionally want to be able
>to find the beginning of the line into the middle of which I just seeked.
>Right now, I'm using a simple-minded revgetc() I wrote which is basically:

I had to do the very same thing a number of years ago.  The most
efficient method was to read using read(2) for BLKSIZ bytes (#defined
in <stdio.h> or <stand.h> or someplace like that) and search the
buffer manually.  With a simple searching algorithm, this can be very
fast - even with a poor algorithm, it'll still be much faster than
asking for i/o for each character.  It's even portable.
-- 
=======================================================================
	    "Pro is to con, as progress is to Congress..."
                                                                      
                                           ...!uunet \



More information about the Comp.unix.internals mailing list