4 * Copyright (C) 2001 Jeffrey Fulmer <jdfulmer@armstrong.com>
5 * This file is part of LIBPING
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #endif /* HAVE_CONFIG_H */
33 # define strrchr rindex
34 # endif /* HAVE_STRCHR */
35 char *strchr (), *strrchr ();
37 # define memcpy(d, s, n) bcopy ((s), (d), (n))
38 # define memmove(d, s, n) bcopy ((s), (d), (n))
39 # endif /* HAVE_MEMCPY */
40 #endif /* STDC_HEADERS */
45 #include <sys/types.h>
51 * returns an int value for the difference
52 * between now and starttime in milliseconds.
55 elapsed_time( struct timeval *starttime ){
56 struct timeval *newtime;
58 newtime = (struct timeval*)malloc( sizeof(struct timeval));
59 gettimeofday(newtime,NULL);
62 if(( newtime->tv_usec - starttime->tv_usec) > 0 ){
63 elapsed += (newtime->tv_usec - starttime->tv_usec)/1000 ;
66 elapsed += ( 1000000 + newtime->tv_usec - starttime->tv_usec ) /1000;
69 if(( newtime->tv_sec - starttime->tv_sec ) > 0 ){
70 elapsed += 1000 * ( newtime->tv_sec - starttime->tv_sec );
81 * returns a char pointer from int start
85 substring (char *buffer, int start, int length)
88 sub = xmalloc (sizeof (char) * (length + 1));
90 if ((length < 1) || (start < 0) || (start > strlen (buffer)))
93 if (strlen (buffer) < length){
94 sub = (char*) strdup (buffer);
99 perror( "insufficient memory." );
103 memset (sub, 0, length + 1);
106 memcpy (sub, buffer, length);