--- libaitio/src/Attic/tools.c 2012/02/02 21:32:42 1.8 +++ libaitio/src/Attic/tools.c 2012/03/15 01:52:23 1.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.8 2012/02/02 21:32:42 misho Exp $ +* $Id: tools.c,v 1.9 2012/03/15 01:52:23 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -294,6 +294,50 @@ io_FreeNullTerm(char *** __restrict arr) free(*arr); *arr = NULL; } +} + +/* + * 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; } /*