From owner-freebsd-current@FreeBSD.ORG Tue Jun 9 09:19:04 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D15811065676 for ; Tue, 9 Jun 2009 09:19:04 +0000 (UTC) (envelope-from serenity@exscape.org) Received: from ch-smtp01.sth.basefarm.net (ch-smtp01.sth.basefarm.net [80.76.149.212]) by mx1.freebsd.org (Postfix) with ESMTP id 8BFDC8FC1A for ; Tue, 9 Jun 2009 09:19:04 +0000 (UTC) (envelope-from serenity@exscape.org) Received: from c83-253-252-234.bredband.comhem.se ([83.253.252.234]:35813 helo=mx.exscape.org) by ch-smtp01.sth.basefarm.net with esmtp (Exim 4.69) (envelope-from ) id 1MDxT8-0007RB-3t; Tue, 09 Jun 2009 11:18:12 +0200 Received: from [192.168.1.5] (macbookpro [192.168.1.5]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mx.exscape.org (Postfix) with ESMTPSA id D330241225; Tue, 9 Jun 2009 11:18:08 +0200 (CEST) Message-Id: <60F36765-E4FA-4A2D-AD6B-E7881537F6DA@exscape.org> From: Thomas Backman To: Ivan Voras In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v935.3) Date: Tue, 9 Jun 2009 11:18:07 +0200 References: X-Mailer: Apple Mail (2.935.3) X-Originating-IP: 83.253.252.234 X-Scan-Result: No virus found in message 1MDxT8-0007RB-3t. X-Scan-Signature: ch-smtp01.sth.basefarm.net 1MDxT8-0007RB-3t 28a54c667898d62bd052404f53cd4720 Cc: freebsd-current@freebsd.org Subject: Re: FS utils treates directories as files? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jun 2009 09:19:05 -0000 On Jun 9, 2009, at 11:03 AM, Ivan Voras wrote: > Thomas Backman wrote: >> FreeBSD 8.0-CURRENT r193521 (Jun 5), bash: >> [root@chaos /usr/ports]# file / >> /: directory >> [root@chaos /usr/ports]# cat / >> =EF=BF=BDg=EF=BF=BD=EF=BF=BD=3D[root@chaos /usr/ports]# >> [root@chaos /usr/ports]# cat /usr/ports/mail >> =EF=BF=BD > > This is the traditional behaviour because yes, directories are just > simply ordinary files with a special bit set to distinguish them. =20 > Other > systems might have modified "cat" to check if directories are files =20= > but > it's not standard. > > You can easily check this yourself. The following small program should > work on every unix-ish system: > > #include > #include > #include > > int main() { > int fd, i; > char buf[512]; > =09 > fd =3D open(".", O_RDONLY); > read(fd, buf, 512); > for (i =3D 0; i < 512; i++) > printf("%4d ", buf[i]); > } Yes, I realize that, and actually added a stat() call to cat to check =20= for directories... before I realized it was true for other utils as =20 well. I still think it's weird, though, and that the utils should check (as =20= long as they return gibberish; less /etc on my GNU/Linux system =20 actually shows a readable list of files - it seems as if less /etc =3D=3D = =20 ls -al /etc | less). Is there *any* use for this behaviour, or is it =20 simply there because nobody has added a check? Regards, Thomas=