X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fos_regex%2Fos_regex_strbreak.c;h=dde2d233d875e9d59a1b49942d65645e43d8ff8b;hp=d04f3555a14f5e8a2eda20f09cbb21bb8559f5a3;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b 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 d04f355..dde2d23 --- a/src/os_regex/os_regex_strbreak.c +++ b/src/os_regex/os_regex_strbreak.c @@ -1,5 +1,3 @@ -/* $OSSEC, os_regex_strbreak.c, v0.3, 2005/04/05, Daniel B. Cid$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -9,7 +7,6 @@ * Foundation */ - #include #include #include @@ -18,59 +15,51 @@ #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, const char *str, size_t size) { size_t count = 0; size_t i = 0; - const char *tmp_str = str; - char **ret; /* We can't do anything if str is null */ - if(str == NULL) - return(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; } @@ -79,44 +68,39 @@ char **OS_StrBreak(char match, const char *str, size_t 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 */