From: djberg96@... (Daniel Berger) Date: 2004-11-16T04:28:20+09:00 Subject: Re: Win32, file descriptors and rb_io_check_writable() "Park Heesob" wrote in message news:<003c01c4c91f$1c2718f0$bcdefea9@2xnm9896kmqn5b9>... > > > Following code will work: > > #define OpenFile WINAPI_OpenFile > #include > .. > #undef OpenFile > #include "ruby.h" > #include "rubyio.h" > .. > // Convert HANDLE to file descriptor > args[0] = UINT2NUM(_open_osfhandle((long)h,O_RDWR)); > > RFILE(self)->fptr->mode = rb_io_mode_flags("w+"); // mode string correspond to dwAccess > RFcorrespond to dwAccess > > // Return a bonafide File object, based on the file descriptor > return rb_class_new_instance(1,args,rb_cFile); > } > > Regards, > > Park Heesob Thank you very much Park. There is one curious difference I noticed with the write operations. It seems that there is a line ending issue between a file descriptor opened with File.open vs File.nopen. You can see this easily enough by doing something like this: fh1 = File.open("test1.txt","w+") fh1.print "hello\nworld\n" fh1.close Open this up with notepad - looks fine. Now try this: fh2 = File.nopen("test2.txt",nil,nil,File::OPEN_ALWAYS) fh2.print "hello\nworld\n" fh2.close Opened with notepad, you'll see that the line endings aren't the same (although wordpad handles them properly). I guess I should find an octal dump tool for windows to verify. Hopefully, you'll see what I mean. Regards, Dan