Saturday, 17 September 2011

Implementation of mkdir command

 




#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
void usage(const char *myname)
{
printf(“\nUsage: %s <pathname> [<mode>]\n\n”, myname);
exit(1);
}
void main(int argc, char *argv[])
{
int mode;
if(argc<2)
usage(argv[0]);
if(argc==2)
mode = 0777;
elseif(sscanf(argv[2], “%o”, &mode==0)
{
printf(“%s : Invalid Mode\n”, argv[0]);
exit(1);
}
if(mkdir(argv[1], mode)== -1)
perror(argv[0]);
else
printf(“%s directory is created successfully”, argv[1]);
}

0 comments:

Post a Comment