-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.c
87 lines (77 loc) · 2.43 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* QTC: utils.c (c) 2011, 2012 50m30n3
*
* This file is part of QTC.
*
* QTC is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QTC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QTC. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
/*******************************************************************************
* Function to get the current time *
* *
* Returns the current time in microsecond accuracy *
*******************************************************************************/
unsigned long int get_time( void )
{
struct timeval tv;
gettimeofday( &tv, NULL );
return tv.tv_sec * 1000000lu + tv.tv_usec;
}
/*******************************************************************************
* Function to increase a numerical field in a filename *
* *
* name is a pointer to the file name *
* *
* Modifies name *
* *
* Returns 1 on success, 0 on overflow *
*******************************************************************************/
int inc_filename( char *name )
{
int i, carry, done;
carry = 1;
done = 0;
for( i=strlen( name )-1; i>=0; i-- )
{
if( ( name[i] >= '0' ) && ( name[i] <= '9' ) )
{
done = 1;
if( carry )
{
if( name[i] < '9' )
{
name[i]++;
carry = 0;
}
else
{
name[i] = '0';
carry = 1;
}
}
else
{
break;
}
}
else
{
if( done )
break;
}
}
return !carry;
}