From owner-freebsd-ports@FreeBSD.ORG Sun Jan 8 10:52:25 2006 Return-Path: X-Original-To: freebsd-ports@freebsd.org Delivered-To: freebsd-ports@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E076416A41F for ; Sun, 8 Jan 2006 10:52:25 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: from pne-smtpout2-sn1.fre.skanova.net (pne-smtpout2-sn1.fre.skanova.net [81.228.11.159]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5ED9B43D49 for ; Sun, 8 Jan 2006 10:52:24 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: from falcon.midgard.homeip.net (83.253.29.241) by pne-smtpout2-sn1.fre.skanova.net (7.2.069.1) id 43ABF6D50039B13F for freebsd-ports@freebsd.org; Sun, 8 Jan 2006 11:52:23 +0100 Received: (qmail 21244 invoked by uid 1001); 8 Jan 2006 11:52:23 +0100 Date: Sun, 8 Jan 2006 11:52:23 +0100 From: Erik Trulsson To: Edwin Groothuis Message-ID: <20060108105223.GA19330@falcon.midgard.homeip.net> Mail-Followup-To: Edwin Groothuis , freebsd-ports@freebsd.org References: <20060108103402.GB3806@k7.mavetju> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060108103402.GB3806@k7.mavetju> User-Agent: Mutt/1.5.11 Cc: freebsd-ports@freebsd.org Subject: Re: time_t printf() X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jan 2006 10:52:26 -0000 On Sun, Jan 08, 2006 at 09:34:02PM +1100, Edwin Groothuis wrote: > Trying to printf() a time_t value, I tried the following permutations: > > time_t days = 0, hours = 0, minutes = 0, seconds = 0; > sprintf(buffer, "%2d %2u %2ld %2lu", days, hours, minutes, seconds); > > 4.11 said: > misc.c:117: warning: int format, time_t arg (arg 3) > misc.c:117: warning: unsigned int format, long unsigned int arg (arg 4) > > 6.0 said: > misc.c:117: warning: long int format, time_t arg (arg 5) > misc.c:117: warning: long unsigned int format, time_t arg (arg 6) > > So between 4.11 and 6.0 there is no uniform way to printf() time_t > values... Yes, there is. Cast the argument to [unsigned] long (or possibly [u]intmax_t when using a C99 compiler) and print it as such. Should be portable to all Unix-like systems. If you try to make the code as portable as possible you should keep in mind that the only requirement the C standard puts on time_t is that it must be an arithmetic type, so some implementations may define it as a double or a float. -- Erik Trulsson ertr1013@student.uu.se