You can simply use SystemVerilog DPI to get the environment. And since it getenvis the standard C library for each POSIX platform, you do not need to use your equivalent function again getenv()to define the function.
Sample code in SV.
import "DPI-C" function string getenv(input string env_name);
module top;
initial begin
$write("env = %s\n", {getenv("HOME"), "/FileName"});
end
endmodule
Launch
ncverilog -sv dpi.v
or
vcs -sverilog dpi.v
He will show
env = /home/user/FileName
, PATH - ":". , , "PATH". fopen "/bin:/usr/bin:/usr/local/bin/FileName", .