From owner-svn-src-head@freebsd.org Tue May 8 20:43:43 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 683B8FC9B13; Tue, 8 May 2018 20:43:43 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 162D26AE78; Tue, 8 May 2018 20:43:43 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id A2C09239D8; Tue, 8 May 2018 20:43:42 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-lf0-f44.google.com with SMTP id z142-v6so4555685lff.5; Tue, 08 May 2018 13:43:42 -0700 (PDT) X-Gm-Message-State: ALQs6tDImYcqXez3RbIsrFBLICsLuKVi9cra//YOnsVZ1NUewZsIxU3I xgGV0WsfH2LuKHH1gW/n1FlW3VwWZO1M5ad5Ij0= X-Google-Smtp-Source: AB8JxZoS/N+4EpXQNPWrvUB1iCZqjHKD4RO+n4MTqkGHvtF3pWL50+kyp4Tf/MhBp8olUpSVe2MDfpF+rrLA1P9H5YU= X-Received: by 2002:a2e:7113:: with SMTP id m19-v6mr30137444ljc.44.1525812221187; Tue, 08 May 2018 13:43:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.46.49.18 with HTTP; Tue, 8 May 2018 13:43:20 -0700 (PDT) In-Reply-To: References: <201805080353.w483rlde033542@repo.freebsd.org> <20180508105815.GB7299@FreeBSD.org> <20180508144912.GA3581@FreeBSD.org> From: Kyle Evans Date: Tue, 8 May 2018 15:43:20 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r333351 - head/usr.bin/grep To: Ronald Klop Cc: Alexey Dokuchaev , svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 May 2018 20:43:43 -0000 On Tue, May 8, 2018 at 3:36 PM, Ronald Klop wrote: > On Tue, 08 May 2018 16:49:12 +0200, Alexey Dokuchaev > wrote: > >> On Tue, May 08, 2018 at 09:36:21AM -0500, Kyle Evans wrote: >>> >>> On Tue, May 8, 2018 at 5:58 AM, Alexey Dokuchaev >>> wrote: >>> >> >>> >> - if ((f = fopen(fn, "r")) == NULL) >>> >> + if (strcmp(fn, "-") == 0) >>> >> + f = stdin; >>> > >>> > This makes sense: when `fn' is "-", `f' is stdin. >>> > >>> >> - fclose(f); >>> >> + if (strcmp(fn, "-") != 0) >>> >> + fclose(f); >>> > >>> > But not this one: why are you checking `fn' again? Shouldn't you >>> > fclose(f) if it's not stdin? >>> > >>> > if (f != stdin) >>> > fclose(f); >>> > >>> >>> You say potato, I say potato. =) In this case, it's low overhead in a >>> not particularly performance critical bit and drawing a connection >>> between this and the opening of 'f' above in an extremely obvious way. >> >> >> Well, I'm not worried about the overhead or performance issues, they are >> negligible. I just find second strcmp(fn, "-") to be semantically wrong >> (and that's why you need implicit "there's only one way to get stdin here" >> assert). You assign `f' to stdin based on `fn' being "-", but you >> fclose(f) when it's not stdin; the value of `fn' is irrelevant this time. >> As a nice bonus, you only spell strcmp(fn, "-") once and do not need to >> implicitly assert that there's only one way to get stdin here. >> >>> This also might get ripped out soon -- we'll see how things go. >> >> >> I see, understood. >> >> ./danfe > > > What is the result of "-f /dev/stdin"? Of does that fopen return a different > filedesc? > Indeed- /dev/stdin will force it to open another filedesc and read from stdin all the same. Thanks, Kyle Evans