[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Problem with seeking in existing files.

Thomas Morgan

10/30/2003 3:46:00 PM


--- Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Problem with seeking in existing files."
> on 03/10/30, agemoagemo@yahoo.com
> <agemoagemo@yahoo.com> writes:
>
> |I'm trying to write a program that will be writing
> |data to an existing file, that will not necessarily
> be
> |done in the physical file order. I used mode 'ab+'
> to
> |open the file, as only the 'a' modes allow writing
> |without changing the existing file. I am using
> sysread
> |and syswrite to work with the file.
>
> I don't know what platform you are working on. But
> in general, stdio
> does not work well with "a" (append) mode and
> seeking. It's stdio
> restriction.

Win32.

What IO commands should be used with append mode?

-Morgan.

__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/brit...

1 Answer

Martin Weber

10/30/2003 4:01:00 PM

0

On Fri, Oct 31, 2003 at 12:46:20AM +0900, agemoagemo@yahoo.com wrote:
> Win32.
>
> What IO commands should be used with append mode?

Dunno about win32 in general, but why not simply use File.open/new ?


f = File.new("ayaken", File::CREAT|File::RDWR, 0644)
f.puts("banzai!");
f.close
f = File.new("ayaken", File::RDWR)
f.seek(8);
f.puts("ayaken!");

=> ayaken now contains (at least on Unix)
banzai!\n
ayaken!\n

(on windows probably have to seek one further for the \r)

-Martin