🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9269

Re: reading directory under SYSTEM V

#9269
From: Daniel R. Levy
Date: Sun, 07 Sep 1986 03:51
35 lines
2498 bytes
In article <5770001@acf2.UUCP>, banner@acf2.UUCP (Bernard Banner) writes:
>
>Cound anybody suggest a method of reading directory information from a C
>program under SYSTEM V UNIX? I need something equivalent to the opendir and 
>readdir functionality supplied under BSD.

Since SysV directories have a fixed structure, it is absurdly simple to
write your own directory parsers:

$ od -c /usr/bin
0000000  \0   k   .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020  \0 002   .   .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000040  \0   l   n   e   w   s  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000060  \0   m   b   c  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000100  \0   n   m   4  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000120  \0   o   p   r   o   f  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000140  \0   p   p   c   a   t  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000160  \0   q   c   b  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000200  \0   r   l   i   n   t  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
        ^^^^^^^   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        INODE     FILENAME (14 bytes, NUL-filled [be careful, since 14-byte
        (Zero               names will NOT be NUL-terminated!  {f}read() the
        if entry            filename field into a longer buffer with a NUL
        is unlinked)        in the 15th byte to avoid this problem])
...

Look in /usr/include/sys/dir.h for declarations that you can use.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy
Technical Details
Message-ID: <1185@ttrdc.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!ihnp4!cuae2!ltuxa!ttrdc!levy
References: <5770001@acf2.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!ihnp4!cuae2!ltuxa!ttrdc!levy
From: levy@ttrdc.UUCP (Daniel R. Levy)
Newsgroups: net.lang.c
Subject: Re: reading directory under SYSTEM V
Message-ID: <1185@ttrdc.UUCP>
Date: Sat, 6-Sep-86 23:51:05 EDT
Article-I.D.: ttrdc.1185
Posted: Sat Sep  6 23:51:05 1986
Date-Received: Sun, 7-Sep-86 20:19:38 EDT
References: <5770001@acf2.UUCP>
Organization: AT&T, Computer Systems Division, Skokie, IL
Lines: 35