c - linux symlink()函数在绝对路径上损坏

标签 c linux

为什么会这样:

#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>

int main(void) {
        const char filea[] = "../test/hunspell";
        const char fileb[] = "testa/dictionaries";
        int returnr;
        returnr = symlink(filea, fileb);
        printf("%d\n", returnr);
        return returnr;
}

返回 0,我得到这个:

[gala@arch test]$ tree
.
├── symtest
├── test
├── testa
│   └── dictionaries -> ../test/hunspell
└── test.c

[gala@arch test]$ pwd
/home/gala/testing/test

但是这个:

#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>

int main(void) {
        const char filea[] = "/home/gala/testing/test/hunspell";
        const char fileb[] = "/home/gala/testing/testa/dictionaries";
        int returnr;
        returnr = symlink(filea, fileb);
        printf("%d\n", returnr);
        return returnr;
}

返回 -1 并失败。

为什么 c symlink() 函数在绝对路径上失败但在相对路径上有效?有什么我想念的吗?

为什么坏了?

最佳答案

你确定你的路径是好的吗?如果你在 /home/gala/testing/test 中运行了 tree,那么 fileb 的路径应该是 /home/gala/testing/test/testa/dictionaries 而不是 /home/gala/testing/testa/dictionaries

关于c - linux symlink()函数在绝对路径上损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36988380/

相关文章:

c++ - GetWindowText 和 GetWindowTextLength 在没有括号的情况下运行?

python - 如何使用 BASH 或 Python 脚本将两个文件合并为一个文件?

c - Bitshift 和 equals 在一起

c - 使用gdb调试时未找到调试符号

linux - $ 在 Linux 中是什么意思?

java - NetBeans 找不到 JTextField.append()

linux - 如何判断两个 NFS 挂载是否在同一个远程文件系统上?

linux - 如何管理 docker 备份

c - 当我多次运行程序时如何使用或释放​​动态分配的内存?

c - 为什么我的代码不能停止?使用 fscanf