use gmtime_r() instead of gmtime()
This avoids pulling in gmtime's static buffer:
function                                             old     new   delta
svlogd_main                                         1401    1412     +11
send_headers                                         668     678     +10
gmtime                                                21       -     -21
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/0 up/down: 21/-21)              Total: 0 bytes
   text	   data	    bss	    dec	    hex	filename
 920221	    555	   5804	 926580	  e2374	busybox_old
 920221	    555	   5740	 926516	  e2334	busybox_unstripped
                   ^^^^
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
			
			
This commit is contained in:
		@@ -347,11 +347,13 @@ static unsigned pmatch(const char *p, const char *s, unsigned len)
 | 
			
		||||
/* NUL terminated */
 | 
			
		||||
static void fmt_time_human_30nul(char *s, char dt_delim)
 | 
			
		||||
{
 | 
			
		||||
	struct tm tm;
 | 
			
		||||
	struct tm *ptm;
 | 
			
		||||
	struct timeval tv;
 | 
			
		||||
 | 
			
		||||
	gettimeofday(&tv, NULL);
 | 
			
		||||
	ptm = gmtime(&tv.tv_sec);
 | 
			
		||||
	ptm = gmtime_r(&tv.tv_sec, &tm);
 | 
			
		||||
	/* ^^^ using gmtime_r() instead of gmtime() to not use static data */
 | 
			
		||||
	sprintf(s, "%04u-%02u-%02u%c%02u:%02u:%02u.%06u000",
 | 
			
		||||
		(unsigned)(1900 + ptm->tm_year),
 | 
			
		||||
		(unsigned)(ptm->tm_mon + 1),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user