newlib-cygwin/newlib/libc/time/asctime.c

64 lines
1.2 KiB
C
Raw Normal View History

2000-02-18 03:39:52 +08:00
/*
* asctime.c
* Original Author: G. Haley
*
* Converts the broken down time in the structure pointed to by tim_p into a
* string of the form
*
* Wed Jun 15 11:38:07 1988\n\0
*
* Returns a pointer to the string.
*/
/*
FUNCTION
<<asctime>>---format time as string
INDEX
asctime
INDEX
_asctime_r
SYNOPSIS
2000-02-18 03:39:52 +08:00
#include <time.h>
char *asctime(const struct tm *<[clock]>);
char *_asctime_r(const struct tm *<[clock]>, char *<[buf]>);
2000-02-18 03:39:52 +08:00
DESCRIPTION
Format the time value at <[clock]> into a string of the form
. Wed Jun 15 11:38:07 1988\n\0
The string is generated in a static buffer; each call to <<asctime>>
overwrites the string generated by previous calls.
RETURNS
A pointer to the string containing a formatted timestamp.
PORTABILITY
ANSI C requires <<asctime>>.
<<asctime>> 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>
#include <string.h>
2000-02-18 03:39:52 +08:00
#include <time.h>
#include <_ansi.h>
#include <reent.h>
#ifdef _REENT_THREAD_LOCAL
_Thread_local char _tls_asctime_buf[_REENT_ASCTIME_SIZE];
#endif
2000-02-18 03:39:52 +08:00
#ifndef _REENT_ONLY
char *
asctime (const struct tm *tim_p)
2000-02-18 03:39:52 +08:00
{
2013-04-29 Sebastian Huber <sebastian.huber@embedded-brains.de> * libc/stdio/local.h (CHECK_INIT): Evaluate argument only once. (CHECK_STD_INIT): Likewise. * libc/stdio/fgetc.c (fgetc): Use local variable for _REENT. * libc/stdio/fgetwc.c (fwgetc): Likewise. * libc/stdio/fgetws.c (fgetws): Likewise. * libc/stdio/fputc.c (fputc): Likewise. * libc/stdio/fputwc.c (fputwc): Likewise. * libc/stdio/fputws.c (fputws): Likewise. * libc/stdio/getc.c (getc): Likewise. * libc/stdio/getchar.c (_getchar_r): Likewise. * libc/stdio/putc.c (putc): Likewise. * libc/stdio/putchar.c (putchar): Likewise. * libc/stdio/scanf.c (scanf): Likewise. * libc/stdio/setvbuf.c (setvbuf): Likewise. * libc/stdio/ungetwc.c (ungetwc): Likewise. * libc/stdio/vfscanf.c (VFSCANF): Likewise. * libc/stdio/vfwscanf.c (VFWSCANF): Likewise. * libc/stdio/viprintf.c (viprintf): Likewise. * libc/stdio/viscanf.c (viscanf): Likewise. * libc/stdio/vprintf.c (vprintf): Likewise. * libc/stdio/vscanf.c (vscanf): Likewise. * libc/stdio/vwprintf.c (vwprintf): Likewise. * libc/stdio/vwscanf.c (vwscanf): Likewise. * libc/stdio/wscanf.c (wscanf): Likewise. * libc/stdlib/ecvtbuf.c (fcvtbuf): Likewise. (fcvtbuf): Likewise. (ecvtbuf): Likewise. (ecvtbuf): Likewise. * libc/stdlib/mblen.c (mblen): Likewise. * libc/stdlib/mbrlen.c (mbrlen): Likewise. * libc/stdlib/mbrtowc.c (mbrtowc): Likewise. * libc/stdlib/mbtowc.c (mbtowc): Likewise. * libc/stdlib/rand.c (srand): Likewise. (rand): Likewise. * libc/stdlib/wcrtomb.c (wcrtomb): Likewise. * libc/stdlib/wctob.c (wctob): Likewise. * libc/stdlib/wctomb.c (wctomb): Likewise. * libc/string/strtok.c (strtok): Likewise. * libc/time/asctime.c (asctime): Likewise. * libc/time/gmtime.c (gmtime): Likewise. * libc/time/lcltime.c (lcltime): Likewise.
2013-04-30 05:06:23 +08:00
struct _reent *reent = _REENT;
_REENT_CHECK_ASCTIME_BUF(reent);
return asctime_r (tim_p, _REENT_ASCTIME_BUF(reent));
2000-02-18 03:39:52 +08:00
}
#endif