Indentation fix, cleanup.
[AROS.git] / compiler / arossupport / strrncasecmp.c
blob250888b662899535698c741449dbc9c6b63a1a98
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Compare the tails of two strings
6 Lang: english
7 */
9 #include <ctype.h>
11 /*****************************************************************************
13 NAME */
14 #include <string.h>
16 int strrncasecmp (
18 /* SYNOPSIS */
19 const char * str1,
20 const char * str2,
21 int cnt)
23 /* FUNCTION
24 Compare the end parts of two strings. Case is ignored.
26 INPUTS
27 str1, str2 - Strings to compare
28 cnt - Compare that many characters
30 RESULT
31 Returns 0 if the strings are equal and != 0 otherwise.
33 NOTES
34 This function is not part of a library and may thus be called
35 any time.
37 EXAMPLE
38 // rc = 0
39 rc = strrncasecmp ("disk.info", ".INFO", 5);
41 // rc <> 0
42 rc = strrncasecmp ("disk.info", ".c", 2);
44 BUGS
46 SEE ALSO
47 clib/strcmp(), clib/strcasecmp(), clib/strncasecmp(), clib/strrchr()
49 INTERNALS
51 HISTORY
53 ******************************************************************************/
55 const char * ptr1, * ptr2;
56 int diff = 0;
58 /* If any string is empty, the strings are equal */
59 if (!*str1 || !*str2)
60 return 0;
62 ptr1 = str1;
64 while (*ptr1)
65 ptr1++;
67 ptr2 = str2;
69 while (*ptr2)
70 ptr2++;
74 if (!cnt)
75 break;
77 cnt --;
78 ptr1 --;
79 ptr2 --;
81 diff = tolower (*ptr1) - tolower (*ptr2);
83 while (!diff && ptr1 != str1 && ptr2 != str2);
85 /* Compared all neccessary chars ? */
86 if (!cnt)
87 return diff;
89 /* Run out of chars in only one of the two strings ? */
90 if (ptr1 != str1)
91 diff = 1;
92 else if (ptr2 != str2)
93 diff = -1;
95 /* The strings differ */
96 return diff;
97 } /* strrncasecmp */
99 #ifdef TEST
100 #include <stdio.h>
102 int main (int argc, char ** argv)
104 int n;
106 if (argc != 4)
108 fprintf (stderr, "Usage: %s string1 string2 len\n", argv[0]);
109 return 5;
112 n = atoi (argv[3]);
114 printf ("strrncasecmp (\"%s\", \"%s\", %d) = %d\n",
115 argv[1],
116 argv[2],
118 strrncasecmp (argv[1], argv[2], n)
121 } /* main */
123 #endif /* TEST */