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 13:26:01 -0700 Organization: None to speak of Lines: 44 Message-ID: References: <7q1tD.728075$PJ7.722912@fx01.am4> <709acf50-9c29-8cdc-8117-10ac31d8ec25@jacob.remcomp.fr> 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="8015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ozt5/cxu7Bla7R7G/yowd" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:RJCFCMbXsVT7rpLF2QQxsbdYnmU= sha1:9Zb1OyXbHZsryFwsccyf5zyxALs= Xref: csiph.com comp.lang.c:136133 jacobnavia writes: > Le 03/10/2018 à 21:03, Keith Thompson a écrit : >> Is writing a C program to do something that the existing OS utilities >> can already do not over-engineering? > > No. > > GNU is not unix. Your original statement in the article that started this thread was: Unix has the "wc" utility to count the lines of a file. It is a pity that under linux that program is unusable to count lines in ----- a hierarchy of several directories. It requires ZERO terminated file names, and the "find" utility produces \n terminated file names, so it is unusable for that. By "linux", I assumed you meant something like, say, Ubuntu or Fedora, which uses a Linux kernel and GNU user space programs (like coreutils and findutils). If you have a UNIX-like system, perhaps with a Linux kernel, that *doesn't* have GNU coreutils and findutils, then the problem you describe could be real, and your program could be useful. (But building GNU utilities for the system could also be a solution.) I'll note that the busybox version of "wc" (commonly used on small Linux-based systems) doesn't have the "--files0-from=F" option, but busybox find does have "-print0" and busybox xargs has "-0". find . -type f -print0 | xargs -0 wc does things that your program can't. If you don't care about those things, that's fine. I'm merely pointing out that there are existing (and IMHO more flexible and robust) solutions to the problem your program tries to solve. -- 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"