From owner-svn-src-all@freebsd.org Tue May 8 14:36:43 2018 Return-Path: Delivered-To: svn-src-all@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 E1A76FB7AE0; Tue, 8 May 2018 14:36: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 907817AFCA; Tue, 8 May 2018 14:36:43 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) (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 2FB14214F3; Tue, 8 May 2018 14:36:43 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-lf0-f50.google.com with SMTP id r25-v6so2435559lfd.1; Tue, 08 May 2018 07:36:43 -0700 (PDT) X-Gm-Message-State: ALQs6tDtDl4Iw+CaBpgZfu1a11G+VGUC+qg61kOJAm7SnnZs66cOUU2W L1072m4e8jbZhiN5j51YrbDvZZxkIefBWjKkHU0= X-Google-Smtp-Source: AB8JxZqyFw1Mf190SkI76UgaK42SrdsyjAbcghKSW2w+AIjSi+Vr2EKyeRfWYExpW4GJkQGERYI3Aoi3oOdOJUvASfo= X-Received: by 2002:a2e:7113:: with SMTP id m19-v6mr29300273ljc.44.1525790201790; Tue, 08 May 2018 07:36:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.46.49.18 with HTTP; Tue, 8 May 2018 07:36:21 -0700 (PDT) In-Reply-To: <20180508105815.GB7299@FreeBSD.org> References: <201805080353.w483rlde033542@repo.freebsd.org> <20180508105815.GB7299@FreeBSD.org> From: Kyle Evans Date: Tue, 8 May 2018 09:36:21 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r333351 - head/usr.bin/grep To: Alexey Dokuchaev Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 May 2018 14:36:44 -0000 On Tue, May 8, 2018 at 5:58 AM, Alexey Dokuchaev wrote: > On Tue, May 08, 2018 at 03:53:47AM +0000, Kyle Evans wrote: >> New Revision: 333351 >> URL: https://svnweb.freebsd.org/changeset/base/333351 >> >> Log: >> bsdgrep: Allow "-" to be passed to -f to mean "standard input" >> >> A version of this patch was originally sent to me by se@, matching behavior >> from newer versions of GNU grep. >> >> - 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. Granted, there's only one way to get stdin here. This also might get ripped out soon- we'll see how things go.