[PATCH] libc/time/gmtime_r.c, libc/time/lcltime_r.c,, libc/time/local.h, libc/time/mktm_r.c: move localtime related functionality, from _mktm_r() to new _mklocaltm_r() to break dependency of gmtime() on, timezones

Corinna Vinschen vinschen@redhat.com
Thu Sep 4 08:36:00 GMT 2014


Hi,

On Sep  3 21:59, Freddie Chopin wrote:
> Hello again (;
> 
> I attach patch and a ChangeLog entry with a bigger change to time-related
> sources.
> 
> Currently functions gmtime() and localtime() are both implemented with
> common code in _mktm_r(), which decides whether to do time zone adjustments
> by additional parameter - is_gmtime, true for gmtime() and false for
> localtime(). This way if you use gmtime() and don't care about time zones,
> you get them anyway in the final binary.
> 
> This change moves all time zone related stuff from _mktm_r() to new function
> _mklocaltm_r(). gmtime_r() still calls _mktm_r() (but with this boolean
> parameter removed), while localtime_r() first calls _mktm_r() and then calls
> _mklocaltm_r() using the result of _mktm_r().
> 
> This way you get time zone stuff in the final link only if it's really
> needed - when you use localtime(). If you use just gmtime(), the time zone
> functions are not linked, which saves about 1kB of flash and a little below
> 100B of RAM (on ARM Cortex-M3). (the savings would be bigger if proper locks
> are implemented - by default only stubs are used and no code for mutexes is
> needed)

How does that work?  _mktm_r and _mklocaltm_r are still in the same source
file, so if you get one, you also get the other.  Where did you get your
savings from?

> Actually the names of the functions are not 100% good, but changing the name
> of _mktm_r() to something clearer (_mkgmtime_r()?) should come with changing
> the name of the source file, so I decided to leave that as it is... If you
> think that the names should change too, I could modify the patch and extend
> it.

Since these are internal functions, I think the names are fine.  Comments
preceding _mktm_r and _mklocaltm_r would be nice.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20140904/db89ceab/attachment.sig>


More information about the Newlib mailing list