X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_regex%2Fos_regex_strbreak.c;h=dde2d233d875e9d59a1b49942d65645e43d8ff8b;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=e8a4228991843ac0175eae13229b12399b8cc3e4;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/os_regex/os_regex_strbreak.c b/src/os_regex/os_regex_strbreak.c old mode 100755 new mode 100644 index e8a4228..dde2d23 --- a/src/os_regex/os_regex_strbreak.c +++ b/src/os_regex/os_regex_strbreak.c @@ -1,74 +1,65 @@ -/* $OSSEC, os_regex_strbreak.c, v0.3, 2005/04/05, Daniel B. Cid$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ - #include #include #include + +#include "os_regex.h" #include "os_regex_internal.h" -/** char **OS_StrBreak(char match, char *str, int size) v0.2 - * Split a string into multiples pieces, divided by a char "match". +/* Split a string into multiples pieces, divided by a char "match". * Returns a NULL terminated array on success or NULL on error. */ -char **OS_StrBreak(char match, char *str, int size) +char **OS_StrBreak(char match, const char *str, size_t size) { - int count = 0; - int i = 0; - - char *tmp_str = str; - + size_t count = 0; + size_t i = 0; + const char *tmp_str = str; char **ret; - /* We can't do anything if str is null or size <= 0 */ - if((str == NULL)||(size <= 0)) - return(NULL); + /* We can't do anything if str is null */ + if (str == NULL) { + return (NULL); + } - ret = (char **)calloc(size+1, sizeof(char *)); + ret = (char **)calloc(size + 1, sizeof(char *)); - if(ret == NULL) - { - /* Memory error. Should provice a better way to detect it */ - return(NULL); + if (ret == NULL) { + /* Memory error. Should provide a better way to detect it */ + return (NULL); } - - /* Allocating memory to null */ - while(i <= size) - { + + /* Allocate memory to null */ + while (i <= size) { ret[i] = NULL; i++; } i = 0; - /* */ - while(*str != '\0') - { + while (*str != '\0') { i++; - if((count < size-1)&&(*str == match)) - { - ret[count] = (char *)calloc(i,sizeof(char)); + if ((count < size - 1) && (*str == match)) { + ret[count] = (char *)calloc(i, sizeof(char)); - if(ret[count] == NULL) - { + if (ret[count] == NULL) { goto error; } - /* Copying the string */ - ret[count][i-1] = '\0'; - strncpy(ret[count],tmp_str,i-1); + /* Copy the string */ + ret[count][i - 1] = '\0'; + strncpy(ret[count], tmp_str, i - 1); tmp_str = ++str; count++; - i=0; + i = 0; continue; } @@ -77,44 +68,39 @@ char **OS_StrBreak(char match, char *str, int size) /* Just do it if count < size */ - if(count < size) - { - ret[count] = (char *)calloc(i+1,sizeof(char)); + if (count < size) { + ret[count] = (char *)calloc(i + 1, sizeof(char)); - if(ret[count] == NULL) - { + if (ret[count] == NULL) { goto error; } - /* Copying the string */ + /* Copy the string */ ret[count][i] = '\0'; - strncpy(ret[count],tmp_str,i); + strncpy(ret[count], tmp_str, i); count++; - /* Making sure it is null terminated */ + /* Make sure it is null terminated */ ret[count] = NULL; - return(ret); + return (ret); } /* We shouldn't get to this point * Just let "error" handle that */ - error: - i = 0; +error: + i = 0; - /* Deallocating the memory whe can */ - while(i < count) - { - free(ret[i]); - i++; - } + while (i < count) { + free(ret[i]); + i++; + } - free(ret); - return(NULL); + free(ret); + return (NULL); } -/* EOF */