1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3
4<head>
5<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
6<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 8.0.2.0 for Windows">
7<META http-equiv="Content-Style-Type" content="text/css">
8<title>STD_CompareLString</title>
9<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css">
10</head>
11
12<body>
13
14<h1 align="left">STD_CompareLString <img src="../../image/NTR.gif"align="middle"><img src="../../image/TWL.gif" align="middle"></h1>
15<h2>Syntax</h2>
16<dl>
17  <dd><PRE><CODE>#include &lt;nitro/std.h&gt;
18
19int STD_CompareLString( const char* str1, const char* str2, int len );</CODE></PRE>
20  <PRE><CODE>int STD_StrLCmp( const char* str1, const char* str2, int len );
21</CODE></PRE></dd>
22</dl>
23
24<h2>Arguments</h2>
25<table border="1" width="100%">
26  <tbody>
27    <TR>
28<TD width="200"><SPAN class="argument">str1</SPAN></TD>
29<TD width="800">Pointer to the compared string.</TD>
30    </TR>
31    <TR>
32<TD width="200"><SPAN class="argument">str2</SPAN></TD>
33<TD width="800">Pointer to the compared string.</TD>
34    </TR>
35    <TR>
36<TD width="200"><SPAN class="argument">len</SPAN></TD>
37<TD width="800">Length of the string to compare.</TD>
38    </TR>
39  </tbody>
40</table>
41
42<h2>Return Values</h2>
43<p>
44Returns 0 if the compared strings are the same.
45</p>
46
47<H2>Description</H2>
48<P>
49Compares only <SPAN class="argument">len</SPAN> characters between the two strings <SPAN class="argument">str1</SPAN> and <SPAN class="argument">str2</SPAN>. This has the same behavior as the <CODE>strlcmp</CODE> function.
50</P>
51<P>
52The difference when compared to the <CODE>STD_CompareNString</CODE> function lies in the fact that the two strings are not considered a match even if the length of <SPAN class="argument">len</SPAN> is compared and found to match, but the next character in <SPAN class="argument">str1</SPAN> is not <CODE>NULL</CODE>.
53<P>
54When detecting the difference between buffers as a means to prevent buffer overflow, it is possible to prevent the comparison of addresses that come after the buffer length, by replacing a comparison function without a length restriction check with a function that includes a length restriction check.
55</P>
56<P>
57Although replacing the <CODE>strcmp</CODE> function with the <CODE>strncmp</CODE> function serves as an actual example, if you simply specify the buffer size in the <SPAN class="argument">len</SPAN> parameter used to specify length when using the <CODE>strncmp</CODE> function, if the result of comparison is a match, the result &quot;match&quot; is returned even if the buffer overflows. Buffer overflow can therefore also be detected based on the fact that the result &quot;match&quot; is not returned if the <CODE>NULL</CODE> character is not found within (<SPAN class="argument">len</SPAN>+1) characters when using the <CODE>strlcmp</CODE> function.
58</P>
59<P>
60It is therefore best to use the <CODE>STD_CompareLString</CODE> function when using string comparison for the purpose of checking buffers. <!--??????len?str1???????????????? str1????????????????????????????????????????????????? ???????????????????�????????????????? -->
61</P>
62<P>
63<CODE>STD_StrLCmp</CODE> is defined as another name for <CODE>STD_StrCompareLString</CODE>.
64</P>
65
66<h2>See Also</h2>
67<p><A href="STD_CompareString.html"><CODE>STD_CompareString</CODE></A><BR> <A href="STD_CompareNString.html"><CODE>STD_CompareNString</CODE></A></p>
68
69<H2>Revision History</H2>
70<P>
712008/10/06 Added a description of the difference with the <CODE>STD_CompareNString</CODE> function.<BR> 2008/09/26 Revised definitions.<BR> 2005/10/05 Initial version.<BR>
72</P>
73<hr><p>CONFIDENTIAL</p></body>
74</html>
75