1m4_ignore([dnl
2#include <sys/types.h>
3
4#include <db.h>
5
6u_int32_t compare_prefix(DB *, const DBT *a, const DBT *b);
7
8int
9main()
10{
11	DB *dbp;
12	DBT key, data;
13
14	(void)compare_prefix(dbp, &key, &data);
15	return (0);
16}])
17
18m4_indent([dnl
19u_int32_t
20compare_prefix(dbp, a, b)
21	DB *dbp;
22	const DBT *a, *b;
23{
24	size_t cnt, len;
25	u_int8_t *p1, *p2;
26m4_blank
27	cnt = 1;
28	len = a-__GT__size __GT__ b-__GT__size ? b-__GT__size : a-__GT__size;
29	for (p1 =
30		a-__GT__data, p2 = b-__GT__data; len--; ++p1, ++p2, ++cnt)
31			if (*p1 != *p2)
32				return (cnt);
33
34	/*
35	 * They match up to the smaller of the two sizes.
36	 * Collate the longer after the shorter.
37	 */
38	if (a-__GT__size __LT__ b-__GT__size)
39		return (a-__GT__size + 1);
40	if (b-__GT__size __LT__ a-__GT__size)
41		return (b-__GT__size + 1);
42	return (b-__GT__size);
43}])
44