From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 12 00:26:02 2011 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E08D51065670 for ; Sat, 12 Feb 2011 00:26:02 +0000 (UTC) (envelope-from jhs@berklix.com) Received: from tower.berklix.org (tower.berklix.org [83.236.223.114]) by mx1.freebsd.org (Postfix) with ESMTP id 4FEC38FC15 for ; Sat, 12 Feb 2011 00:26:01 +0000 (UTC) Received: from park.js.berklix.net (p5B22E7EC.dip.t-dialin.net [91.34.231.236]) (authenticated bits=0) by tower.berklix.org (8.14.2/8.14.2) with ESMTP id p1C0PxBa021869 for ; Sat, 12 Feb 2011 00:26:00 GMT (envelope-from jhs@berklix.com) Received: from fire.js.berklix.net (fire.js.berklix.net [192.168.91.41]) by park.js.berklix.net (8.13.8/8.13.8) with ESMTP id p1C0QEZI012845 for ; Sat, 12 Feb 2011 01:26:14 +0100 (CET) (envelope-from jhs@berklix.com) Received: from fire.js.berklix.net (localhost [127.0.0.1]) by fire.js.berklix.net (8.14.3/8.14.3) with ESMTP id p1C0Q9BW031963 for ; Sat, 12 Feb 2011 01:26:14 +0100 (CET) (envelope-from jhs@fire.js.berklix.net) Message-Id: <201102120026.p1C0Q9BW031963@fire.js.berklix.net> To: hackers@freebsd.org From: "Julian H. Stacey" Organization: http://www.berklix.com BSD Unix Linux Consultancy, Munich Germany User-agent: EXMH on FreeBSD http://www.berklix.com/free/ X-URL: http://www.berklix.com In-reply-to: Your message "Fri, 11 Feb 2011 16:35:06 EST." Date: Sat, 12 Feb 2011 01:26:09 +0100 Sender: jhs@berklix.com Cc: Subject: Re: reverse of getchar() read() open() fopen() ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Feb 2011 00:26:03 -0000 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.