--- libaitio/src/Attic/tools.c 2012/05/14 16:14:13 1.12 +++ libaitio/src/Attic/tools.c 2012/07/22 20:39:45 1.16 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.12 2012/05/14 16:14:13 misho Exp $ +* $Id: tools.c,v 1.16 2012/07/22 20:39:45 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -123,7 +123,7 @@ io_UnquotStr(char * __restrict psLine) return 0; if (*psLine == '"' || *psLine == '\'') { - str = strdup(psLine + 1); + str = io_strdup(psLine + 1); for (pos = str, flg = 0; *pos; flg = ('\\' == *pos), pos++) { if (!flg && *pos == *psLine) { *pos = 0; @@ -131,7 +131,7 @@ io_UnquotStr(char * __restrict psLine) break; } } - free(str); + io_free(str); return 1; } @@ -143,7 +143,7 @@ io_UnquotStr(char * __restrict psLine) * * @psLine = Text string * @lineLen = Length of Text string - * return: NULL nothing to do or error; !=0 Allocated new converted data without term\0 (must be free) + * return: NULL nothing to do or error; !=0 Allocated new converted data without term\0 (must be io_free) */ inline u_char * io_Ch2Hex(u_char *psLine, int lineLen) @@ -155,7 +155,7 @@ io_Ch2Hex(u_char *psLine, int lineLen) if (!psLine || !*psLine || !lineLen) return NULL; - str = malloc(lineLen / 2); + str = io_malloc(lineLen / 2); if (!str) { LOGERR; return NULL; @@ -176,7 +176,7 @@ io_Ch2Hex(u_char *psLine, int lineLen) * * @psLine = Text string * @lineLen = Length of Text string - * return: NULL nothing to do or error; !=0 Allocated new converted string(must be free) + * return: NULL nothing to do or error; !=0 Allocated new converted string(must be io_free) */ inline char * io_Hex2Ch(u_char *psLine, int lineLen) @@ -187,7 +187,7 @@ io_Hex2Ch(u_char *psLine, int lineLen) if (!psLine || !*psLine || !lineLen) return NULL; - str = malloc(lineLen * 2 + 1); + str = io_malloc(lineLen * 2 + 1); if (!str) { LOGERR; return NULL; @@ -207,7 +207,7 @@ io_Hex2Ch(u_char *psLine, int lineLen) * io_CopyEnv() - Copy environment to new environment array; * * @oldenv = Environment array - * return: NULL error; !=NULL Allocated new environment array(must be free) + * return: NULL error; !=NULL Allocated new environment array(must be io_free) */ char ** io_CopyEnv(const char **oldenv) @@ -226,7 +226,7 @@ io_CopyEnv(const char **oldenv) num++; /* create and copy new environment */ - newenv = calloc(num + 1, sizeof(char*)); + newenv = io_calloc(num + 1, sizeof(char*)); if (!newenv) { LOGERR; return NULL; @@ -235,7 +235,7 @@ io_CopyEnv(const char **oldenv) for (i = 0; oldenv[i]; i++) if (*strchr(oldenv[i], '=')) { - *el = strdup(oldenv[i]); + *el = io_strdup(oldenv[i]); el++; } *el = NULL; @@ -248,7 +248,7 @@ io_CopyEnv(const char **oldenv) * * @psProg = Program name for execute * @oldarg = Arguments array - * return: NULL error; !=NULL Allocated execution array(must be free) + * return: NULL error; !=NULL Allocated execution array(must be io_free) */ char ** io_ExecArgs(const char *psProg, const char **oldarg) @@ -265,18 +265,18 @@ io_ExecArgs(const char *psProg, const char **oldarg) for (num = 0; oldarg[num]; num++); /* create and copy new arguments */ - newarg = calloc(num + 2, sizeof(char*)); + newarg = io_calloc(num + 2, sizeof(char*)); if (!newarg) { LOGERR; return NULL; } else el = newarg; - *el = strdup(psProg); + *el = io_strdup(psProg); el++; for (i = 0; oldarg[i]; i++, el++) - *el = strdup(oldarg[i]); + *el = io_strdup(oldarg[i]); *el = NULL; return newarg; @@ -296,8 +296,8 @@ io_FreeNullTerm(char *** __restrict arr) if (arr && *arr) { a = *arr; while (a && *a) - free(*a++); - free(*arr); + io_free(*a++); + io_free(*arr); *arr = NULL; } } @@ -323,7 +323,7 @@ io_Path2File(const char * __restrict csArgs, char * __ if (psPath && !pathLen) return -1; - psBuf = strdup(csArgs); + psBuf = io_strdup(csArgs); if (!psBuf) { LOGERR; return -1; @@ -333,7 +333,7 @@ io_Path2File(const char * __restrict csArgs, char * __ if (!pos) { strlcpy(psFile, psBuf, fileLen); - free(psBuf); + io_free(psBuf); return 1; } else *pos++ = 0; @@ -342,7 +342,7 @@ io_Path2File(const char * __restrict csArgs, char * __ if (psPath) strlcpy(psPath, psBuf, pathLen); - free(psBuf); + io_free(psBuf); return 2; } @@ -420,8 +420,6 @@ io_n2port(io_sockaddr_t * __restrict addr) case AF_INET6: return ntohs(addr->sin6.sin6_port); default: - io_SetErr(ESOCKTNOSUPPORT, "Unsuported address family %d", - addr->sa.sa_family); break; } @@ -444,6 +442,7 @@ io_n2addr(io_sockaddr_t * __restrict addr, ait_val_t * if (!addr || !val) return ret; + AIT_INIT_VAL(val); switch (addr->sa.sa_family) { case AF_INET: if (!inet_ntop(AF_INET, &addr->sin.sin_addr, str, INET_ADDRSTRLEN)) { @@ -459,6 +458,9 @@ io_n2addr(io_sockaddr_t * __restrict addr, ait_val_t * } else ret = str; break; + case AF_LOCAL: + ret = addr->sun.sun_path; + break; default: io_SetErr(EPROTONOSUPPORT, "Unsuported address family %d", addr->sa.sa_family); @@ -484,8 +486,6 @@ io_gethostbyname(const char *psHost, u_short port, io_ if (!psHost || !addr) return NULL; - else - memset(addr, 0, sizeof(io_sockaddr_t)); if (*psHost != '/') { /* resolver */ @@ -496,10 +496,15 @@ io_gethostbyname(const char *psHost, u_short port, io_ if (!host) { io_SetErr(EINVAL, "Resolver #%d - %s", h_errno, hstrerror(h_errno)); return NULL; - } else + } else { + memset(addr, 0, sizeof(io_sockaddr_t)); addr->sa.sa_family = host->h_addrtype; - } else + } + } else { + memset(addr, 0, sizeof(io_sockaddr_t)); addr->sa.sa_family = AF_LOCAL; + } + switch (addr->sa.sa_family) { case AF_INET: