_screen is only valid between show/hide.
[AROS.git] / compiler / stdc / strncmp.c
blob1bc995b13f9d5a714e1e425ce4486ee3520bfe84
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 C function strncmp().
6 */
8 /*****************************************************************************
10 NAME */
11 #include <string.h>
13 int strncmp (
15 /* SYNOPSIS */
16 const char * str1,
17 const char * str2,
18 size_t n)
20 /* FUNCTION
21 Calculate str1 - str2 for upto n chars or upto the first 0 byte.
23 INPUTS
24 str1, str2 - Strings to compare
26 RESULT
27 The difference of the strings. The difference is 0, if both are
28 equal, < 0 if str1 < str2 and > 0 if str1 > str2. Note that
29 it may be greater then 1 or less than -1.
31 NOTES
32 This function is not part of a library and may thus be called
33 any time.
35 EXAMPLE
37 BUGS
39 SEE ALSO
41 INTERNALS
43 ******************************************************************************/
46 If n == 0, then this will not be initialized, even though it is
47 returned at the end, so we say two strings of 0 length are equal
49 int diff = 0;
51 /* No need to check *str2 since: a) str1 is equal str2 (both are 0),
52 then *str1 will terminate the loop b) str1 and str2 are not equal
53 (eg. *str2 is 0), then the diff part will be FALSE. I calculate
54 the diff first since a) it's more probable that the first chars
55 will be different and b) I don't need to initialize diff then. */
56 while (n && !(diff = *(unsigned char*) str1 - *(unsigned char*) str2) && *str1)
58 /* advance both strings. I do that here, since doing it in the
59 check above would mean to advance the strings once too often */
60 str1 ++;
61 str2 ++;
62 n --;
65 /* Now return the difference. */
66 return diff;
67 } /* strncmp */