summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2019-09-18 14:43:26 +0200
committerVictor Kareh <[email protected]>2019-10-01 22:06:07 -0400
commitf70a69eb07d5b240f1ca7b53bf42077702cded01 (patch)
treed2b9b09d58e6c08fae5a0940abe8ccc3fa56401c
parent338cf0257c2fd8a4d404a85a397f2020d4437af6 (diff)
downloadengrampa-f70a69eb07d5b240f1ca7b53bf42077702cded01.tar.bz2
engrampa-f70a69eb07d5b240f1ca7b53bf42077702cded01.tar.xz
fr-command-tar: fetch dates with strptime
-rw-r--r--src/fr-command-tar.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/src/fr-command-tar.c b/src/fr-command-tar.c
index 439a12e..61800ce 100644
--- a/src/fr-command-tar.c
+++ b/src/fr-command-tar.c
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define _XOPEN_SOURCE /* strptime */
+
#include <config.h>
#include <sys/types.h>
@@ -39,6 +41,7 @@
#include "fr-command-tar.h"
#define ACTIVITY_DELAY 20
+#define LSTAR_DATE_FORMAT "%Y-%m-%d %H:%M"
static void fr_command_tar_class_init (FrCommandTarClass *class);
static void fr_command_tar_init (FrCommand *afile);
@@ -52,40 +55,11 @@ static FrCommandClass *parent_class = NULL;
/* -- list -- */
static time_t
-mktime_from_string (char *date_s,
- char *time_s)
+mktime_from_string (const char *time_s)
{
- struct tm tm = {0, };
- char **fields;
-
+ struct tm tm = {0, };
tm.tm_isdst = -1;
-
- /* date */
-
- fields = g_strsplit (date_s, "-", 3);
- if (fields[0] != NULL) {
- tm.tm_year = atoi (fields[0]) - 1900;
- if (fields[1] != NULL) {
- tm.tm_mon = atoi (fields[1]) - 1;
- if (fields[2] != NULL)
- tm.tm_mday = atoi (fields[2]);
- }
- }
- g_strfreev (fields);
-
- /* time */
-
- fields = g_strsplit (time_s, ":", 3);
- if (fields[0] != NULL) {
- tm.tm_hour = atoi (fields[0]);
- if (fields[1] != NULL) {
- tm.tm_min = atoi (fields[1]);
- if (fields[2] != NULL)
- tm.tm_sec = atoi (fields[2]);
- }
- }
- g_strfreev (fields);
-
+ strptime (time_s, LSTAR_DATE_FORMAT, &tm);
return mktime (&tm);
}
@@ -128,7 +102,7 @@ process_line (char *line,
FrCommand *comm = FR_COMMAND (data);
char **fields;
int date_idx;
- char *field_date, *field_time, *field_size, *field_name;
+ char *field_date, *field_size, *field_name;
char *name;
g_return_if_fail (line != NULL);
@@ -143,11 +117,9 @@ process_line (char *line,
fdata->size = g_ascii_strtoull (field_size, NULL, 10);
g_free (field_size);
- field_date = file_list__get_next_field (line, date_idx, 1);
- field_time = file_list__get_next_field (line, date_idx, 2);
- fdata->modified = mktime_from_string (field_date, field_time);
+ field_date = g_strndup (line + date_idx, 16);
+ fdata->modified = mktime_from_string (field_date);
g_free (field_date);
- g_free (field_time);
/* Full path */