Fix and clean up strtotimeval
- parsing of fractional part was wrong (always parsed as 0) - return value was also wrong in the presence of fractional parts - general style clean up Change-Id: I1935a63db938dbed7cacb4b5646e993a52c27f1a Signed-off-by: Weichuan Yan <wchyan@marvell.com>
This commit is contained in:
parent
4bfaf462f0
commit
f1d7536dcf
@ -30,34 +30,29 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
char * strtotimeval (const char *str, struct timeval *ts)
|
char * strtotimeval(const char *str, struct timeval *ts) {
|
||||||
{
|
char *s;
|
||||||
int n;
|
long fs = 0; /* fractional seconds */
|
||||||
char *s, *s0;
|
|
||||||
long fs; /* Fractional seconds */
|
|
||||||
|
|
||||||
ts->tv_sec = strtoumax(str, &s, 10);
|
ts->tv_sec = strtoumax(str, &s, 10);
|
||||||
fs = 0;
|
|
||||||
|
|
||||||
if ( *s == '.' ) {
|
if (*s == '.') {
|
||||||
int count;
|
s++;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
s0 = s+1;
|
/* read up to 6 digits (microseconds) */
|
||||||
|
while (*s && isdigit(*s)) {
|
||||||
/* read up to 6 digits */
|
if (++count < 7) {
|
||||||
fs = 0;
|
fs = fs*10 + (*s - '0');
|
||||||
count = 0;
|
}
|
||||||
while ( *s && isdigit(*s) )
|
s++;
|
||||||
{
|
|
||||||
if ( ++count < 7 )
|
|
||||||
fs = fs*10 + (*s - '0');
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( ; count < 6; count++ )
|
|
||||||
fs *= 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ts->tv_usec = fs;
|
for (; count < 6; count++) {
|
||||||
return s;
|
fs *= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ts->tv_usec = fs;
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user