new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_regex / os_regex_str.c
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All right reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13
14 #include "os_regex.h"
15 #include "os_regex_internal.h"
16
17
18 /* Check if a specific string is numeric (like "129544") */
19 int OS_StrIsNum(const char *str)
20 {
21     if (str == NULL) {
22         return (FALSE);
23     }
24
25     while (*str != '\0') {
26         if (!_IsD(*str)) {
27             return (FALSE);
28         }
29         str++;
30     }
31
32     return (TRUE);
33 }
34
35 /* Return the number of characters that both strings have in common */
36 size_t OS_StrHowClosedMatch(const char *str1, const char *str2)
37 {
38     size_t count = 0;
39
40     /* They don't match if any of them is null */
41     if (!str1 || !str2) {
42         return (0);
43     }
44
45     do {
46         if (str1[count] != str2[count]) {
47             break;
48         }
49
50         count++;
51     } while ((str1[count] != '\0') && (str2[count] != '\0'));
52
53     return (count);
54 }
55