0

I am writing a small console-like program in C, along with implementations for ls, tac and dir.

I use execvp() function to override the forked children of the process, but when the user inserts one of the above 3 commands, I have to execute my own version, not the one from the system.

I know that execvp() uses the system PATH variable to search in different locations for the executable file. Can I somehow edit the PATH in my program, so I could add a custom directory as the first place for execvp() search?

Thank you!

Cristian Holdunu
  • 1,880
  • 1
  • 18
  • 43

1 Answers1

0

You can change PATH with setenv -- but mind you, it might be simpler to just check for those commands explicitly before doing the exec.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836