I have no idea how to make the code for this command.
I had something but is not working. I think is a problem at the exec.
Can someone make it work?
i'm a newbie in this field.
#include<sys/stat.h>
#include<libgen.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<dirent.h>
#include<stdio.h>
void showArgs(int argc, char *argv[]){
int i;
for (i=0;i<argc;i++) {
printf("Argument is %s ",argv[i]);
}
}
int main(int argc, char*argv[])
{
int isdir(const char *path) {
struct stat statbuf;
if (stat(path, &statbuf) != 0)
return 0;
return S_ISDIR(statbuf.st_mode);
}
printf("Program started... \n");
showArgs(argc, argv);
if(argc == 2)
{
if(isdir(argv[1]))
{
printf("Calling dir with parameter\n");
execl("dirname",argv[1],NULL);
}else{
printf("invalid dir name\n");
}
}
return 0;
}
dirname
program counts as implementing it?execl("dirname",argv[1],NULL);
printf
statements.isdir()
is defined and called in samemain()
function, it will not create any problem for you?dirname
hardly counts as a way of implementingdirname
, at least not in my book.