Re: reverse of getchar() read() open() fopen() ?

看板FB_hackers作者時間15年前 (2011/02/12 06:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/4 (看更多)
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 _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
文章代碼(AID): #1DLRZYAR (FB_hackers)
文章代碼(AID): #1DLRZYAR (FB_hackers)