version 1.4.4.1, 2011/05/10 20:47:31
|
version 1.5.4.1, 2011/10/14 07:28:16
|
Line 199 io_Hex2Ch(u_char *psLine, int lineLen)
|
Line 199 io_Hex2Ch(u_char *psLine, int lineLen)
|
|
|
return str; |
return str; |
} |
} |
|
|
|
/* |
|
* io_CopyEnv() Copy environment to new environment array; |
|
* @oldenv = Environment array |
|
* return: NULL error; !=NULL Allocated new environment array(must be free) |
|
*/ |
|
char ** |
|
io_CopyEnv(const char **oldenv) |
|
{ |
|
char **newenv, **el; |
|
register int i, num; |
|
|
|
if (!oldenv) |
|
return NULL; |
|
else |
|
newenv = el = NULL; |
|
|
|
/* count items environment */ |
|
for (i = num = 0; oldenv[i]; i++) |
|
if (*strchr(oldenv[i], '=')) |
|
num++; |
|
|
|
/* create and copy new environment */ |
|
newenv = calloc(num + 1, sizeof(char*)); |
|
if (!newenv) { |
|
LOGERR; |
|
return NULL; |
|
} else |
|
el = newenv; |
|
|
|
for (i = 0; oldenv[i]; i++) |
|
if (*strchr(oldenv[i], '=')) { |
|
*el = strdup(oldenv[i]); |
|
el++; |
|
} |
|
*el = NULL; |
|
|
|
return newenv; |
|
} |
|
|
|
/* |
|
* io_ExecArgs() Build exec arguments from other array |
|
* @psProg = Program name for execute |
|
* @oldarg = Arguments array |
|
* return: NULL error; !=NULL Allocated execution array(must be free) |
|
*/ |
|
char ** |
|
io_ExecArgs(const char *psProg, const char **oldarg) |
|
{ |
|
char **newarg, **el; |
|
register int i, num; |
|
|
|
if (!psProg || !oldarg) |
|
return NULL; |
|
else |
|
newarg = el = NULL; |
|
|
|
/* count items arguments */ |
|
for (num = 0; oldarg[num]; num++); |
|
|
|
/* create and copy new arguments */ |
|
newarg = calloc(num + 2, sizeof(char*)); |
|
if (!newarg) { |
|
LOGERR; |
|
return NULL; |
|
} else |
|
el = newarg; |
|
|
|
*el = strdup(psProg); |
|
el++; |
|
|
|
for (i = 0; oldarg[i]; i++, el++) |
|
*el = strdup(oldarg[i]); |
|
*el = NULL; |
|
|
|
return newarg; |
|
} |
|
|
|
/* |
|
* io_FreeNullTerm() Free dynamic allocated null terminated array with strings |
|
* @arr = Pointer to array for free |
|
* return: none |
|
*/ |
|
inline void |
|
io_FreeNullTerm(char *** __restrict arr) |
|
{ |
|
char **a; |
|
|
|
if (arr && *arr) { |
|
a = *arr; |
|
while (a && *a) |
|
free(*a++); |
|
free(*arr); |
|
*arr = NULL; |
|
} |
|
} |
|
|
|
/* |
|
* io_ether_ntoa() Convert ethernet address to string |
|
* @n = ethernet address structure, like struct ether_addr |
|
* @a = string |
|
* @len = string length |
|
* return: NULL error or !=NULL string a |
|
*/ |
|
inline char * |
|
io_ether_ntoa(const struct io_ether_addr *n, char * __restrict a, int len) |
|
{ |
|
if (!n || !a) |
|
return NULL; |
|
|
|
memset(a, 0, len); |
|
if (snprintf(a, len, "%02x:%02x:%02x:%02x:%02x:%02x", |
|
n->ether_addr_octet[0], n->ether_addr_octet[1], |
|
n->ether_addr_octet[2], n->ether_addr_octet[3], |
|
n->ether_addr_octet[4], n->ether_addr_octet[5]) < 17) |
|
return NULL; |
|
|
|
return a; |
|
} |