From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 11 22:04:37 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 CB76E106564A for ; Fri, 11 Feb 2011 22:04:37 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email2.allantgroup.com (email2.emsphone.com [199.67.51.116]) by mx1.freebsd.org (Postfix) with ESMTP id 7793D8FC17 for ; Fri, 11 Feb 2011 22:04:37 +0000 (UTC) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email2.allantgroup.com (8.14.4/8.14.4) with ESMTP id p1BLjse2081684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Feb 2011 15:45:55 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.4/8.14.4) with ESMTP id p1BLjsfx037944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Feb 2011 15:45:54 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.4/8.14.4/Submit) id p1BLjrXJ037943; Fri, 11 Feb 2011 15:45:54 -0600 (CST) (envelope-from dan) Date: Fri, 11 Feb 2011 15:45:53 -0600 From: Dan Nelson To: "Julian H. Stacey" Message-ID: <20110211214553.GH66849@dan.emsphone.com> References: <201102112132.p1BLWkiP003000@fire.js.berklix.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201102112132.p1BLWkiP003000@fire.js.berklix.net> X-OS: FreeBSD 8.2-PRERELEASE User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: clamav-milter 0.96.4 at email2.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.6 (email2.allantgroup.com [199.67.51.78]); Fri, 11 Feb 2011 15:45:55 -0600 (CST) X-Scanned-By: MIMEDefang 2.68 on 199.67.51.78 Cc: hackers@freebsd.org 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: Fri, 11 Feb 2011 22:04:37 -0000 In the last episode (Feb 11), Julian H. Stacey said: > Hi hackers@, > Do we have C libraries with reverse of getchar() [ & maybe read() ] & > fopen() [ & maybe open() ] etc, to read from end of file toward beginning > ? I dont see anything in the See Also sections. I'm not looking to > write, just read. I'm looking for something that returns last char in > file as first etc, I'm not interested in wchars etc, I could write some C > functions, with seek etc & probably will, if none exist, but no point if > they already exist ? tail -r does this on a line-by-line basis. Tail does it for regular files by mmaping and then reading backwards, but you could also read the block of data at (filesize MOD buffersize) and return its bytes in reverse order, then seek back buffersize bytes, read that block and print it reversed, etc. 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. -- Dan Nelson dnelson@allantgroup.com