1. 03 Oct, 2016 2 commits
    • Elliott Hughes's avatar
      Add missing O_CLOEXEC and TEMP_FAILURE_RETRY to localtime.c. · 4edd651e
      Elliott Hughes authored
      Follow-on change from http://b/31848040.
      
      Test: *time* tests.
      Change-Id: I3f1c9ce19b90f6f8c1ac6e0753e3fed0ff63c0b4
      4edd651e
    • Elliott Hughes's avatar
      Fix tzdata loading. · 81c46fc1
      Elliott Hughes authored
      Android uses one large file of tzdata, so the "read up to the maximum
      possible length of a valid tzfile" code in upstream localtime.c is
      broken: there is always data after the current tzfile (even the
      last tzfile is followed by the zone.tab data). This patch passes the
      exact length through to the read(2) call so we don't over-read, rather
      than have to rewrite upstream code that measures back from the "end" of
      the tzfile.
      
      The old code failed the existing time.strftime_null_tm_zone test after
      updating to tzdata2016g.
      
      Bug: http://b/31848040
      Test: time.strftime_null_tm_zone
      Change-Id: Iee059b5a8c051bd4952cfd80f02b00d83e489d5e
      81c46fc1
  2. 17 Sep, 2016 1 commit
  3. 12 Aug, 2016 1 commit
  4. 29 Jul, 2016 1 commit
    • Elliott Hughes's avatar
      Upgrade to tzcode-2016f. · 0a610d00
      Elliott Hughes authored
      No significant changes other than a default implementation of strftime_l.
      
      Change-Id: I6edd2c03e5e7559f012c0c87d43f7109d641d3ca
      0a610d00
  5. 21 Jul, 2016 1 commit
    • Elliott Hughes's avatar
      Treat "persist.sys.timezone" as being a Java-format timezone. · 3e3f4a51
      Elliott Hughes authored
      POSIX and Java disagree about the sign in a timezone string like "GMT+3".
      This means that if you set "persist.sys.timezone" to such a string, native
      code and Java code disagree about what time it is. Resolve this by
      translating to POSIX form for native code.
      
      Bug: http://b/25463955
      Change-Id: I7c08c459dd8514348a12ce419edcbfbfe8f6d327
      Test: manually tested with setprop and date.
      3e3f4a51
  6. 06 Jan, 2016 1 commit
  7. 13 Nov, 2015 2 commits
    • Elliott Hughes's avatar
      Improve libc time zone fallback behavior. · d1c28a36
      Elliott Hughes authored
      We should fall back to GMT if neither the environment variable nor the
      system property is set. This is the case if you wipe a WiFi-only device,
      because we currently only take the time zone from cell networks.
      
      Bug: http://b/24773112
      Change-Id: I90d236d4d492b6562d75021bd312030b91c1e298
      d1c28a36
    • Elliott Hughes's avatar
      Fix strftime if tm_zone is null. · a9cac4c8
      Elliott Hughes authored
      Upstream tzcode said "On platforms with tm_zone, strftime.c now assumes it
      is not NULL". Which is fine for any struct tm generated by tzcode, but not
      necessarily true of a struct tm constructed by arbitrary code. In particular,
      Netflix on Nexus Player was failing to start because they format "%Z" with
      a struct tm whose tm_zone is null (the other fields are valid, but, yeah,
      that's probably not intentional).
      
      glibc takes a null tm_zone to mean "the current time zone", so let's do that
      too. (Historically Android would use the empty string, and POSIX doesn't
      clarify which of this is the appropriate behavior when tm_zone is null.)
      
      Bug: http://b/25170306
      Change-Id: Idbf68bfe90d143aca7dada8607742905188b1d33
      a9cac4c8
  8. 02 Nov, 2015 1 commit
    • Christopher Ferris's avatar
      Fix comment to reflect the actual reality. · 384ffe34
      Christopher Ferris authored
      The original comment implied that Android 32 bit was the only one
      using a bad time_t, but it turns out 32 bit glibc has the same time_t
      as Android. Update the comment to reflect this reality.
      
      Change-Id: I72cdd2c677a6521f7b43d4695a52fd8fdc3305bd
      384ffe34
  9. 09 Oct, 2015 1 commit
    • Elliott Hughes's avatar
      Sync with upstream tzcode (2015g). · 9fb22a3e
      Elliott Hughes authored
      This is quite a large patch because we haven't updated for some time,
      but the good news is that upstream is now thread-safe so a lot of our
      changes go away in this update and the remaining diff is a lot smaller.
      
      (Note that our whitespace still doesn't match upstream. I use diff -wub
      to compare. Upstream doesn't even really have a consistent style. New
      code seems to be two spaces, old code tabs.)
      
      From the intervening changelogs (eliding the changes that only affected
      the tools, which we don't use):
      
      2014a:
           An uninitialized-storage bug in 'localtime' has been fixed.
           (Thanks to Logan Chien.)
      
      2014b:
           'zic' and 'localtime' no longer reject locations needing four
           transitions per year for the forseeable future.  (Thanks to Andrew
           Main (Zefram).)
      
      2014c:
           <None>
      
      2014d:
           <None>
      
      2014e:
           <None>
      
      2014f:
           'localtime', 'mktime', etc. now use much less stack space if
           ALL_STATE is defined.  (Thanks to Elliott Hughes for reporting the
           problem.)
      
           Some lint has been removed when using GCC_DEBUG_FLAGS with GCC
           4.9.0.
      
      2014g:
           Unless NETBSD_INSPIRED is defined to 0, the tz library now
           supplies functions for creating and using objects that represent
           time zones. The new functions are tzalloc, tzfree, localtime_rz,
           mktime_z, and (if STD_INSPIRED is also defined) posix2time_z and
           time2posix_z.  They are intended for performance: for example,
           localtime_rz (unlike localtime_r) is trivially thread-safe without
           locking.  (Thanks to Christos Zoulas for proposing NetBSD-inspired
           functions, and to Alan Barrett and Jonathan Lennox for helping to
           debug the change.)
      
           If THREAD_SAFE is defined to 1, the tz library is now thread-safe.
           Although not needed for tz's own applications, which are single-threaded,
           this supports POSIX better if the tz library is used in multithreaded apps.
      
           Some crashes have been fixed when zdump or the tz library is given
           invalid or outlandish input.
      
           The tz library no longer mishandles leap seconds on platforms with
           unsigned time_t in time zones that lack ordinary transitions after 1970.
      
           The tz code now attempts to infer TM_GMTOFF and TM_ZONE if not
           already defined, to make it easier to configure on common platforms.
           Define NO_TM_GMTOFF and NO_TM_ZONE to suppress this.
      
           Unless the new macro UNINIT_TRAP is defined to 1, the tz code now
           assumes that reading uninitialized memory yields garbage values
           but does not cause other problems such as traps.
      
           If TM_GMTOFF is defined and UNINIT_TRAP is 0, mktime is now
           more likely to guess right for ambiguous time stamps near
           transitions where tm_isdst does not change.
      
           If HAVE_STRFTIME_L is defined to 1, the tz library now defines
           strftime_l for compatibility with recent versions of POSIX.
           Only the C locale is supported, though.  HAVE_STRFTIME_L defaults
           to 1 on recent POSIX versions, and to 0 otherwise.
      
           tzselect -c now uses a hybrid distance measure that works better
           in Africa.  (Thanks to Alan Barrett for noting the problem.)
      
           The C source code now ports to NetBSD when GCC_DEBUG_FLAGS is used,
           or when time_tz is defined.
      
           When HAVE_UTMPX_H is set the 'date' command now builds on systems
           whose <utmpx.h> file does not define WTMPX_FILE, and when setting
           the date it updates the wtmpx file if _PATH_WTMPX is defined.
           This affects GNU/Linux and similar systems.
      
           For easier maintenance later, some C code has been simplified,
           some lint has been removed, and the code has been tweaked so that
           plain 'make' is more likely to work.
      
           The C type 'bool' is now used for boolean values, instead of 'int'.
      
           The long-obsolete LOCALE_HOME code has been removed.
      
           The long-obsolete 'gtime' function has been removed.
      
      2014h:
           The tz library's localtime and mktime functions now set tzname to a value
           appropriate for the requested time stamp, and zdump now uses this
           on platforms not defining TM_ZONE, fixing a 2014g regression.
           (Thanks to Tim Parenti for reporting the problem.)
      
           The tz library no longer sets tzname if localtime or mktime fails.
      
           An access to uninitalized data has been fixed.
           (Thanks to Jörg Richter for reporting the problem.)
      
           When THREAD_SAFE is defined, the code ports to the C11 memory model.
           A memory leak has been fixed if ALL_STATE and THREAD_SAFE are defined
           and two threads race to initialize data used by gmtime-like functions.
           (Thanks to Andy Heninger for reporting the problems.)
      
      2014i:
           The time-related library functions now set errno on failure,
           and some crashes in the new tzalloc-related library functions
           have been fixed.  (Thanks to Christos Zoulas for reporting
           most of these problems and for suggesting fixes.)
      
           If USG_COMPAT is defined and the requested time stamp is
           standard time, the tz library's localtime and mktime functions
           now set the extern variable timezone to a value appropriate
           for that time stamp; and similarly for ALTZONE, daylight
           saving time, and the altzone variable.  This change is a
           companion to the tzname change in 2014h, and is designed to
           make timezone and altzone more compatible with tzname.
      
           The tz library's functions now set errno to EOVERFLOW if they
           fail because the result cannot be represented.  ctime and
           ctime_r now return NULL and set errno when a time stamp is out
           of range, rather than having undefined behavior.
      
           Some bugs associated with the new 2014g functions have been
           fixed.  This includes a bug that largely incapacitated the new
           functions time2posix_z and posix2time_z.  (Thanks to Christos
           Zoulas.)  It also includes some uses of uninitialized
           variables after tzalloc.  The new code uses the standard type
           'ssize_t', which the Makefile now gives porting advice about.
      
      2014j:
           <None>
      
      2015a:
           tzalloc now scrubs time zone abbreviations compatibly with the way
           that tzset always has, by replacing invalid bytes with '_' and by
           shortening too-long abbreviations.
      
      2015b:
           Fix integer overflow bug in reference 'mktime' implementation.
           (Problem reported by Jörg Richter.)
      
           Allow -Dtime_tz=time_t compilations, and allow -Dtime_tz=... libraries
           to be used in the same executable as standard-library time_t functions.
           (Problems reported by Bradley White.)
      
      2015c:
           <None>
      
      2015d:
           <None>
      
      2015e:
           <None>
      
      2015f:
           <None>
      
      2015g:
          localtime no longer mishandles America/Anchorage after 2037.
          (Thanks to Bradley White for reporting the bug.)
      
          On hosts with signed 32-bit time_t, localtime no longer mishandles
          Pacific/Fiji after 2038-01-16 14:00 UTC.
      
          The localtime module allows the variables 'timezone', 'daylight',
          and 'altzone' to be in common storage shared with other modules,
          and declares them in case the system <time.h> does not.
          (Problems reported by Kees Dekker.)
      
          On platforms with tm_zone, strftime.c now assumes it is not NULL.
          This simplifies the code and is consistent with zdump.c.
          (Problem reported by Christos Zoulas.)
      
      Change-Id: I9eb0a8323cb8bd9968fcfe612dc14f45aa3b59d2
      9fb22a3e
  10. 02 Oct, 2015 1 commit
    • Mark Salyzyn's avatar
      bionic: tzset running hot · d0578949
      Mark Salyzyn authored
      logd makes a non-insignificant number of calls to localtime, 3% of
      the time in logd is spent performing __system_property_get within the
      context of tzset_locked().
      
      Bug: 23685592
      Change-Id: I75f8c2d436b60374e92c166b87393abda9487af7
      d0578949
  11. 29 Sep, 2015 1 commit
    • Stephen Hines's avatar
      Remove invalid left shifts of -1. · 23360cc4
      Stephen Hines authored
      Bug: 24492248
      
      Shifting sign bits left is considered undefined behavior, so we need to
      switch these uses to unsigned equivalents. The time_t-related code is
      updated relative to upstream sources.
      
      Change-Id: I226e5a929a10f5c57dfcb90c748fdac34eb377c2
      23360cc4
  12. 25 Mar, 2015 1 commit
  13. 15 Nov, 2014 1 commit
    • Satoru Takeuchi's avatar
      libc: Fix mktime returns an uncorrect time in empty TZ case · 154e2026
      Satoru Takeuchi authored
      The mktime API returned an uncorrect time when TZ is set as empty.
      A timezone UTC/GMT+0 should be implied in the empty case. However
      mktime keeps previous information about timezone. If mktime was called
      with a timezone which has DST before, the "defaulttype" member of
      "state" structure wouldn't be 0. Then it would be used next time,
      even though UTC/GMT+0 doesn't have DST.
      
      Added initialization of the "defaulttype" in the empty TZ case.
      
      Change-Id: Ic480c63c548c05444134e0aefb30a7b380e3f40b
      154e2026
  14. 28 Oct, 2014 1 commit
  15. 27 Oct, 2014 1 commit
  16. 09 Oct, 2014 1 commit
    • Dan Albert's avatar
      Use snprintf(3) instead of sprintf(3). · ca75f9cd
      Dan Albert authored
      This change should probably be made upstream as well, but they have a
      note about not using it because it isn't available on all systems.
      
      Change-Id: I6d8404c031bd2f486532ced55d94bbb4a4cd2e71
      ca75f9cd
  17. 07 Aug, 2014 1 commit
    • Elliott Hughes's avatar
      Fix the tzdata update tools. · 13bab433
      Elliott Hughes authored
      The recent libcore ZoneInfo changes mean that we can no longer
      compile libcore's ZoneInfo against the RI. Luckily, the field in
      our data file that we needed ZoneInfo for isn't actually used.
      This change removes our dependence on libcore.
      
      I've left the field in to avoid a file format change. We can remove
      the field if/when we next have a real need to bump the file format.
      
      (cherry-pick of 90cb5ffb.)
      
      Bug: 16168653
      Change-Id: Iedad2252c2b49f4d8bb2c7d9078b39b622444ca7
      13bab433
  18. 06 Aug, 2014 1 commit
    • Elliott Hughes's avatar
      Fix the tzdata update tools. · 90cb5ffb
      Elliott Hughes authored
      The recent libcore ZoneInfo changes mean that we can no longer
      compile libcore's ZoneInfo against the RI. Luckily, the field in
      our data file that we needed ZoneInfo for isn't actually used.
      This change removes our dependence on libcore.
      
      I've left the field in to avoid a file format change. We can remove
      the field if/when we next have a real need to bump the file format.
      
      Bug: 16168653
      Change-Id: Iedad2252c2b49f4d8bb2c7d9078b39b622444ca7
      90cb5ffb
  19. 26 Jul, 2014 1 commit
    • Elliott Hughes's avatar
      Remove localtime_tz and strftime_tz. · c1a6a725
      Elliott Hughes authored
      This also brings our copy of strftime.c much closer to upstream, though
      we still have several GNU extensions and hacks to deal with Android32's
      broken time_t.
      
      Bug: 15765976
      
      (cherry picked from commit 39d903ae)
      
      Change-Id: Ie278d3e976b7adc77bad5ce795dd4899cfbf3648
      c1a6a725
  20. 25 Jul, 2014 3 commits
  21. 19 Jun, 2014 4 commits
    • Elliott Hughes's avatar
      Build tzcode with hidden visibility. · d10db826
      Elliott Hughes authored
      Bug: 11156955
      Change-Id: Ib98d837b56cbbdfd01687cb3054fe3103eec0da9
      d10db826
    • Elliott Hughes's avatar
      Fix arm64 localtime.c build. · 2cb75266
      Elliott Hughes authored
      I'm sick of having so many different compilers.
      
      Change-Id: I9088c38df2504e2b827d0ce5ba0fa551ae48f8f9
      2cb75266
    • Elliott Hughes's avatar
      Build tzcode with -Werror. · 5f564540
      Elliott Hughes authored
      Parts of this are just getting us in sync with upstream, but the
      'const' stuff is our own mess. We should kill the *_tz functions
      and lose this difference from upstream.
      
      Change-Id: I17d26534ed3f54667143d78147a8c53be56d7b33
      5f564540
    • Elliott Hughes's avatar
      Update localtime.c. · 906eb999
      Elliott Hughes authored
      This brings us closer to upstream's ToT localtime.c; our main interest
      being their alternative fix for the stack usage we addressed in commit
      8a8b0c9b.
      
      Bug: 14468519
      Change-Id: Ic28600115afda7f3158d91255edf422678bac082
      906eb999
  22. 12 Jun, 2014 1 commit
  23. 14 May, 2014 2 commits
    • Christopher Ferris's avatar
      Do not keep struct state on the stack. · 8a8b0c9b
      Christopher Ferris authored
      This structure is huge (~18000 bytes on arm64) and can blow out
      the stack very easily.
      Modify the code to allocate these structures instead of leaving them
      on the stack.
      
      Bug: 14468519
      Change-Id: I774f71235d896d32a14ab1af06f95ca9ef819f52
      8a8b0c9b
    • Elliott Hughes's avatar
      Switch to g_ for globals. · 1728b239
      Elliott Hughes authored
      That's what the Google style guide recommends, and we're starting
      to get a mix.
      
      Change-Id: Ib0c53a890bb5deed5c679e887541a715faea91fc
      1728b239
  24. 06 May, 2014 2 commits
    • Elliott Hughes's avatar
      Fix <math.h> to quieten most of our warnings. · 9a5a3e8e
      Elliott Hughes authored
      I've reported the wcsftime bug upstream, but we really just want to use -D
      to ensure the buggy code isn't built. (I've also brought our strftime a bit
      closer to upstream now we have the right define.)
      
      I don't think upstream is likely to fix all their sign-compare and
      uninitialized warnings, so let's just silence them.
      
      As for libm, again upstream isn't likely to fix all their warnings, and
      silencing those made the ones that were our fault stand out. I've fixed
      our <math.h> to fix the warnings caused by our lack of definitions for
      the non-imprecise long-double functions. I checked the C99 standard, and
      all these functions are there.
      
      Change-Id: Iee8e1182c1db375058fb2c451eceb212bab47a37
      9a5a3e8e
    • Elliott Hughes's avatar
      Remove the non-standard time64 stuff for LP64. · 52defb7c
      Elliott Hughes authored
      We need a workaround in strftime as long as we still need to support
      64-bit times on LP32.
      
      Change-Id: I8ffb616f6312d4063fb9ea3c36b52653e8f4c5f8
      52defb7c
  25. 26 Apr, 2014 1 commit
  26. 28 Feb, 2014 4 commits
  27. 09 Oct, 2013 2 commits
    • Elliott Hughes's avatar
      Fix x86_64 build, clean up intermediate libraries. · eb847bc8
      Elliott Hughes authored
      The x86_64 build was failing because clone.S had a call to __thread_entry which
      was being added to a different intermediate .a on the way to making libc.so,
      and the linker couldn't guarantee statically that such a relocation would be
      possible.
      
        ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC
      
      This patch addresses that by ensuring that the caller and callee end up in the
      same intermediate .a. While I'm here, I've tried to clean up some of the mess
      that led to this situation too. In particular, this removes libc/private/ from
      the default include path (except for the DNS code), and splits out the DNS
      code into its own library (since it's a weird special case of upstream NetBSD
      code that's diverged so heavily it's unlikely ever to get back in sync).
      
      There's more cleanup of the DNS situation possible, but this is definitely a
      step in the right direction, and it's more than enough to get x86_64 building
      cleanly.
      
      Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
      eb847bc8
    • Elliott Hughes's avatar
      Fix 32-bit build. · 51aeff70
      Elliott Hughes authored
        libc/tzcode/localtime.c: In function 'differ_by_repeat':
        libc/tzcode/localtime.c:338:2: error: comparison is always false due to limited range of data type [-Werror=type-limits]
      
      Change-Id: Ic84be6391a66e9d50ed98f41d865387c77a60ffa
      51aeff70