From patchwork Thu Oct 7 17:38:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Nicol X-Patchwork-Id: 238561 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o97Hd2Y8013814 for ; Thu, 7 Oct 2010 17:39:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751362Ab0JGRi6 (ORCPT ); Thu, 7 Oct 2010 13:38:58 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:58944 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750972Ab0JGRi6 (ORCPT ); Thu, 7 Oct 2010 13:38:58 -0400 Received: by iwn9 with SMTP id 9so97899iwn.19 for ; Thu, 07 Oct 2010 10:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:cc:content-type; bh=idc3z5d+yhyeXtip185MeBRNK5oekrzk2pYtwKZsyIo=; b=Hj4kdGgDlta3f5oeUt1X124RQVNfAhzXnYbyyWnGR6kTznue7KZr9mQKg1G1LTgPDY DubT9SvwNuIeKDsHSIRCHdAnI0ootEgP+y7UMuqJDQHGjOEwJPTFjfRK7g9DZAOjiz6W RofShz2C7zZmvm7z/qwKiHBZNodY2/IRQargQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc :content-type; b=D0uDfKTfvw7qRAASZTfeftADfM7Wv17RT4G/C3WuK9Fm9JmVKpywbVlX4Wf3blj6js CHthLM6v6TNmrQVNSTzZYv4I2qUpRjAQ2y38rXUxtj93c8IVRGy0vzLOkZlAykVptAgb eEJBKIdLluKx/rr/B9Fm4CaGFrASMT54YYcoo= Received: by 10.231.152.146 with SMTP id g18mr1208688ibw.48.1286473137586; Thu, 07 Oct 2010 10:38:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.152.1 with HTTP; Thu, 7 Oct 2010 10:38:36 -0700 (PDT) In-Reply-To: <201010070810.42505.kreijack@libero.it> References: <201010070810.42505.kreijack@libero.it> From: David Nicol Date: Thu, 7 Oct 2010 12:38:36 -0500 Message-ID: Subject: Re: IOCTL #21 part two: btrfs progs patch, including iso 8601 timeout support Cc: linux-btrfs@vger.kernel.org To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 07 Oct 2010 17:39:02 +0000 (UTC) diff --git a/iso8601toms.c b/iso8601toms.c index a1ee9bd..f982d34 100644 --- a/iso8601toms.c +++ b/iso8601toms.c @@ -25,6 +25,8 @@ accept a non-integer as the last numeric component + always treats "m" as minutes + it silently accepts: out of order duration type letters @@ -35,10 +37,12 @@ non-integers in any position - it warns on: + it halts and catches fire on: P or p appearing somewhere besides the beginning of the string + Attempts to use Years or Months + unrecognized characters @@ -53,7 +57,6 @@ unsigned long iso8601toms(char *P){ char *ptr; char *endptr; short M_min = 0; - ms = 0UL; ptr = P; for(;;){ @@ -62,18 +65,13 @@ unsigned long iso8601toms(char *P){ { case 'P': /* anchor */ case 'p': if (ptr > P) - fprintf(stderr, "ignoring non-initial P " - "in ISO8601 duration string %s\n", P); - break; - case 'Y': /* years */ case 'y': - component *= 12; - BIGM: - /* average days in a gregorian month */ - component *= (365.2425 / 12.0); - /* ms in a day */ - component *= ( 24 * 3600 * 1000 ); - ms += component; - break; + fprintf(stderr, "non-initial P " + "in duration string %s\n", P); + exit (-1); + case 'Y': /* year */ case 'y': + fprintf(stderr, "Years are not supported " + "in duration string %s\n", P); + exit (-1); case 'T': /* Time (not date) anchor */ case 't': M_min = 1; break; @@ -84,9 +82,15 @@ unsigned long iso8601toms(char *P){ case 'H': /* hour */ case 'h': component *= 60; M_min = 1; - case 'M': /* month, or minute */ case 'm': - if (!M_min++) - goto BIGM; + case 'M': /* month, or minute */ + if (M_min == 0 ){ + fprintf(stderr, "Months are not supported " + "in duration string %s\n" + "use 'm' instead or prefix a 'T'\n" + , P); + exit (-1); + }; + case 'm': /* minute */ component *= 60; case 'S': /* second */ case 's': case '\0': /* default to second */ @@ -96,10 +100,11 @@ unsigned long iso8601toms(char *P){ default: fprintf(stderr, - "ignoring unexpected char [%c] " - "in iso8601 duration string %s\n", + "unexpected char [%c] in duration string %s\n" + "valid designators are [WwDdHhMmSs] with implied trailing S.\n", *endptr, P ); + exit (-1); }; if (!*endptr)