1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
14 /* Add pointer to array */
15 void **os_AddPtArray(void *pt, void **array)
26 os_realloc(array, (i + 2)*sizeof(void *), ret);
33 /* Add a string to an array */
34 char **os_AddStrArray(const char *str, char **array)
44 os_realloc(array, (i + 2)*sizeof(char *), ret);
45 os_strdup(str, ret[i]);
51 /* Check if String is on array (Must be NULL terminated) */
52 int os_IsStrOnArray(const char *str, char **array)
59 if (strcmp(*array, str) == 0) {
67 /* Clear the memory of one char and one char** */
68 void os_FreeArray(char *ch1, char **ch2)
80 while (*ch2 != NULL) {
92 /* Allocate memory at "*at" and copy *str to it
93 * If *at already exist, realloc the memory and strcat str on it
94 * It will return the new string on success or NULL on memory error
96 char *os_LoadString(char *at, const char *str)
101 merror(MEM_ERROR, __local_name, errno, strerror(errno));
104 } else { /* at is not null. Need to reallocate its memory and copy str to it */
106 size_t strsize = strlen(str);
107 size_t finalsize = strsize + strlen(at) + 1;
109 newat = (char *) realloc(at, finalsize * sizeof(char));
112 merror(MEM_ERROR, __local_name, errno, strerror(errno));
117 strncat(at, str, strsize);
118 at[finalsize - 1] = '\0';
126 /* Clear memory regardless of compiler optimizations
127 * v = memory to clear
128 * c = character to set
129 * n = memory size to clear
131 void *memset_secure(void *v, int c, size_t n)
133 volatile unsigned char *p = (volatile unsigned char *)v;
135 *p++ = (unsigned char) c;