lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Feb 17, 2014 at 10:05 PM, William Ahern
<> wrote:
> The sockets implementation in my cqueues library has a text-mode translation
> feature which translates \r\n sequences to \n, because on Unix (unlike
> Windows) this is not done by the underlying stdio implementation. This
> allows simple (and in practice mostly correct) implementation of MIME-like
> protocols. But of course I had to implement all of the buffering myself
> because you simply cannot reliably depend on the underlying implementation
> if you want dependable behavior.

AFAIK sockets does not use an underlying stdio, they are aprox. at the
IO level, with open/read/write/close(2). It is the other way round,
you wrap a socket in an stdio object.

Anyway, I connot speak of unix in general, but the glibcs I normally
use have text mode, in fact they describe the default open behaviour
as text ( from man 3 fopen ):

       r      Open text file for reading.  The stream is positioned at
the beginning of the file.

It just happens that text mode is easy on unix.

I've used a lot of C runtimes in CP/M, MSDOS and WIN* , and found that
'text' file handling was at least peculiar. I've found runtimes which
just dropped '\015', others which considered '\012\015', '\015\012'
and '\012' as '\n', others which used '\015*\012', even ones which
also considered naked '\015' as line end. For your purpose of reading
lines, you would be out of luck with all of them, as every single one
I tested considered naked '\012' as '\n', which would make 'A\015\012'
and 'A\012' undistinguishable.

OTOH that's is, as you say, mostly correct. If you adhere to the motto
'Be strict in what you send and tolerant in what you accept', they
work quite well.

Francisco Olarte.