X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Leszek Matok Newsgroups: comp.os.msdos.djgpp Subject: gettimeofday( ) reports time 24 hours in the future at 0:00 Date: Thu, 01 Jun 2006 02:25:06 +0200 Organization: tp.internet - http://www.tpi.pl/ Lines: 55 Message-ID: <1149121505.3843.30.camel@pensja.lam.pl> NNTP-Posting-Host: pc7.siedlce.sdi.tpnet.pl Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-WCqcEmrRQeycEAp158U9" X-Trace: nemesis.news.tpi.pl 1149121636 28622 217.96.220.7 (1 Jun 2006 00:27:16 GMT) X-Complaints-To: usenet AT tpi DOT pl NNTP-Posting-Date: Thu, 1 Jun 2006 00:27:16 +0000 (UTC) X-Mailer: Evolution 2.6.1 (2.6.1-1.fc5.2) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com --=-WCqcEmrRQeycEAp158U9 Content-Type: text/plain Content-Transfer-Encoding: 7bit I'm attaching a tiny C program showing gettimeofday( ) being broken in DJGPP (version "djdev203 Development Kit and Runtime (June 2002 Refresh)"). I run it under FreeDOS in dosemu, but the problem was first spotted by my friend under Windows XP, so it's not something OS-dependant. The problem is that at 0:00, when the date changes, gettimeofday( ) reports next day, but still 23:59. I guess it's taking time before date from system clock and the date can change between the calls with clock change (from 23:59 to 0:00) isn't noticed, than it builds struct timeval from wrong data. If I'm right, the fix would be to first grab date, then time, then date again (date changes very rarely compared to time) and if the date differs, time again :) My program sets the time to 23:59:59 yesterday, then grabs the time again and again and again, until one second later, when the day changes and the error manifests itself: C:\TEST>test t1: 1149206399, Thu Jun 1 23:59:59 2006 t2: 1149120000, Thu Jun 1 00:00:00 2006 This happens every single time I run the attached program. Of course, in real life, for my real program, this happens once per day or two, but I guess my program isn't the only one depending on gettimeofday( ) returning proper time. Is it fixed in cvs? Or can it somehow be my error? :) Lam --=-WCqcEmrRQeycEAp158U9 Content-Description: Content-Disposition: inline; filename=test.c Content-Type: text/x-csrc; charset=UTF-8 Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN5cy90aW1lLmg+DQojaW5jbHVkZSA8dGltZS5oPg0KI2luY2x1ZGUgPHN0ZGlv Lmg+DQoNCmludCBtYWluKCB2b2lkICkNCnsNCiAgICBzdHJ1Y3QgdGltZXZhbCB0djsNCiAgICB0 aW1lX3QgdDEsIHQyOw0KDQogICAgdHYudHZfc2VjID0gMTE0OTExOTk5OTsNCiAgICB0di50dl91 c2VjID0gMDsNCiAgICBzZXR0aW1lb2ZkYXkoICZ0diwgMCApOw0KDQogICAgdDEgPSAwOw0KICAg IHdoaWxlICggMSApDQogICAgew0KCWdldHRpbWVvZmRheSggJnR2LCAwICk7DQoJdDIgPSB0di50 dl9zZWM7DQoJaWYgKCB0MiA8IHQxICkNCgkgICAgYnJlYWs7DQoJdDEgPSB0MjsNCiAgICB9DQoN CiAgICBwcmludGYoICJ0MTogJWQsICVzIiwgdDEsIGFzY3RpbWUoIGxvY2FsdGltZSggJnQxICkg KSApOw0KICAgIHByaW50ZiggInQyOiAlZCwgJXMiLCB0MiwgYXNjdGltZSggbG9jYWx0aW1lKCAm dDIgKSApICk7DQogICAgcmV0dXJuIDA7DQp9DQo= --=-WCqcEmrRQeycEAp158U9--