--- libaitio/src/Attic/tools.c 2012/07/30 11:49:46 1.16.4.1 +++ libaitio/src/Attic/tools.c 2012/09/10 12:03:56 1.17.6.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.16.4.1 2012/07/30 11:49:46 misho Exp $ +* $Id: tools.c,v 1.17.6.1 2012/09/10 12:03:56 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -303,6 +303,28 @@ io_FreeNullTerm(char *** __restrict arr) } /* + * io_argsNum() Parse and calculate number of arguments + * + * @csArgs = Input arguments line + * @csDelim = Delimiter(s) for separate + * return: 0 error format; -1 error:: can`t read; >0 ok, number of items + */ +inline int +io_argsNum(const char *csArgs, const char *csDelim) +{ + register int res; + char *pos; + + assert(csArgs); + assert(csDelim); + if (!csArgs || !csDelim) + return -1; + + for (res = 1, pos = (char*) csArgs; (pos = strpbrk(pos, csDelim)); res++, pos++); + return res; +} + +/* * io_MakeAV() Parse and make attribute/value pair * * @csArgs = Input argument line @@ -616,4 +638,18 @@ io_gethostbyname(const char *psHost, u_short port, io_ } return NULL; +} + +/* + * io_usleep() - usleep() replacement for ELWIX + * + * @usec = microseconds for sleep + * return: -1 interrupted by signal or 0 ok + */ +inline int +io_usleep(u_int usec) +{ + struct timeval tv = { (time_t) (usec / 1000000), (long) (usec % 1000000) }; + + return select(0, NULL, NULL, NULL, &tv); }