Use portable commands instead of libgen.h commands for path handling

Signed-off-by: Saggi Mizrahi <ficoos@gmail.com>