1 /* @(#) $Id: ./src/shared/mem_op.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
17 /* Add pointer to array. */
18 void **os_AddPtArray(void *pt, void **array)
31 os_realloc(array, (i + 2)*sizeof(char *), ret);
39 /* Add a string to an array. */
40 char **os_AddStrArray(char *str, char **array)
52 os_realloc(array, (i + 2)*sizeof(char *), ret);
53 os_strdup(str, ret[i]);
60 /* Check if String is on array (Must be NULL terminated) */
61 int os_IsStrOnArray(char *str, char **array)
70 if(strcmp(*array, str) == 0)
80 /* Clear the memory of one char and one char** */
81 void os_FreeArray(char *ch1, char **ch2)
90 /* Cleaning chat ** */
109 /* os_LoadString: v0.1
110 * Allocate memory at "*at" and copy *str to it.
111 * If *at already exist, realloc the memory and strcat str
113 * It will return the new string on success or NULL on memory error.
115 char *os_LoadString(char *at, char *str)
122 merror(MEM_ERROR,ARGV0);
126 else /*at is not null. Need to reallocat its memory and copy str to it*/
129 int strsize = strlen(str);
130 int finalsize = strsize + strlen(at) + 1;
132 newat = realloc(at, finalsize*sizeof(char));
136 merror(MEM_ERROR,ARGV0);
141 strncat(at, str, strsize);
142 at[finalsize -1] = '\0';