X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=src%2Fshared%2Fstring_op.c;fp=src%2Fshared%2Fstring_op.c;h=f458793402006f3706f7c2c67e1c68b286fd8b5d;hb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;hp=0000000000000000000000000000000000000000;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/shared/string_op.c b/src/shared/string_op.c new file mode 100755 index 0000000..f458793 --- /dev/null +++ b/src/shared/string_op.c @@ -0,0 +1,91 @@ +/* @(#) $Id: ./src/shared/string_op.c, 2011/11/01 dcid Exp $ + */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All rights 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 2) as published by the FSF - Free Software + * Foundation + * + * License details at the LICENSE file included with OSSEC or + * online at: http://www.ossec.net/en/licensing.html + */ + + +#include "shared.h" +#include "string.h" + +/** os_trimcrlf + * Trims the cr and/or LF from the last positions of a string + */ +void os_trimcrlf(char *str) +{ + int len; + + len=strlen(str); + len--; + + while (str[len]=='\n' || str[len]=='\r') + { + str[len]='\0'; + len--; + } +} + +/* Remove offending char (e.g., double quotes) from source */ +char *os_strip_char(char *source, char remove) { + char *clean; + char *iterator = source; + int length = 0; + int i; + + // Figure out how much memory to allocate + for( ; *iterator; iterator++ ) { + if ( *iterator != remove ) { + length++; + } + } + + // Allocate the memory + if( (clean = malloc( length + 1 )) == NULL ) { + // Return NULL + return NULL; + } + memset(clean, '\0', length + 1); + + // Remove the characters + iterator=source; + for( i=0; *iterator; iterator++ ) { + if ( *iterator != remove ) { + clean[i] = *iterator; + i++; + } + } + + return clean; +} + +/* Do a substring */ +int os_substr(char *dest, const char *src, int position, int length) { + dest[0]='\0'; + + if( length <= 0 ) { + // Unsupported negative length string + return -3; + } + if( src == NULL ) { + return -2; + } + if( position >= strlen(src) ) { + return -1; + } + + strncat(dest, (src + position), length); + // Return Success + return 0; +} + + +/* EOF */