sbase/libutil/linecmp.c
Michael Forney 8ca79a2993 linecmp: Handle NUL bytes properly
Test case:

if [ "$(printf 'a\na\0b' | ./sort -u)" = "$(printf 'a\na\0b')" ] ; then
	echo pass
else
	echo fail
fi
2016-07-09 10:09:50 +01:00

18 lines
304 B
C

/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <string.h>
#include "../text.h"
#include "../util.h"
int
linecmp(struct line *a, struct line *b)
{
int res = 0;
if (!(res = memcmp(a->data, b->data, MIN(a->len, b->len))))
res = a->len - b->len;
return res;
}