>>but that is not guaranteed
Yes I know, which is why I made the qualified statement. Only some compilers do that.
getcwd() only gets the current working directory, which is also available in MS-Windows. If the program changes directories before calling getcwd() itt will not give you what you are looking for, assuming you want the path to the *.exe file.
I don't know if there is a POSIX equivalent to GetModueFileName(), but getcwd() is not it.