2 * Copyright 2002-2013, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
10 #include <errno_private.h>
12 #include <syscall_utils.h>
16 readlink(const char *path
, char *buffer
, size_t bufferSize
)
18 return readlinkat(AT_FDCWD
, path
, buffer
, bufferSize
);
23 readlinkat(int fd
, const char *path
, char *buffer
, size_t bufferSize
)
25 size_t linkLen
= bufferSize
;
26 status_t status
= _kern_read_link(fd
, path
, buffer
, &linkLen
);
32 // If the buffer is big enough, null-terminate the string. That's not
33 // required by the standard, but helps non-conforming apps.
34 if (linkLen
< bufferSize
)
35 buffer
[linkLen
] = '\0';
42 symlink(const char *toPath
, const char *symlinkPath
)
44 int status
= _kern_create_symlink(-1, symlinkPath
, toPath
, 0);
46 RETURN_AND_SET_ERRNO(status
);
51 symlinkat(const char *toPath
, int fd
, const char *symlinkPath
)
53 RETURN_AND_SET_ERRNO(_kern_create_symlink(fd
, symlinkPath
, toPath
, 0));
58 unlink(const char *path
)
60 int status
= _kern_unlink(-1, path
);
62 RETURN_AND_SET_ERRNO(status
);
67 unlinkat(int fd
, const char *path
, int flag
)
69 if ((flag
& AT_REMOVEDIR
) != 0)
70 RETURN_AND_SET_ERRNO(_kern_remove_dir(fd
, path
));
72 RETURN_AND_SET_ERRNO(_kern_unlink(fd
, path
));
77 link(const char *toPath
, const char *linkPath
)
79 int status
= _kern_create_link(-1, linkPath
, -1, toPath
, true);
80 // Haiku -> POSIX error mapping
81 if (status
== B_UNSUPPORTED
)
84 RETURN_AND_SET_ERRNO(status
);
89 linkat(int toFD
, const char *toPath
, int linkFD
, const char *linkPath
, int flag
)
91 RETURN_AND_SET_ERRNO(_kern_create_link(linkFD
, linkPath
, toFD
, toPath
,
92 (flag
& AT_SYMLINK_FOLLOW
) != 0));