From patchwork Sat Nov 9 16:38:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Watkins X-Patchwork-Id: 3163961 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BA5339F43F for ; Sat, 9 Nov 2013 16:38:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C25EA2038C for ; Sat, 9 Nov 2013 16:38:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B71E20387 for ; Sat, 9 Nov 2013 16:38:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753773Ab3KIQiU (ORCPT ); Sat, 9 Nov 2013 11:38:20 -0500 Received: from mail-qa0-f53.google.com ([209.85.216.53]:45620 "EHLO mail-qa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753745Ab3KIQiU (ORCPT ); Sat, 9 Nov 2013 11:38:20 -0500 Received: by mail-qa0-f53.google.com with SMTP id k4so584689qaq.19 for ; Sat, 09 Nov 2013 08:38:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=UjNu4DLJj0HchTLBRZVV5OphzO28YSZ43fYxBpGZQ6o=; b=eEEe4Z/0y5xaYaK8JEbtZDjpgR472ZLmrnkwzihjYM91TVpaDx8l6hu2K1O1zATWX2 GrzJVQKAfOVLUDI+/9h+kozki1OtZNoGeNU8qNQlGwNKmGXkcSPxdIo995JVTaMYyHd5 lWP/vdx7uIz2zrkov30PSmLt2PniL9ZGmgDSChBPZeUHVJ0NKL6hoO9IHncpyKCj+ISr nm5q29kaufpErpI+R7TTo4W586v/HI0u79RjBMsYQCttSOkkx/HP52FppYEcj60mcihx ul/0tbOIVKQSaKTU0eMP6D+lKkQZVwTRfPaznvjX21DAxLujZL1H5gc3xYlc62WeZw6A M1Dg== X-Gm-Message-State: ALoCoQmsVx6t9Nb7RT9TP7FnRjSxhlwsxSQQHcrOQJSC2Ok/UfTPIp+YmGCh1OsJGRbTOW7gVcXE MIME-Version: 1.0 X-Received: by 10.49.12.136 with SMTP id y8mr31934640qeb.41.1384015099423; Sat, 09 Nov 2013 08:38:19 -0800 (PST) Received: by 10.96.66.195 with HTTP; Sat, 9 Nov 2013 08:38:19 -0800 (PST) In-Reply-To: <6035A0D088A63A46850C3988ED045A4B665E2149@BITCOM1.int.sbss.com.au> References: <6035A0D088A63A46850C3988ED045A4B665E2149@BITCOM1.int.sbss.com.au> Date: Sat, 9 Nov 2013 08:38:19 -0800 Message-ID: Subject: Re: portability issue with gmtime method in utime_t From: Noah Watkins To: James Harper Cc: "ceph-devel@vger.kernel.org" Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi James, I think my vote would be to rename `ostream& gmtime(ostream& out) const` to something like `write_gmtime`, but the global namespace approach seems OK too. Maybe someone else has a strong opinion. --- sort of related: while we are on the subject of utime_t, `timegm` isn't portable. This is the hack I'm using in `wip-port`, but I don't think it should stay this way: On Sat, Nov 9, 2013 at 12:24 AM, James Harper wrote: > utime.h defines a utime_t class with a gmtime() method, and also calls the library function gmtime_r(). > > mingw implements gmtime_r() as a macro in pthread.h that in turn calls gmtime(), and gcc bails because it gets confused about which is being called: > > utime.h: In member function 'utime_t utime_t::round_to_minute()': > utime.h:113:5: error: no matching function for call to 'utime_t::gmtime(time_t*)' > utime.h:113:5: note: candidate is: > utime.h:146:12: note: std::ostream& utime_t::gmtime(std::ostream&) const > utime.h:146:12: note: no known conversion for argument 1 from 'time_t* {aka long long int*}' to 'std::ostream& {aka std::basic_ostream&}' > > Same for asctime and localtime. I can work around it by creating a static method that in turn calls ::gmtime() etc, but I'm not sure that's the best way to do it. > > There's a bunch of other build errors in there too so it may be a lost cause... > > James > -- > To unsubscribe from this list: send the line "unsubscribe ceph-devel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/include/utime.h b/src/include/utime.h index 5bebc70..1a74a85 100644 --- a/src/include/utime.h +++ b/src/include/utime.h @@ -238,6 +238,22 @@ class utime_t { bdt.tm_hour, bdt.tm_min, bdt.tm_sec, usec()); } + static time_t my_timegm (struct tm *tm) { + time_t ret; + char *tz; + + tz = getenv("TZ"); + setenv("TZ", "", 1); + tzset(); + ret = mktime(tm); + if (tz) + setenv("TZ", tz, 1); + else + unsetenv("TZ"); + tzset(); + return ret; + } + static int parse_date(const string& date, uint64_t *epoch, uint64_t *nsec, string *out_date=NULL, string *out_time=NULL) { struct tm tm; @@ -274,7 +290,7 @@ class utime_t { } else { return -EINVAL; } - time_t t = timegm(&tm); + time_t t = my_timegm(&tm); if (epoch) *epoch = (uint64_t)t;