chomp should only remove the newline if it occurs at the end of the input.
authorMatt Kraai <kraai@debian.org>
Wed, 2 Jan 2002 18:51:23 +0000 (18:51 -0000)
committerMatt Kraai <kraai@debian.org>
Wed, 2 Jan 2002 18:51:23 +0000 (18:51 -0000)
This was caught by the test suite (in sed/sed-aic-commands).

* libbb/chomp.c: Revert to revision 1.5.

libbb/chomp.c

index e5a522f01df3665aa40217befb6e31bd87f38c98..94404a98d2df2e08cd9995cbed544c58abeff73f 100644 (file)
 #include <string.h>
 #include "libbb.h"
 
+
 void chomp(char *s)
 {
-       if (!(s && *s)) return;
-       while (*s && (*s != '\n')) s++;
-       *s = 0;
+       char *lc = last_char_is(s, '\n');
+       
+       if(lc)
+               *lc = 0;
 }