newlib: auto-detect sizeof(time_t)
To make the transition from 32-bit time_t to 64-bit time_t smoother, detect the size of this type in CMake and remove the manual option in Kconfig. The information about 64-bit time_t support is moved from Kconfig help string into the "system time" section of the API reference.
This commit is contained in:
@@ -130,6 +130,21 @@ To set local timezone, use the following POSIX functions:
|
||||
Once these steps are completed, call the standard C library function ``localtime()``, and it will return correct local time taking into account the time zone offset and daylight saving time.
|
||||
|
||||
|
||||
64-bit ``time_t``
|
||||
-----------------
|
||||
|
||||
ESP-IDF uses 32-bit ``time_t`` type by default. To address Y2K38 issue, you may need to use 64-bit ``time_t`` type when building the application.
|
||||
|
||||
Currently this requires building the cross-compiler toolchain from scratch. See the instructions for building the toolchain in :doc:`/get-started/linux-setup-scratch`. To enable 64-bit ``time_t`` support in the toolchain, you need to remove the ``--enable-newlib-long-time_t`` option from the ``crosstool-NG/samples/xtensa-esp32-elf/crosstool.config`` file before building the toolchain.
|
||||
|
||||
If you need to make the program compatible with both 32-bit and 64-bit ``time_t``, you may use the following methods:
|
||||
|
||||
- In C or C++ source files, ``_USE_LONG_TIME_T`` preprocessor macro will be defined if 32-bit ``time_t`` is used. You need to include ``<sys/types.h>`` to make this macro available.
|
||||
- In CMake files, ``TIME_T_SIZE`` IDF build property will be set to the size of ``time_t``, in bytes. You may call ``idf_build_get_property(var TIME_T_SIZE)`` to get the value of this property into a CMake variable ``var``. See :ref:`build system API reference <cmake_buildsystem_api>` for more information about ``idf_build_get_property``.
|
||||
|
||||
Note that the size of ``time_t`` type also affects the sizes of other types, for example ``struct timeval``, ``struct stat``, ``struct utimbuf``.
|
||||
|
||||
|
||||
API Reference
|
||||
-------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user