/*
 * Copyright (c) 2002, 2005 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include "sm/generic.h"
SM_RCSID("@(#)$Id: strcmp.c,v 1.7 2005/06/09 00:43:40 ca Exp $")

#include "sm/assert.h"
#include "sm/magic.h"
#include "sm/memops.h"
#include "sm/rpool.h"
#include "sm/str.h"
#include "sm/str-int.h"

/*
**  SM_STR_CMP -- Compare two strings.
**
**	Parameters:
**		s1 -- first string.
**		s2 -- second string.
**
**	Returns:
**		0: strings are equal
**		<0: 1. string < 2. string
**		>0: 1. string > 2. string
*/

int
sm_str_cmp(const sm_str_P s1, const sm_str_P s2)
{
	int d, r;
	uint l;

	SM_IS_BUF(s1);
	SM_IS_BUF(s2);
	l = s1->sm_str_len;
	if (l > s2->sm_str_len)
	{
		d = 1;
		l = s2->sm_str_len;
	}
	else if (l == s2->sm_str_len)
		d = 0;
	else
		d = -1;
	r = sm_memcmp(s1->sm_str_base, s2->sm_str_base, l);
	if (r == 0)
		r = d;
	return r;
}


syntax highlighted by Code2HTML, v. 0.9.1