Date: Sat, 12 Feb 2011 01:26:09 +0100 From: "Julian H. Stacey" <jhs@berklix.com> To: hackers@freebsd.org Subject: Re: reverse of getchar() read() open() fopen() ? Message-ID: <201102120026.p1C0Q9BW031963@fire.js.berklix.net> In-Reply-To: Your message "Fri, 11 Feb 2011 16:35:06 EST." <AC6674AB7BC78549BB231821ABF7A9AE924A762570@EMBX01-WF.jnpr.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Andrew Duane wrote:
> I've never seen any such thing, but I've done similar things a
> lot. I'd say malloc/read the whole file in and use a decrementing
> pointer to return the "previous" character.
Thanks, but I'll need a loop too, as malloc(filesize()) would be
too big, as I omitted to say I'll be running it from find, reading
all files on system, including DVD images @ 4.7G. Some of my machines
dont have that much swap, let alone RAM :-)
Aside:
I was doing inefficient things here with getchar() (while searching
forward, for a one off run, (CPU cycles were cheaper than brain
cycles, so it was easier to hack a pre-existing prog that used
getchar() ).
I was doing a search for (trailing) nulls blocks, from BSD tar silently
zeroing data from bad media, per
http://lists.freebsd.org/pipermail/freebsd-hackers/2011-January/034254.html
http://www.freebsd.org/cgi/query-pr.cgi?pr=154407
http://berklix.com/~jhs/src/bsd/fixes/FreeBSD/src/gen/usr.bin/tar/
But my search logs from find with
http://berklix.com/~jhs/src/bsd/jhs/bin/public/8f
were too big, so I'll reduce by searching backward & only indexing
on trailing nulls.
Dan Nelson wrote:
> You might even be able to write functions that could be passed to funopen().
> Then you'd have a regular FILE* that you could call with regular stdio
> functions. Getting the buffering right for good performance might get
> tricky, though.
Thanks, I didnt know funopen, I'll read it again tomorrow morning :-)
Thanks to Devin Teske re src/usr.bin/tail/,
sorry in my first post I forgot to say binary.
Brian Reichert wrote:
> Use lseek() to position yourself, iterate over the file, copying into a
> small buffer, then iterate over your buffer in reverse?
Yes, thanks, better for efficiency, being lazy I had first
wondered if there was some fopen_starting_from_tail()
& getchar_starting_from_tail() I could just call for aone off run :-)
Thanks all.
Cheers,
Julian
--
Julian Stacey, BSD Unix Linux C Sys Eng Consultants Munich http://berklix.com
Mail plain text; Not quoted-printable, Not HTML, Not base 64.
Reply below text sections not at top, to avoid breaking cumulative context.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102120026.p1C0Q9BW031963>
