FreeBASIC  0.91.0
str_comp.c
Go to the documentation of this file.
1 /* string compare function */
2 
3 #include "fb.h"
4 
6  (
7  void *str1,
8  ssize_t str1_size,
9  void *str2,
10  ssize_t str2_size
11  )
12 {
13  const char *str1_ptr, *str2_ptr;
14  ssize_t str1_len, str2_len;
15  int res;
16 
17  /* both not null? */
18  if( (str1 != NULL) && (str2 != NULL) )
19  {
20  FB_STRSETUP_FIX( str1, str1_size, str1_ptr, str1_len );
21  FB_STRSETUP_FIX( str2, str2_size, str2_ptr, str2_len );
22 
23  res = FB_MEMCMP( str1_ptr,
24  str2_ptr,
25  ((str1_len < str2_len) ? str1_len : str2_len) );
26 
27  if( (res == 0) && (str1_len != str2_len) )
28  res = (( str1_len > str2_len ) ? 1 : -1 );
29  }
30  /* left null? */
31  else if( str1 == NULL )
32  {
33  /* right also null? return eq */
34  if( str2 == NULL )
35  res = 0;
36  else
37  {
38  FB_STRSETUP_FIX( str2, str2_size, str2_ptr, str2_len );
39 
40  /* is right empty? return eq */
41  if( str2_len == 0 )
42  res = 0;
43 
44  /* else, return lt */
45  else
46  res = -1;
47  }
48  }
49  /* only right is null */
50  else
51  {
52  FB_STRSETUP_FIX( str1, str1_size, str1_ptr, str1_len );
53 
54  /* is left empty? return eq */
55  if( str1_len == 0 )
56  res = 0;
57  /* else, return gt */
58  else
59  res = 1;
60  }
61 
62 
63  FB_STRLOCK();
64 
65  /* delete temps? */
66  if( str1_size == -1 )
68  if( str2_size == -1 )
70 
71  FB_STRUNLOCK();
72 
73  return res;
74 }