summaryrefslogtreecommitdiffstats
path: root/src/dir.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2017-04-15 12:00:24 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2017-04-15 12:00:24 +0200
commita1419a0806b4270bfad92ea496624b2edee5062c (patch)
treed08d076cd116f0a05092d49ddac393bfc82ab3b9 /src/dir.c
parent1cba494e472d280483cc3bf05940efd061846a9e (diff)
Use localtime_t() instead of localtime()
Diffstat (limited to 'src/dir.c')
-rw-r--r--src/dir.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/src/dir.c b/src/dir.c
index ee9c16d..85b7689 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -153,6 +153,27 @@ void mode_string (const unsigned int mode, char *str)
#endif
}
+int set_datestr(char *datestr, size_t n, const time_t timev)
+{
+ int test_date=0;
+ struct tm tmp;
+ const struct tm *tm_p;
+ if(timev!=0 && (tm_p= localtime_r(&timev, &tmp))!=NULL)
+ {
+ snprintf(datestr, n,"%2d-%s-%4d %02d:%02d",
+ tm_p->tm_mday, monstr[tm_p->tm_mon],
+ 1900 + tm_p->tm_year, tm_p->tm_hour,
+ tm_p->tm_min);
+ if(1900+tm_p->tm_year>=2000 && 1900+tm_p->tm_year<=2014)
+ {
+ test_date=1;
+ }
+ } else {
+ strncpy(datestr, " ", n);
+ }
+ return test_date;
+}
+
int dir_aff_log(const dir_data_t *dir_data, const file_info_t *dir_list)
{
int test_date=0;
@@ -166,23 +187,7 @@ int dir_aff_log(const dir_data_t *dir_data, const file_info_t *dir_list)
const file_info_t *current_file=td_list_entry_const(file_walker, const file_info_t, list);
char datestr[80];
char str[11];
- {
- const struct tm *tm_p;
- if(current_file->td_mtime && (tm_p = localtime(&current_file->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* FIXME: a check using current_file->name will be better */
- if(1900+tm_p->tm_year>=2000 && 1900+tm_p->tm_year<=2014)
- {
- test_date=1;
- }
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ test_date=set_datestr((char *)&datestr, sizeof(datestr), current_file->td_mtime);
mode_string(current_file->st_mode, str);
if((current_file->status&FILE_STATUS_DELETED)!=0)
log_info("X");
@@ -225,23 +230,7 @@ int log_list_file(const disk_t *disk, const partition_t *partition, const dir_da
log_info("X");
else
log_info(" ");
- {
- const struct tm *tm_p;
- if(current_file->td_mtime && (tm_p = localtime(&current_file->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* FIXME: a check using current_file->name will be better */
- if(1900+tm_p->tm_year>=2000 && 1900+tm_p->tm_year<=2014)
- {
- test_date=1;
- }
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ test_date=set_datestr((char *)&datestr, sizeof(datestr), current_file->td_mtime);
mode_string(current_file->st_mode, str);
log_info("%7lu ",(unsigned long int)current_file->st_ino);
log_info("%s %5u %5u ",