smtk-import-improve smtk_time_to_secs()

Can't remember what I was thinking when wrote that crappy thing. A
simple sscanf call will do the job, and a sanity check, off course.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
This commit is contained in:
Salvador Cuñat 2017-01-22 14:05:06 +01:00 committed by Dirk Hohndel
parent 7c91cdd89e
commit f7045c57cd

View file

@ -118,15 +118,11 @@ static void smtk_time_to_tm(char *t_buffer, struct tm *tm_date)
*/
static unsigned int smtk_time_to_secs(char *t_buffer)
{
char *temp;
unsigned int hr, min, sec;
unsigned int n, hr, min, sec;
if (!same_string(t_buffer, "")) {
temp = rindex(copy_string(t_buffer), ' ');
hr = atoi(strtok(temp, ":"));
min = atoi(strtok(NULL, ":"));
sec = atoi(strtok(NULL, "\0"));
return((((hr*60)+min)*60)+sec);
n = sscanf(t_buffer, "%*m[/0-9] %d:%d:%d ", &hr, &min, &sec);
return((n == 3) ? (((hr*60)+min)*60)+sec : 0);
} else {
return 0;
}