-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc-4.6.1-timefmt.diff
165 lines (158 loc) · 4.82 KB
/
mc-4.6.1-timefmt.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#
# Adds an safe(r) strftime()/localtime() handling, as replacement
# for the "mc-4.6.1-invalid-mtime.diff" patch
#
# Source: metux
# Reference: 4.6.1
# Submit-By: Enrico Weigelt, metux IT service <weigelt@metux.de>
# Submit-Date: 2008-12-30
# Obsoletes: mc-4.6.1-invalid-mtime.diff
#
diff -ruN mc-4.6.1.orig/edit/edit.c mc-4.6.1/edit/edit.c
--- mc-4.6.1.orig/edit/edit.c 2008-12-30 01:52:56.000000000 +0100
+++ mc-4.6.1/edit/edit.c 2008-12-30 01:53:41.000000000 +0100
@@ -29,6 +29,7 @@
#include "../src/cmd.h" /* view_other_cmd() */
#include "../src/user.h" /* user_menu_cmd() */
#include "../src/wtools.h" /* query_dialog() */
+#include "../src/timefmt.h" /* time formatting */
/*
what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
@@ -2512,20 +2513,13 @@
break;
case CK_Date:{
- time_t t;
-#ifdef HAVE_STRFTIME
char s[1024];
/* fool gcc to prevent a Y2K warning */
char time_format[] = "_c";
time_format[0] = '%';
-#endif
- time (&t);
-#ifdef HAVE_STRFTIME
- strftime (s, sizeof (s), time_format, localtime (&t));
+
+ FMT_LOCALTIME_CURRENT(s, sizeof(s), time_format);
edit_print_string (edit, s);
-#else
- edit_print_string (edit, ctime (&t));
-#endif
edit->force |= REDRAW_PAGE;
break;
}
diff -ruN mc-4.6.1.orig/src/Makefile.am mc-4.6.1/src/Makefile.am
--- mc-4.6.1.orig/src/Makefile.am 2008-12-30 01:52:56.000000000 +0100
+++ mc-4.6.1/src/Makefile.am 2008-12-30 01:53:41.000000000 +0100
@@ -57,9 +57,9 @@
popt.c poptconfig.c popt.h popthelp.c poptint.h poptparse.c \
profile.c profile.h regex.c rxvt.c screen.c setup.c setup.h \
slint.c subshell.c subshell.h textconf.c textconf.h \
- tree.c tree.h treestore.c treestore.h tty.h user.c user.h \
- util.c util.h utilunix.c view.c view.h vfsdummy.h widget.c \
- widget.h win.c win.h wtools.c wtools.h \
+ tree.c tree.h treestore.c treestore.h timefmt.h tty.h user.c \
+ user.h util.c util.h utilunix.c view.c view.h vfsdummy.h \
+ widget.c widget.h win.c win.h wtools.c wtools.h \
x11conn.h x11conn.c
if CHARSET
diff -ruN mc-4.6.1.orig/src/timefmt.h mc-4.6.1/src/timefmt.h
--- mc-4.6.1.orig/src/timefmt.h 1970-01-01 01:00:00.000000000 +0100
+++ mc-4.6.1/src/timefmt.h 2008-12-30 01:53:41.000000000 +0100
@@ -0,0 +1,43 @@
+#ifndef __UTIL_TIMEFMT_H
+#define __UTIL_TIMEFMT_H
+
+#include <sys/types.h>
+
+#define INVALID_TIME_TEXT "(invalid)"
+
+#ifdef HAVE_STRFTIME
+
+/* safe localtime formatting - strftime()-using version */
+#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
+ { \
+ struct tm *whentm; \
+ whentm = localtime(&when); \
+ if (whentm == NULL) \
+ { \
+ strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
+ buffer[bufsize-1] = 0; \
+ } \
+ else \
+ { \
+ strftime(buffer, bufsize, fmt, whentm); \
+ } \
+ } \
+
+#else
+
+/* fallback when strftime/localtime not available */
+#define FMT_LOCALTIME(buffer,bufsize,fmt,when) \
+ { \
+ ctime_r(when,buffer); \
+ } \
+
+#endif
+
+#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
+ { \
+ time_t __current_time; \
+ time(&__current_time); \
+ FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
+ }
+
+#endif /* !__UTIL_H */
diff -ruN mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
--- mc-4.6.1.orig/src/util.c 2008-12-30 01:52:56.000000000 +0100
+++ mc-4.6.1/src/util.c 2008-12-30 01:53:41.000000000 +0100
@@ -39,6 +39,7 @@
#include "cmd.h" /* guess_message_value */
#include "mountlist.h"
#include "win.h" /* xterm_flag */
+#include "timefmt.h"
#ifdef HAVE_CHARSET
#include "charsets.h"
@@ -694,19 +695,28 @@
short-month-name sizes for different locales */
size_t i18n_checktimelength (void)
{
- size_t length, a, b;
- char buf [MAX_I18NTIMELENGTH + 1];
time_t testtime = time (NULL);
-
- a = strftime (buf, sizeof(buf)-1, _("%b %e %H:%M"), localtime(&testtime));
- b = strftime (buf, sizeof(buf)-1, _("%b %e %Y"), localtime(&testtime));
-
- length = max (a, b);
-
+ struct tm* lt = localtime(&testtime);
+ size_t length;
+
+ if (lt == NULL)
+ {
+ // huh, localtime() doesnt seem to work ... falling back to "(invalid)"
+ length = strlen(INVALID_TIME_TEXT);
+ }
+ else
+ {
+ char buf [MAX_I18NTIMELENGTH + 1];
+ size_t a, b;
+ a = strftime (buf, sizeof(buf)-1, _("%b %e %H:%M"), lt);
+ b = strftime (buf, sizeof(buf)-1, _("%b %e %Y"), lt);
+ length = max (a, b);
+ }
+
/* Don't handle big differences. Use standard value (email bug, please) */
if ( length > MAX_I18NTIMELENGTH || length < MIN_I18NTIMELENGTH )
length = STD_I18NTIMELENGTH;
-
+
return length;
}
@@ -740,7 +750,7 @@
else
fmt = fmttime;
- strftime (timebuf, i18n_timelength, fmt, localtime(&when));
+ FMT_LOCALTIME(timebuf, i18n_timelength, fmt, when);
return timebuf;
}