reading directory under SYSTEM V

Daniel R. Levy levy at ttrdc.UUCP
Sun Sep 7 13:51:05 AEST 1986


In article <5770001 at acf2.UUCP>, banner at 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



More information about the Comp.lang.c mailing list