From f7045c57cd94700d64ef4e18b4733c9d8cab1e79 Mon Sep 17 00:00:00 2001 From: Salvador Cuñat Date: Sun, 22 Jan 2017 14:05:06 +0100 Subject: smtk-import-improve smtk_time_to_secs() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- smtk-import/smartrak.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'smtk-import') diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index e102c1abd..3fd8db6de 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -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; } -- cgit v1.2.3-70-g09d2