2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
* localtime.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<localtime>>---convert time to local representation
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
localtime
|
2008-11-01 05:08:03 +08:00
|
|
|
INDEX
|
|
|
|
localtime_r
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2017-11-30 16:22:31 +08:00
|
|
|
SYNOPSIS
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <time.h>
|
|
|
|
struct tm *localtime(time_t *<[clock]>);
|
|
|
|
struct tm *localtime_r(time_t *<[clock]>, struct tm *<[res]>);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
<<localtime>> converts the time at <[clock]> into local time, then
|
|
|
|
converts its representation from the arithmetic representation to the
|
|
|
|
traditional representation defined by <<struct tm>>.
|
|
|
|
|
|
|
|
<<localtime>> constructs the traditional time representation in static
|
|
|
|
storage; each call to <<gmtime>> or <<localtime>> will overwrite the
|
|
|
|
information generated by previous calls to either function.
|
|
|
|
|
|
|
|
<<mktime>> is the inverse of <<localtime>>.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
A pointer to the traditional time representation (<<struct tm>>).
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
ANSI C requires <<localtime>>.
|
|
|
|
|
|
|
|
<<localtime>> requires no supporting OS subroutines.
|
|
|
|
*/
|
|
|
|
|
Add missing headers to fix implicit function defns
A few files were missing headers for memset/malloc, likely missed
because the files don't directly call the functions, rather they
come in via macros in libc/include/sys/reent.h:
#define _REENT_CHECK(var, what, type, size, init) do { \
struct _reent *_r = (var); \
if (_r->what == NULL) { \
_r->what = (type)malloc(size); \
#define _REENT_CHECK_ASCTIME_BUF(var) \
_REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \
memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE))
Without these fixes, implicit function signatures are provided,
which gcc warns could cause aliasing issues down the line:
../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'memset' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: return value type mismatch
_PTR _EXFUN(memset,(_PTR, int, size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: 'memset' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/time/lcltime.c:58:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/string/strsignal.c:70:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
Including the proper headers elminates the implicit function
signatures and these warnings.
2017-01-16 08:12:02 +08:00
|
|
|
#include <stdlib.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <reent.h>
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
|
|
|
|
struct tm *
|
2017-12-04 11:43:30 +08:00
|
|
|
localtime (const time_t * tim_p)
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
2013-04-30 05:06:23 +08:00
|
|
|
struct _reent *reent = _REENT;
|
|
|
|
|
|
|
|
_REENT_CHECK_TM(reent);
|
|
|
|
return localtime_r (tim_p, (struct tm *)_REENT_TM(reent));
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|