DragonFly BSD
DragonFly commits List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: cvs commit: src/bin/cat


From: Jason Smethers <jason@xxxxxxxxxxxx>
Date: Sun, 07 Nov 2004 17:29:27 -0600

Matthew Dillon wrote:
:
:Liam J. Foy wrote:
:> liamfoy 2004/11/04 13:31:37 PST
:> :> DragonFly src repository
:> :> Modified files:
:> bin/cat cat.c :> Log:
:> - Remove unnecessary selection statement to see if buf == NULL.
:> - Don't use fileno to get stdout, just use STDOUT_FILENO
:> - Fix malloc err message
:> :> OK'ed by: Joerg and Jeroen
:> :> Revision Changes Path
:> 1.12 +8 -10 src/bin/cat/cat.c
:> :> :> http://www.dragonflybsd.org/cvsweb/src/bin/cat/cat.c.diff?r1=1.11&r2=1.12&f=u
:
:
:Removing the check for (buf == NULL):
:1. Introduces a memory leak -- equal to (bsize * (n - 1)) where n is the :number of times raw_cat is called.
:2. Adds unecessary work -- stdout never changes
:
:
:Also, the constant 1024 in the buffer size check should be replaced by :the posix constant BUFSIZ.
:
:- Jason
Whoops, quite right. I missed the fact that 'buf' was a static when
I review Liam's commit.


    The original code isn't so good either.  While I don't expect we
    will be cat'ing multiple block devices I think it would probably still
    be a good idea to fstat/resize the buffer on a per-descriptor basis.
    The expensive is minimal.

I'll just go ahead and fix it. Don't worry about it, Liam.

-Matt
Matthew Dillon <dillon@xxxxxxxxxxxxx>



But there is only one descriptor to stat -- stdout. Cat always writes to stdout, and as per POSIX stdout is never closed and reopened. Shouldn't fstat therefore always return the same value? Or, do you mean you want to optimize the code for the input buffer instead of the output buffer?


- Jason




[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]