LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2003, 08:09 AM   #1
skywalker27182
Member
 
Registered: Nov 2003
Posts: 35

Rep: Reputation: 15
Question Opening a directory WITHOUT using 'opendir' and 'readdir'


Hi,
i am trying to write a program in 'C' (on RedHat 9) that lists all the files in a directory using only 'open' and 'read' and its details like space, inode no, etc. i remember reading in a book that UNIX treats all directories as normal files. so it is possible, right? but i couldn't do it. i saw in Ritchie's book on 'C' that 'readdir' and 'opendir' does use 'read' and 'open'. but it also uses 'malloc'. someone please tell me why and how to go about the program
 
Old 11-15-2003, 02:10 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
The striucture of the actual directory entry is dependant of the underlying filesystem. You do want to use readdir(3) or if you want a closer (linux spesific) interface, you can use open(2) and getdents(2) to read the contents of the directory. The read(2) gives you a 'EISDIR fd refers to a directory.' error if you try to access the directory directly.
 
Old 11-16-2003, 01:32 PM   #3
coldfusion
LQ Newbie
 
Registered: Nov 2003
Distribution: Slackware 9 / kernel 2.6-test9
Posts: 8

Rep: Reputation: 0
you could use exec

you could do something like this:


execl("/bin/ls","/bin/ls","/",NULL);


though, if i recall correctly, exec will take over your program with "ls"


:edited: mistyped the execl

Last edited by coldfusion; 11-16-2003 at 04:42 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ opendir() handling error bendeco13 Programming 1 11-06-2005 02:37 AM
opendir() SIGSEGV on RedHat 9 rylan76 Programming 2 05-26-2004 10:47 AM
Konqueror freezes when opening /mnt directory yokel Linux - General 4 10-14-2003 09:29 PM
perl opendir like function for php? paulish Programming 2 09-21-2003 03:45 AM
permission denied when opening directory pilot1 Linux - General 1 10-23-2002 08:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration