Ognjen Galić
Ognjen Galić

Reputation: 2742

linux symlink() function broken on absolute paths

Why does this:

#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;
}

Return 0 and i get this:

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

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

But this:

#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;
}

Returns -1 and fails.

Why does the c symlink() function fail on absolute paths but works on relative paths? Is there something I'm missing?

Why is it broken?

Upvotes: 0

Views: 80

Answers (1)

blatinox
blatinox

Reputation: 843

Are you sure that your paths are good ? If you ran tree in /home/gala/testing/test, then the path for fileb should be /home/gala/testing/test/testa/dictionaries instead of /home/gala/testing/testa/dictionaries.

Upvotes: 2

Related Questions