Date: Thu, 8 May 1997 17:06:20 +0300 (IDT) From: Eli Zaretskii To: Diego Zuccato cc: djgpp-workers AT delorie DOT com Subject: Re: write() modified to handle __FSEXT funcs on text files In-Reply-To: <33721B44.2FDB@bo.dada.it> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 8 May 1997, Diego Zuccato wrote: > > Thanks, but I think the call to the __FSEXT function should be *before* > > the conversion, > I too. But it's quite anti-intuitive. After all, text files are DOS > specific, right ? Yes, but they look like Unix files *before* the conversion; after the conversion, they have those CR characters added that are DOS-specific. > I wrote a 'portable' locker for a database and a friend told me that in > Linux O_BINARY and O_TEXT aren't defined. Just say this, and it will be portable to Unix/Linux also: #include #ifndef O_BINARY # define O_BINARY 0 #endif #ifndef O_TEXT # define O_TEXT 0 #endif Now, when you say open ("blabla", O_RDONLY | O_BINARY), all systems will be happy. If you want to be friendly to Win32 compilers, check for _O_BINARY and define O_BINARY to be _O_BINARY if O_BINARY isn't defined. > > 1) The hook might not need the conversion at all, in which > > case you are just waisting cycles. > Right. But if I don't want conversion, I open it in binary format... I disagree. The beauty of Filesystem Extensions is exactly that it is so completely transparent to the code that calls `write'. You hook the `write' call, but whoever called `write' doesn't even know that the call winds up in your handler! So this mechanism is ideal when you need to radically change the behavior of a program without touching anything in the main code of that program. Therefore, we should not assume that the same person both decides how to open the file and installs his/her FSEXT hook. > original code...). Or we could call a user-defined function to handle > text conversion (__FSEXT_txt_conv ?)... I think that conversion NL -> CR-LF is so easy that any FSEXT hook that really needs it could do it by itself. So I say: don't bother with conversion, let the hook do it.