[PATCH] coreutils tac (was: coreutils tac)

Denys Vlasenko vda.linux at googlemail.com
Mon Jan 7 16:15:14 UTC 2008


On Sunday 06 January 2008 09:31, Tito wrote:
> On Sunday 06 January 2008 07:28:47 Denys Vlasenko wrote:
> > On Wednesday 02 January 2008 15:23, Natanael Copa wrote:
> > > Denys, whats the status on the tac patch?
> > 
> > Version which does inversion in memory is appled to svn.
> > It handles non terminated last line the same as coreutils,
> > but mishandles NULs.
> Hi,
> Denis, did you forget svn add again?  :-)

Yes :(. Try now.

> Why it mishandles NULs?
> I thought that i've got it right in version 2 of my patch (attached):
> 
>               /* Get line and add it to the start of the temp linked list. */
>                 while ((line = xmalloc_fgets(f))) {
>                         if (temp_list && !last_char_is(temp_list->data, '\n'))
>                                 /* Last line ended with '\0' so concatenate them. */
>                                  temp_list->data = xasprintf("%s%s", temp_list->data, line);
>                         else
>                                 llist_add_to(&temp_list, line); 
>                 }
> 
> this was the test file i used (attached):
> 055 056 057 000 057 056 055 010
> 
> result is:
> 
> GNU tac
> tac prova4
> 789987
> 
> busybox
>  ./busybox tac prova4
> 789987

It's visibly similar, but GNU tac preserves NUL, while above version eats it.
--
vda


More information about the busybox mailing list