X-Recipient: archive-cygwin@delorie.com X-SWARE-Spam-Status: No, hits=2.2 required=5.0 tests=AWL,BAYES_00,CHARSET_FARAWAY_HEADER X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Wed, 26 May 2010 12:23:54 +0300 Message-ID: Subject: 1.7.5-1: problem with settimeofday() & gettimeofday() From: =?KOI8-R?B?/sXLIP7Fy8nT1A==?= <4ekuct@tut.by> To: cygwin@cygwin.com Content-Type: text/plain; charset=ISO-8859-1 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Delivered-To: mailing list cygwin@cygwin.com Hello. It seems that I found a problem with settimeofday() and gettimeofday() calls in a single context. The problem is that if we set a new time with settimeofday() call it completes succefully and system time is updated. But then if we try to get current time with gettimeofday() call it returns old time! The following example could be used: #include #include int main(int argc, char* argv[]) { struct timeval tv; struct tm time_to_set; // Get current date & time since Epoch. if (gettimeofday(&tv, NULL) != 0) { printf("Cannot get current date & time since Epoch."); } // Calculate local time. if (localtime_r(&tv.tv_sec, &time_to_set) != &time_to_set) { printf("Cannot convert file time to local file time."); } printf("Old time: %d.%d.%d - %d:%d:%d\r\n", time_to_set.tm_year + 1900, time_to_set.tm_mon + 1, time_to_set.tm_mday, time_to_set.tm_hour, time_to_set.tm_min, time_to_set.tm_sec); time_to_set.tm_hour = 20; time_to_set.tm_min = 33; time_to_set.tm_sec = 11; time_to_set.tm_year = 2010 - 1900; time_to_set.tm_mon = 1; time_to_set.tm_mday = 4 + 1; // Make new system time. if ((tv.tv_sec = mktime(&time_to_set)) == (time_t)-1) { printf("Cannot convert system time"); } tv.tv_usec = 0; // Set new system time. if (settimeofday(&tv, NULL) != 0) { printf("Cannot set system time"); } // Get current date & time since Epoch. if (gettimeofday(&tv, NULL) != 0) { printf("Cannot get current date & time since Epoch."); } // Calculate local time. if (localtime_r(&tv.tv_sec, &time_to_set) != &time_to_set) { printf("Cannot convert file time to local file time."); } printf("New time (2010.2.5 - 20:33:11): %d.%d.%d - %d:%d:%d\r\n", time_to_set.tm_year + 1900, time_to_set.tm_mon + 1, time_to_set.tm_mday, time_to_set.tm_hour, time_to_set.tm_min, time_to_set.tm_sec); return 0; } In my case the output is: Old time: 2010.5.26 - 12:47:23 New time (2010.2.5 - 20:33:11): 2010.5.26 - 12:47:23 -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple