Friday 8 May 2015

Opendir() and readdir() UNIX System Call

#include  <stdio.h>
#include  <stdlib.h>
#include  <sys/types.h>
#include  <unistd.h>
#include <dirent.h>

int main(int argc,char *argv[])
{
DIR* proc_listing;
char *name;
struct dirent* proc_entry;
proc_listing = opendir (argv[1]);

while((proc_entry = readdir (proc_listing))!=NULL)
{
name=proc_entry->d_name;

printf("\n%s",name);
}

return 0;
}















Output:

    [telnet29@linux ~]$ ./a.out  /
    [telnet50@linux ~]$ ./a.out  /
misc
boot
opt
mnt
..
srv
net
lost+found
lib
.
etc
sbin
proc
tmp
media
sys
selinux
.autofsck
var
root
dev
bin

usr

No comments:

Post a Comment