bug-gnulib
[Top][All Lists]
Advanced

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

Re: readline fix


From: Eric Blake
Subject: Re: readline fix
Date: Wed, 09 Nov 2005 22:04:02 -0700
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Simon Josefsson on 11/9/2005 7:17 PM:
> Is this right?  I'm not sure what a portable way to remove EOL is.
> Anyway, I installed this because it work on known platforms.

The concept is correct (the full-blown readline library does indeed strip
the trailing newline), but whether you should also strip \r is a different
matter.

> 
>  
> +  if (out[strlen (out) - 1] == '\r')
> +    out[strlen (out) - 1] = '\0';
> +  if (out[strlen (out) - 1] == '\n')
> +    out[strlen (out) - 1] = '\0';

This is backwards: Windows text files have \r\n, so you should strip \n
before \r if you are working from the end (and if others agree that
stripping \r is the right thing to do).  Also, it ignores the fact that
getline() can return embedded NULs, so that a) strlen() may be inaccurate,
and b) it is a waste of computation since the return value of getline() is
already the full length rather than walking the string multiple times.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDctTC84KuGfSFAYARAoDAAJ9ZGEiQrUJCICFIXbG3fX31Kwh5KACgupxq
/JDFkoRVihv/v69Kb0gMR2A=
=6qMR
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]