File: winfunctions.cpp

package info (click to toggle)
openssn 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,340 kB
  • sloc: cpp: 10,973; makefile: 80
file content (72 lines) | stat: -rw-r--r-- 1,544 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifdef WIN32
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "winfunctions.h"

char *my_strcasestr(char *haystack, char *needle)
{
    int length, index;
    char *up_haystack, *up_needle;
    char *result, *my_substr;

    if ( (!haystack) || (! needle) )
       return NULL;

    // create buffers
    up_haystack = (char *) calloc( strlen(haystack) + 1, sizeof(char));
    if (! up_haystack)
       return NULL;
    up_needle = (char *) calloc( strlen(needle) + 1, sizeof(char) );
    if (! up_needle)
    {
       free(up_haystack);
       return NULL;
    }

    length = strlen(haystack);
    for (index = 0; index < length; index++)
       up_haystack[index] = toupper(haystack[index]);
    length = strlen(needle);
    for (index = 0; index < length; index++)
       up_needle[index] = toupper(needle[index]);

    result = strstr(up_haystack, up_needle);
    if (result)
        my_substr = (result - up_haystack) + haystack;
    else
        my_substr = NULL;

    // free buffers
    free(up_needle);
    free(up_haystack);
    return my_substr;
}



int my_strncasecmp(char *str1, char *str2, int letters)
{
   int index = 0;
   int letter1, letter2;
   int result = FALSE;

   while ( (index < letters) && (! result) )
   {
       letter1 = toupper(str1[index]);
       letter2 = toupper(str2[index]);
       if (letter1 == letter2)
          index++;
       else if (letter1 < letter2)
          result = -1;
       else if (letter1 > letter2)
          result = 1;
       
   }
   return result;
}



#endif