我使用 dll 从C程序运行一些fortran源代码。我想在Fortran中使用 CALL GETCWD(DIRNAME)来访问文件。当前工作目录(CWD)是我的fortran dll所在的目录还是我的C代码所在的目录?
答案 0 :(得分:1)
CWD 表示 C urrent W orking D irectory ,并且(通常)是启动当前进程的目录。检查[man7]: GETCWD(3)了解更多详情。我准备了一个小例子,以更好地了解发生了什么。
code.c :
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#define PATH_SIZE 0x0200
int main() {
char buf[PATH_SIZE];
if (getcwd(buf, PATH_SIZE) == NULL) {
printf("Error %d getting CWD\n", errno);
return 1;
}
printf("CWD: [%s]\n", buf);
return 0;
}
输出:
[cfati@cfati-ubtu16x64-0:~/Work/Dev/StackOverflow/q054306561]> ls code.c [cfati@cfati-ubtu16x64-0:~/Work/Dev/StackOverflow/q054306561]> gcc -o cwd code.c [cfati@cfati-ubtu16x64-0:~/Work/Dev/StackOverflow/q054306561]> ls code.c cwd [cfati@cfati-ubtu16x64-0:~/Work/Dev/StackOverflow/q054306561]> ./cwd CWD: [/home/cfati/Work/Dev/StackOverflow/q054306561] [cfati@cfati-ubtu16x64-0:~/Work/Dev/StackOverflow/q054306561]> pushd .. && ./q054306561/cwd && popd ~/Work/Dev/StackOverflow ~/Work/Dev/StackOverflow/q054306561 CWD: [/home/cfati/Work/Dev/StackOverflow] ~/Work/Dev/StackOverflow/q054306561 [cfati@cfati-ubtu16x64-0:~/Work/Dev/StackOverflow/q054306561]> mkdir test && pushd test && ../cwd && popd ~/Work/Dev/StackOverflow/q054306561/test ~/Work/Dev/StackOverflow/q054306561 CWD: [/home/cfati/Work/Dev/StackOverflow/q054306561/test] ~/Work/Dev/StackOverflow/q054306561