Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Counting lines of a file Date: Wed, 03 Oct 2018 11:46:56 -0700 Organization: None to speak of Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="8550f27190323af76201106f961d1e2f"; logging-data="3071"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oDZR3Y+1FVakPhh0hnOmJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ESiRj8Q7yu7P3O1ZQ+lza3jOLpo= sha1:q/OG9k6MhWV2NRMJq6vHe5VLOM8= Xref: csiph.com comp.lang.c:136122 jacobnavia writes: > Le 03/10/2018 à 01:39, Keith Thompson a écrit : >> I can't do that with your program. > > Yes you can: > > find . -name "*.[ch]" | lc - > > That will print correctly formaytted information You snipped too much context. What I said I can't do with your program is: find . -type f -print0 | wc --files0-from=- What I meant is that your program can't take a list of files delimited by null characters, which means (I think, I haven't closely studied your code) it can't process those very rare files that have newlines in their names. It's a rare requirement, but it's one that the existing tools support out of the box. If you know about "find -print0" and "wc --files0-from=" (which you do now) you can handle *all* files regardless of what some silly person has decided to name them. And it doesn't require writing any new code; the tools already exist. Incidentally, I don't *think* that trying to run your program on files with newlines in their names will cause it to do anything nasty. At worst, it could be made to process some files twice ($'foo\nbar' will cause it to try to open 'foo' and 'bar'). But I could probably write a fairly simple shell command that would execute some arbitrary code given maliciously constructed file names. Your program arguably solves *most* of the problem, but existing tools already solve all of it. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"