Skip to content

Readlink incorrectly returns fully qualified path #22999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hoodmane opened this issue Nov 25, 2024 · 1 comment · Fixed by #23000
Closed

Readlink incorrectly returns fully qualified path #22999

hoodmane opened this issue Nov 25, 2024 · 1 comment · Fixed by #23000

Comments

@hoodmane
Copy link
Collaborator

hoodmane commented Nov 25, 2024

Considering the following:

#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <unistd.h>

static void create_file(const char *path, const char *buffer, int mode) {
  int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
  assert(fd >= 0);

  int err = write(fd, buffer, sizeof(char) * strlen(buffer));
  assert(err ==  (sizeof(char) * strlen(buffer)));

  close(fd);
}

int main() {
    char buf[20];

    create_file("symlink_target", "xyz", 0777);
    symlink("symlink_target", "symlink_src");
    readlink("symlink_src", buf, 20);
    printf("buf: '%s'\n", buf);
    unlink("symlink_src");
    unlink("symlink_target");
}

Running with gcc we just the contents of the link vs running with emcc we get a fully qualified path:

$ gcc a.c
$ ./a.out
buf: 'symlink_target'
$ emcc a.c
$ node a.out.js
buf: '/symlink_target'

Note the initial / in the emcc run.

@hoodmane
Copy link
Collaborator Author

Actually the one call site of readlink in the Emscripten source code doesn't seem to expect this behavior since it immediately calls resolve:
https://github.com/emscripten-core/emscripten/blob/main/src/library_fs.js?plain=1#L217-L218

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant