Thursday 29 September 2011

IMPLMENTATION OF LINUX SYSTEM CALLS


IMPLMENTATION OF LINUX SYSTEM CALLS
[opendir (),readdir(),closedir()]
AIM:

To write a C program to access directories using LINUX system calls                           
opendir (),readdir(),closedir().

ALGORITHM:
  1. Start the process.
  2. Create a directory entry in the dirent structure and a directory variable
  3. Get the name of the directory to be opened
  4. Using the system call opendir(),open the given directory and store it in the directory variable.
  5. Read the contents of the directory using readdir()system call and print the list of files in the directory
  6. Close the directory after the read and write process
  7. Stop the process.

PROGRAM:
#include<Stdio.h>
#include<dirent.h>
Struct dirent *dptr;
int main(int argc,char *argv[])
{
char buff[256];
DIR *dirp;
printf(“\n \n enter directory name”);
scanf(“%s”,buff);
if ((disp=opendir(buff))==null);
{
printf(“error”);
exit(1);
} while (dptr=readir(disp))
{
printf(“%s\n”,dptr->d_name);
}
closedir(dirp);
}
OUTPUT:
Enter directory name   raju
Ashwini.c
maha.c

RESULT:
Thus the given C Program is executed and output is verified.

0 comments:

Post a Comment