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
18 /* Add pointer to array. */
19 void **os_AddPtArray(void *pt, void **array)
32 os_realloc(array, (i + 2)*sizeof(char *), ret);
40 /* Add a string to an array. */
41 char **os_AddStrArray(char *str, char **array)
53 os_realloc(array, (i + 2)*sizeof(char *), ret);
54 os_strdup(str, ret[i]);
61 /* Check if String is on array (Must be NULL terminated) */
62 int os_IsStrOnArray(char *str, char **array)
71 if(strcmp(*array, str) == 0)
81 /* Clear the memory of one char and one char** */
82 void os_FreeArray(char *ch1, char **ch2)
91 /* Cleaning chat ** */
110 /* os_LoadString: v0.1
111 * Allocate memory at "*at" and copy *str to it.
112 * If *at already exist, realloc the memory and strcat str
114 * It will return the new string on success or NULL on memory error.
116 char *os_LoadString(char *at, char *str)
123 merror(MEM_ERROR,ARGV0);
127 else /*at is not null. Need to reallocat its memory and copy str to it*/
130 int strsize = strlen(str);
131 int finalsize = strsize + strlen(at) + 1;
133 newat = realloc(at, finalsize*sizeof(char));
137 merror(MEM_ERROR,ARGV0);
142 strncat(at, str, strsize);
143 at[finalsize -1] = '\0';