#
# 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
# State: new
#
diff -ruN mc-4.6.1.orig/edit/edit.c mc-4.6.1/edit/edit.c
old
|
new
|
|
29 | 29 | #include "../src/cmd.h" /* view_other_cmd() */ |
30 | 30 | #include "../src/user.h" /* user_menu_cmd() */ |
31 | 31 | #include "../src/wtools.h" /* query_dialog() */ |
| 32 | #include "../src/timefmt.h" /* time formatting */ |
32 | 33 | |
33 | 34 | /* |
34 | 35 | what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL |
… |
… |
|
2512 | 2513 | break; |
2513 | 2514 | |
2514 | 2515 | case CK_Date:{ |
2515 | | time_t t; |
2516 | | #ifdef HAVE_STRFTIME |
2517 | 2516 | char s[1024]; |
2518 | 2517 | /* fool gcc to prevent a Y2K warning */ |
2519 | 2518 | char time_format[] = "_c"; |
2520 | 2519 | time_format[0] = '%'; |
2521 | | #endif |
2522 | | time (&t); |
2523 | | #ifdef HAVE_STRFTIME |
2524 | | strftime (s, sizeof (s), time_format, localtime (&t)); |
| 2520 | |
| 2521 | FMT_LOCALTIME_CURRENT(s, sizeof(s), time_format); |
2525 | 2522 | edit_print_string (edit, s); |
2526 | | #else |
2527 | | edit_print_string (edit, ctime (&t)); |
2528 | | #endif |
2529 | 2523 | edit->force |= REDRAW_PAGE; |
2530 | 2524 | break; |
2531 | 2525 | } |
diff -ruN mc-4.6.1.orig/src/Makefile.am mc-4.6.1/src/Makefile.am
old
|
new
|
|
57 | 57 | popt.c poptconfig.c popt.h popthelp.c poptint.h poptparse.c \ |
58 | 58 | profile.c profile.h regex.c rxvt.c screen.c setup.c setup.h \ |
59 | 59 | slint.c subshell.c subshell.h textconf.c textconf.h \ |
60 | | tree.c tree.h treestore.c treestore.h tty.h user.c user.h \ |
61 | | util.c util.h utilunix.c view.c view.h vfsdummy.h widget.c \ |
62 | | widget.h win.c win.h wtools.c wtools.h \ |
| 60 | tree.c tree.h treestore.c treestore.h timefmt.h tty.h user.c \ |
| 61 | user.h util.c util.h utilunix.c view.c view.h vfsdummy.h \ |
| 62 | widget.c widget.h win.c win.h wtools.c wtools.h \ |
63 | 63 | x11conn.h x11conn.c |
64 | 64 | |
65 | 65 | if CHARSET |
diff -ruN mc-4.6.1.orig/src/timefmt.h mc-4.6.1/src/timefmt.h
old
|
new
|
|
| 1 | #ifndef __UTIL_TIMEFMT_H |
| 2 | #define __UTIL_TIMEFMT_H |
| 3 | |
| 4 | #include <sys/types.h> |
| 5 | |
| 6 | #define INVALID_TIME_TEXT "(invalid)" |
| 7 | |
| 8 | #ifdef HAVE_STRFTIME |
| 9 | |
| 10 | /* safe localtime formatting - strftime()-using version */ |
| 11 | #define FMT_LOCALTIME(buffer, bufsize, fmt, when) \ |
| 12 | { \ |
| 13 | struct tm *whentm; \ |
| 14 | whentm = localtime(&when); \ |
| 15 | if (whentm == NULL) \ |
| 16 | { \ |
| 17 | strncpy(buffer, INVALID_TIME_TEXT, bufsize); \ |
| 18 | buffer[bufsize-1] = 0; \ |
| 19 | } \ |
| 20 | else \ |
| 21 | { \ |
| 22 | strftime(buffer, bufsize, fmt, whentm); \ |
| 23 | } \ |
| 24 | } \ |
| 25 | |
| 26 | #else |
| 27 | |
| 28 | /* fallback when strftime/localtime not available */ |
| 29 | #define FMT_LOCALTIME(buffer,bufsize,fmt,when) \ |
| 30 | { \ |
| 31 | ctime_r(when,buffer); \ |
| 32 | } \ |
| 33 | |
| 34 | #endif |
| 35 | |
| 36 | #define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \ |
| 37 | { \ |
| 38 | time_t __current_time; \ |
| 39 | time(&__current_time); \ |
| 40 | FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \ |
| 41 | } |
| 42 | |
| 43 | #endif /* !__UTIL_H */ |
diff -ruN mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
old
|
new
|
|
39 | 39 | #include "cmd.h" /* guess_message_value */ |
40 | 40 | #include "mountlist.h" |
41 | 41 | #include "win.h" /* xterm_flag */ |
| 42 | #include "timefmt.h" |
42 | 43 | |
43 | 44 | #ifdef HAVE_CHARSET |
44 | 45 | #include "charsets.h" |
… |
… |
|
694 | 695 | short-month-name sizes for different locales */ |
695 | 696 | size_t i18n_checktimelength (void) |
696 | 697 | { |
697 | | size_t length, a, b; |
698 | | char buf [MAX_I18NTIMELENGTH + 1]; |
699 | 698 | time_t testtime = time (NULL); |
700 | | |
701 | | a = strftime (buf, sizeof(buf)-1, _("%b %e %H:%M"), localtime(&testtime)); |
702 | | b = strftime (buf, sizeof(buf)-1, _("%b %e %Y"), localtime(&testtime)); |
703 | | |
704 | | length = max (a, b); |
705 | | |
| 699 | struct tm* lt = localtime(&testtime); |
| 700 | size_t length; |
| 701 | |
| 702 | if (lt == NULL) |
| 703 | { |
| 704 | // huh, localtime() doesnt seem to work ... falling back to "(invalid)" |
| 705 | length = strlen(INVALID_TIME_TEXT); |
| 706 | } |
| 707 | else |
| 708 | { |
| 709 | char buf [MAX_I18NTIMELENGTH + 1]; |
| 710 | size_t a, b; |
| 711 | a = strftime (buf, sizeof(buf)-1, _("%b %e %H:%M"), lt); |
| 712 | b = strftime (buf, sizeof(buf)-1, _("%b %e %Y"), lt); |
| 713 | length = max (a, b); |
| 714 | } |
| 715 | |
706 | 716 | /* Don't handle big differences. Use standard value (email bug, please) */ |
707 | 717 | if ( length > MAX_I18NTIMELENGTH || length < MIN_I18NTIMELENGTH ) |
708 | 718 | length = STD_I18NTIMELENGTH; |
709 | | |
| 719 | |
710 | 720 | return length; |
711 | 721 | } |
712 | 722 | |
… |
… |
|
740 | 750 | else |
741 | 751 | fmt = fmttime; |
742 | 752 | |
743 | | strftime (timebuf, i18n_timelength, fmt, localtime(&when)); |
| 753 | FMT_LOCALTIME(timebuf, i18n_timelength, fmt, when); |
744 | 754 | return timebuf; |
745 | 755 | } |
746 | 756 | |