1 /* @(#) $Id: mem_op.c,v 1.7 2009/06/24 18:53:08 dcid Exp $ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 3) as published by the FSF - Free Software
16 /* Check if String is on array (Must be NULL terminated) */
17 int os_IsStrOnArray(char *str, char **array)
26 if(strcmp(*array, str) == 0)
36 /* Clear the memory of one char and one char** */
37 void os_FreeArray(char *ch1, char **ch2)
46 /* Cleaning chat ** */
65 /* os_LoadString: v0.1
66 * Allocate memory at "*at" and copy *str to it.
67 * If *at already exist, realloc the memory and strcat str
69 * It will return the new string on success or NULL on memory error.
71 char *os_LoadString(char *at, char *str)
76 if((strsize = strlen(str)) < OS_SIZE_2048)
78 at = calloc(strsize+1,sizeof(char));
81 merror(MEM_ERROR,ARGV0);
84 strncpy(at, str, strsize);
89 merror(SIZE_ERROR,ARGV0,str);
93 else /*at is not null. Need to reallocat its memory and copy str to it*/
95 int strsize = strlen(str);
96 int atsize = strlen(at);
97 int finalsize = atsize+strsize+1;
99 if((atsize > OS_SIZE_2048) || (strsize > OS_SIZE_2048))
101 merror(SIZE_ERROR,ARGV0,str);
105 at = realloc(at, (finalsize)*sizeof(char));
109 merror(MEM_ERROR,ARGV0);
113 strncat(at,str,strsize);
115 at[finalsize-1] = '\0';