"... If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned."
various C library implementations may or may not support using getcwd() this way, with a NULL buffer pointer that tells getcwd() to malloc(3) the returned buffer, which the caller should free(3).
Note: The dir may only be used in a do-block. Specifically, this syntax (<-) is do-block exclusive. To use elsewhere, use getCurrentDirectory (with caution!)
Only works in NodeJS because JavaScript in the browser does not know about your directories.
dir = os.getenv("PWD") orio.popen("cd"):read()
Tries to get a system environment variable PWD. If it is a linux system, it will contain working directory. Will ignore io.popen() then due to short-circuit evaluation. If enviroment variable PWD doesn't exists, it executes cmd command "cd" and reads the result, which will work on windows systems.
interface
function c_getcwd (buf, size) bind(C,name="getcwd") result(r)
import
type(c_ptr) :: r
character(kind=c_char), dimension(*), intent(out) :: buf
integer(kind=c_size_t), value :: size
end function c_getcwd
end interface
if (c_associated(c_getcwd (buf, size(buf,kind=c_size_t)))) then
n = findloc(buf,achar(0),1)
allocate (character(len=n-1) :: dir)
dir(1:n-1) = transfer(buf(1:n-1),dir(1:n-1))
end if