Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 May 2018 09:36:21 -0500
From:      Kyle Evans <kevans@freebsd.org>
To:        Alexey Dokuchaev <danfe@freebsd.org>
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r333351 - head/usr.bin/grep
Message-ID:  <CACNAnaEiV7kC%2BUNy6GwiEtLzOqwA%2BkPuunDNBtb1dQUQeb3uzQ@mail.gmail.com>
In-Reply-To: <20180508105815.GB7299@FreeBSD.org>
References:  <201805080353.w483rlde033542@repo.freebsd.org> <20180508105815.GB7299@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, May 8, 2018 at 5:58 AM, Alexey Dokuchaev <danfe@freebsd.org> 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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACNAnaEiV7kC%2BUNy6GwiEtLzOqwA%2BkPuunDNBtb1dQUQeb3uzQ>