--- libaitio/src/Attic/tools.c 2011/12/14 09:26:58 1.7.2.2 +++ libaitio/src/Attic/tools.c 2012/03/10 15:37:09 1.8.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.7.2.2 2011/12/14 09:26:58 misho Exp $ +* $Id: tools.c,v 1.8.2.1 2012/03/10 15:37:09 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -297,6 +297,50 @@ io_FreeNullTerm(char *** __restrict arr) } /* + * io_Path2File() - Parse and make path/filename pair + * + * @csArgs = Input argument line + * @psPath = Output Path, if ==NULL path not returned + * @pathLen = Size of path array + * @psFile = Output File + * @fileLen = Size of file array + * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items + */ +inline int +io_Path2File(const char * __restrict csArgs, char * __restrict psPath, + int pathLen, char * __restrict psFile, int fileLen) +{ + char *pos, *psBuf; + + if (!csArgs || !psFile || !fileLen) + return -1; + if (psPath && !pathLen) + return -1; + + psBuf = strdup(csArgs); + if (!psBuf) { + LOGERR; + return -1; + } + + pos = strrchr(psBuf, '/'); + if (!pos) { + strlcpy(psFile, psBuf, fileLen); + + free(psBuf); + return 1; + } else + *pos++ = 0; + + strlcpy(psFile, pos, fileLen); + if (psPath) + strlcpy(psPath, psBuf, pathLen); + + free(psBuf); + return 2; +} + +/* * io_ether_ntoa() Convert ethernet address to string * @n = ethernet address structure, like struct ether_addr * @a = string @@ -414,7 +458,7 @@ io_n2addr(io_sockaddr_t * __restrict addr, ait_val_t * if (!AIT_ISEMPTY(val)) AIT_FREE_VAL(val); AIT_SET_STR(val, ret); - return AIT_GET_STR(val); + return (const char*) AIT_GET_STR(val); } /*