LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-31-2006, 01:39 AM   #1
smoothny
LQ Newbie
 
Registered: Mar 2006
Location: Gdynia, Poland
Distribution: Gentoo
Posts: 3

Rep: Reputation: 0
Question Directory listing using kernel calls


I'm new to Linux programming. I wanted to design some kind of plugin loading stuff. What stops me is I do not know and can't figure out how to get the listing of the directory in my program. I look at system calls and I've already found out that I can read directories as if they were regular files. Maybe that's now the way. Modestly but impatiently waiting for response.

Smoothny.
 
Old 03-31-2006, 02:04 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I guess you need to clarify what you want to achieve.

Please elaborate on "kind of plugin loading stuff" and "the listing of the directory".
 
Old 03-31-2006, 02:25 AM   #3
smoothny
LQ Newbie
 
Registered: Mar 2006
Location: Gdynia, Poland
Distribution: Gentoo
Posts: 3

Original Poster
Rep: Reputation: 0
Question

What I want is just get the array of filenames under certain directory in my C program. Eg I look in "/var/www/localhost/cgi-bin/plugin" and i get the array of filenames "unicode.so", "us-ascii.so" etc. I'm done with plugin loading support.

I dont know what kernel calls I should use to get contents of directory.
 
Old 03-31-2006, 03:37 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Do you really need low level programming to do that (i.e. kernel/system calls), or a library call is really what you are after ?

In the latter case, opendir/readdir can be used to build the array you want.
 
Old 03-31-2006, 04:07 AM   #5
smoothny
LQ Newbie
 
Registered: Mar 2006
Location: Gdynia, Poland
Distribution: Gentoo
Posts: 3

Original Poster
Rep: Reputation: 0
Lightbulb

I think I will use library functions you advised. I fall into common mistake trying to do lowlevel stuff losing portablility. Thanks for help.
 
Old 03-31-2006, 03:18 PM   #6
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
You may use scandir() for this. It's implemented over readdir(). For maximum robustness, and if you don't care about entries being sorted, use opendir()/readdir()/closedir() on each file in a serial way, as it doesn't allocate a large buffer to hold all filenames.
 
  


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
Listing Directory Size andy7t Linux - Software 2 12-14-2008 02:46 PM
Apache Directory Listing Of NFS Mount, cannot view directory list via apache luqmana Linux - Networking 2 12-19-2005 06:03 AM
directory listing script linuxzouk Programming 2 06-04-2004 12:07 PM
print listing of directory harnadem Linux - Newbie 2 04-25-2004 09:35 PM
Directory Listing mattbeekler Linux - Software 8 07-22-2003 02:27 PM

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

All times are GMT -5. The time now is 12:55 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