Guest User

003_64Bit_time_t_Y2K38_safe.diff

a guest
Aug 25th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | Source Code | 0 0
  1. 64Bit_time_t.diff
  2.  
  3. Make Native Targets Date functionalty (hopefully) Year 2038+ Capable :-)
  4.  
  5. (only Change was the time.h: time_t as long long, the otp plugin is untestet)
  6.  
  7. As the (unsigned !) RTC Hardware Counter (per def.) starts at 0 in 1970
  8. it should be safe before 2104... (Than the 32Bit Counter rolls over)
  9.  
  10. Testet/used on Devices with a 32Bit RTC Counter as Hardware Clock
  11. (AS3514 based Sansa e200,ClipZip,Fuze, 4760b X3, x1000 native Fiio m3k, ErosQ)
  12.  
  13. I could set a Date after 2038 in the og Players, and after Powercycle,
  14. it was remembered...
  15. Test with Date 24.08.2093: Screendump has the Filename 'dump 930824-161026.bmp'
  16. and FileInfo 2093/08/24 in Rockbox Menue and FileInfo on Linux (SDCard Mounted)
  17. (RB Config Files config... nvram... :Fileinfo 2093/08/24...)
  18.  
  19. (needs way more Smoketesting before the Year 2038 Apocalypse...)
  20.  
  21. Mini-Credit ZappBranigan2972 on forums / F. Jacobsen on the Theme Site
  22.  
  23. ---
  24.  
  25. --- a/firmware/libc/include/time.h.orig 2023-12-31 10:51:38.079765097 +0100
  26. +++ b/firmware/libc/include/time.h  2023-12-31 09:37:11.293918321 +0100
  27. @@ -26,7 +26,7 @@
  28.  };
  29.  
  30.  #if !defined(_TIME_T_DEFINED) && !defined(_TIME_T_DECLARED)
  31. -typedef long time_t;
  32. +typedef long long time_t;
  33.  
  34.  /* this define below is used by the mingw headers to prevent duplicate
  35.     typedefs */
  36.  
  37. --- a/apps/plugins/otp.c.orig   2023-12-31 10:53:52.767339434 +0100
  38. +++ b/apps/plugins/otp.c    2023-12-31 09:37:56.225209097 +0100
  39. @@ -44,7 +44,7 @@
  40.  
  41.      union {
  42.          uint64_t hotp_counter;
  43. -        int totp_period;
  44. +        uint64_t totp_period;
  45.      };
  46.  
  47.      int digits;
  48. @@ -528,7 +528,7 @@
  49.  #if CONFIG_RTC
  50.      else
  51.      {
  52. -        rb->splashf(0, "%0*d (%ld seconds(s) left)", accounts[acct].digits,
  53. +        rb->splashf(0, "%0*d (%lld seconds(s) left)", accounts[acct].digits,
  54.                                                       TOTP(accounts[acct].secret,
  55.                                                            accounts[acct].sec_len,
  56.                                                            accounts[acct].totp_period,
  57. @@ -693,7 +693,7 @@
  58.              if(accounts[acct].is_totp)
  59.                  rb->snprintf(data_buf, sizeof(data_buf), "%d", (int)accounts[acct].hotp_counter);
  60.              else
  61. -                rb->snprintf(data_buf, sizeof(data_buf), "%d", accounts[acct].totp_period);
  62. +                rb->snprintf(data_buf, sizeof(data_buf), "%lld", accounts[acct].totp_period);
  63.  
  64.              if(rb->kbd_input(data_buf, sizeof(data_buf), NULL) < 0)
  65.                  break;
  66.  
Advertisement
Add Comment
Please, Sign In to add comment