1N/A/*
1N/A * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A *
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_RCSID("@(#)$Id: strrevcmp.c,v 1.2 2001/08/27 22:21:51 gshapiro Exp $")
1N/A
1N/A#include <sm/config.h>
1N/A#include <sm/string.h>
1N/A#include <string.h>
1N/A
1N/A/* strcasecmp.c */
1N/Aextern const unsigned char charmap[];
1N/A
1N/A/*
1N/A** SM_STRREVCASECMP -- compare two strings starting at the end (ignore case)
1N/A**
1N/A** Parameters:
1N/A** s1 -- first string.
1N/A** s2 -- second string.
1N/A**
1N/A** Returns:
1N/A** strcasecmp(reverse(s1), reverse(s2))
1N/A*/
1N/A
1N/Aint
1N/Asm_strrevcasecmp(s1, s2)
1N/A const char *s1, *s2;
1N/A{
1N/A register int i1, i2;
1N/A
1N/A i1 = strlen(s1) - 1;
1N/A i2 = strlen(s2) - 1;
1N/A while (i1 >= 0 && i2 >= 0 &&
1N/A charmap[(unsigned char) s1[i1]] ==
1N/A charmap[(unsigned char) s2[i2]])
1N/A {
1N/A --i1;
1N/A --i2;
1N/A }
1N/A if (i1 < 0)
1N/A {
1N/A if (i2 < 0)
1N/A return 0;
1N/A else
1N/A return -1;
1N/A }
1N/A else
1N/A {
1N/A if (i2 < 0)
1N/A return 1;
1N/A else
1N/A return (charmap[(unsigned char) s1[i1]] -
1N/A charmap[(unsigned char) s2[i2]]);
1N/A }
1N/A}
1N/A /*
1N/A** SM_STRREVCMP -- compare two strings starting at the end
1N/A**
1N/A** Parameters:
1N/A** s1 -- first string.
1N/A** s2 -- second string.
1N/A**
1N/A** Returns:
1N/A** strcmp(reverse(s1), reverse(s2))
1N/A*/
1N/A
1N/Aint
1N/Asm_strrevcmp(s1, s2)
1N/A const char *s1, *s2;
1N/A{
1N/A register int i1, i2;
1N/A
1N/A i1 = strlen(s1) - 1;
1N/A i2 = strlen(s2) - 1;
1N/A while (i1 >= 0 && i2 >= 0 && s1[i1] == s2[i2])
1N/A {
1N/A --i1;
1N/A --i2;
1N/A }
1N/A if (i1 < 0)
1N/A {
1N/A if (i2 < 0)
1N/A return 0;
1N/A else
1N/A return -1;
1N/A }
1N/A else
1N/A {
1N/A if (i2 < 0)
1N/A return 1;
1N/A else
1N/A return s1[i1] - s2[i2];
1N/A }
1N/A}