threads / discuss / 952

time casts

Subject: time casts

## tl;dr

One message between Jun 15, 2005 and Jun 15, 2005.

replies: 0people: 1as markdown or json

Jason Wright· Jun 15, 2005, 15:30 UTC · lore

In porting cogito/git 0.11.3 to OpenBSD, I ran into casts of time_t warnings for the printfs below. I think the warnings are harmless, but the patch below fixes 'em.

--Jason L. Wright

--- date.c.orig Wed Jun 15 11:21:00 2005 +++ date.c Wed Jun 15 11:21:30 2005

@@ -438,7 +438,8 @@ void parse_date(char *date, char *result
 		sign = '-';
 	}
 
-	snprintf(result, maxlen, "%lu %c%02d%02d", then, sign, offset/60, offset % 60);
+	snprintf(result, maxlen, "%lu %c%02d%02d", (unsigned long)then,
+	    sign, offset/60, offset % 60);
 }
 
 void datestamp(char *buf, int bufsize)
@@ -451,5 +452,6 @@ void datestamp(char *buf, int bufsize)
 	offset = my_mktime(localtime(&now)) - now;
 	offset /= 60;
 
-	snprintf(buf, bufsize, "%lu %+05d", now, offset/60*100 + offset%60);
+	snprintf(buf, bufsize, "%lu %+05d", (unsigned long)now,
+	    offset/60*100 + offset%60);
 }
--- tar-tree.c.orig	Wed Jun 15 11:24:07 2005
+++ tar-tree.c	Wed Jun 15 11:24:55 2005
@@ -318,7 +318,7 @@ static void write_header(const unsigned 
 	if (S_ISDIR(mode) || S_ISLNK(mode))
 		size = 0;
 	sprintf(&header[124], "%011lo", size);
-	sprintf(&header[136], "%011lo", archive_time);
+	sprintf(&header[136], "%011lo", (unsigned)archive_time);
 
 	header[156] = typeflag;
 

← back to recent threads