Question

I am trying to tell if the argument they give me is a Shared Library or a command I order to load the library or the exec with that especific command.

Right now what I am trying to do is:

if(strstr(argv[1],".so")!=NULL){
  //Load library etc...
}
else
  exec(argv[1],&argv[1],NULL);
  perror("exec");
  exit(1);

But it seems something its wrong because if the argument is "./lib.so" it tries exec(./lib.so).

Thank you in advance.

Était-ce utile?

La solution

Your else branch contains only exec command. perror and exit are non-conditional and will be executed in any case. Aside from that, string check is working as it should (unless you have custom (and incorrect) strstr implementation).

Correct version is

else {
  exec(argv[1],&argv[1],NULL);
  perror("exec");
  exit(1);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top