delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/07/22/16:49:29

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:to:subject:date:message-id:content-type
:content-transfer-encoding:mime-version; q=dns; s=default; b=A2i
veqPArUCXfvkAvJyXpXaj8Nwv4tjvmoVbQQr8yEA9luRzFRwaeO8hM+DeziGNZjM
X/tbs7foVy22RaPwr6HzCi+wEi0M46BEFt0IVqNOMglOXOZJh5dEDVFREQBcYFis
uiIYyypYmOh7OBsiYAjMdmgJ1UOc1rQluE2X91xw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:to:subject:date:message-id:content-type
:content-transfer-encoding:mime-version; s=default; bh=byfSYLLmK
iV8RcRvVi7ApONXmh0=; b=xhE/mFpAqAuQ+Rhmo6kjM7DeT6rR1HCUzt872poE9
hspgP+c0PKb255V4zcqAET/qwZEqkv+yzJd33kuptmVsZ+mDznY0/CTHESS+tSDG
uuz0nIX+RNtTHyQjLGOPh0B0qH1YtJYMONA5ZAf3C1c0nEZF7ql6LGkY+SDbezRk
og=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=contractor, Contractor, Hx-languages-length:1159
X-HELO: nihcesxway2.hub.nih.gov
X-SBRS-Extended: Low
X-IronPortListener: ces-out
From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr AT ncbi DOT nlm DOT nih DOT gov>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: Cygwin strptime() is missing "%s" which strftime() has
Date: Sat, 22 Jul 2017 20:48:26 +0000
Message-ID: <BN3PR09MB0340BFF87B6B3E7A100C1A8EA5A50@BN3PR09MB0340.namprd09.prod.outlook.com>
authentication-results: spf=none (sender IP is ) smtp.mailfrom=lavr AT ncbi DOT nlm DOT nih DOT gov;
x-ms-publictraffictype: Email
x-microsoft-exchange-diagnostics: 1;BN3PR09MB0338;7:uhKVSutB+1b3cGfsWjbaEh4F5lZihxJPkL0W8+obflIYlK/Qkp1YPzXdQl10KWBqAizfkrIl3lYvkJvPjy5FJLhqSsbGpDAbfmC20ydlIwGexOHbNErZqU8z2H3IJT7L3qC9L03igATnCMJgwkgUyE362Rs7uwUrlaIbim4xn6ss3N1t7E18LQfIwIo5gxQ82RTDOTUvPNRXaq71KJCi/Tx6cBKDYjZ955mKRl+9gj3mRHpKmI/h3t+7XRGXiWo7fyRug4MnLhIH3v6cOC6mr9Nv/7YYXjxa7odx6XZ11/DCZV/AJllI4eMsj8p62zW93Jat2jaIpvp5vcnw6LRmnV1RPv/+K8aLsfBG1IUuQeBB8wlIQz4IVrJKljURga/NYw/4/Ye8g7ADM6SLCzZlTtZm1P8sgO88o7ome3Yo0fxEUcn5nEY9Rj2iZkTrJLoWa+14hhcOjTFvm89Q8NF4YIbmfGWs+Gp/lVYTxCi+wDdvE/w3Om4b/ybg7OLspuPKAbhabdGaQqaykFBjsj//ThOi/v/sj/KfOwpsy/IdNZCcszKlhH3F9HGcIyez2RlhZ3RCrhv8EVjW/BXnm9rf8YHWSuBS/a6od+vjHclKwVvuiMWsroLU+P143jQ1EwA2bzI/HKwt2ZEL7KLF2C4hqpf7XRgN7Mq4vyWMCWndZKmexSuF9lkb9ZPINAt7avtmPFJszeXzIP4CLauv2IK/7FF4l9hExod7jhDD/1xnDYg+i6A+Cd7ISdSw++9a/Hk3+6CowokbWHRoIPH1/aIIgfLuzuW4b7nnry4Tgi12mMg=
x-ms-office365-filtering-correlation-id: 0faa0d37-4b2d-4913-adc6-08d4d143008b
x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BN3PR09MB0338;
x-ms-traffictypediagnostic: BN3PR09MB0338:
x-exchange-antispam-report-test: UriScan:;
x-microsoft-antispam-prvs: <BN3PR09MB0338C87FDABD744E2086AD92A5A50 AT BN3PR09MB0338 DOT namprd09 DOT prod DOT outlook DOT com>
x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BN3PR09MB0338;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BN3PR09MB0338;
x-forefront-prvs: 0376ECF4DD
x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39840400002)(39400400002)(39850400002)(39450400003)(39410400002)(199003)(189002)(54356999)(8936002)(5660300001)(305945005)(42882006)(6916009)(50986999)(2351001)(66066001)(105586002)(81166006)(2900100001)(189998001)(9686003)(86362001)(2501003)(6436002)(1730700003)(110136004)(106356001)(7696004)(101416001)(38730400002)(97736004)(8676002)(7736002)(14454004)(81156014)(3846002)(102836003)(6116002)(55016002)(25786009)(68736007)(74316002)(33656002)(5640700003)(53936002)(99286003)(3660700001)(3280700002)(2906002)(478600001)(6506006)(77096006);DIR:OUT;SFP:1102;SCL:1;SRVR:BN3PR09MB0338;H:BN3PR09MB0340.namprd09.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en;
spamdiagnosticoutput: 1:99
spamdiagnosticmetadata: NSPM
MIME-Version: 1.0
X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jul 2017 20:48:26.6844 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 14b77578-9773-42d5-8507-251ca2dc2b06
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR09MB0338
X-OriginatorOrg: ncbi.nlm.nih.gov
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id v6MKnSqH024482

Hello,

It looks like Cygwin implementation of strptime(3) cannot understand the "%s" format (seconds since Jan 1, 1970 UTC), which strftime() can.

When I test the same code of Linux, it appears to work correctly.

Cygwin:
$ gcc -Wall -o timetest timetest.c
$ ./timetest
1500755837 -> 1500755837
Cannot convert string

Linux:

$ gcc -Wall -o timetest timetest.c
$ ./timetest
1500755887 -> 1500755887
1500755887 -> 1500755887, unconverted: ""

Anton Lavrentiev
Contractor NIH/NLM/NCBI

$ cat timetest.c
#define _XOPEN_SOURCE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main()
{
    time_t now = time(0);
    struct tm tm = *localtime(&now);
    char str[80], *s;
    size_t n = strftime(str, sizeof(str), "%s", &tm);
    if (!n) {
        printf("Cannot convert time");
        return 1;
    }
    assert(n == strlen(str));
    printf("%lu -> %s\n", (unsigned long) now, str);
    memset(&tm, 0, sizeof(tm));
    if (!(s = strptime(str, "%s", &tm))) {
        printf("Cannot convert string");
        return 1;
    }
    now = mktime(&tm);
    printf("%s -> %lu, unconverted: \"%s\"\n", str, (unsigned long) now, s);
    return 0;    
}


--
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019