summaryrefslogtreecommitdiff
path: root/tools/include/nolibc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/include/nolibc')
-rw-r--r--tools/include/nolibc/arch-sparc.h2
-rw-r--r--tools/include/nolibc/unistd.h58
2 files changed, 59 insertions, 1 deletions
diff --git a/tools/include/nolibc/arch-sparc.h b/tools/include/nolibc/arch-sparc.h
index ddae9bc10dfe..23fab40accfa 100644
--- a/tools/include/nolibc/arch-sparc.h
+++ b/tools/include/nolibc/arch-sparc.h
@@ -45,7 +45,7 @@
\
__asm__ volatile ( \
_NOLIBC_SYSCALL \
- : "+r"(_arg1) \
+ : "=r"(_arg1) \
: "r"(_num) \
: "memory", "cc" \
); \
diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h
index 79599ceef45d..a264a20da13d 100644
--- a/tools/include/nolibc/unistd.h
+++ b/tools/include/nolibc/unistd.h
@@ -73,6 +73,48 @@ int ftruncate(int fd, off_t length)
return __sysret(_sys_ftruncate(fd, length));
}
+/*
+ * char *getcwd(char *buf, size_t size);
+ */
+
+static __attribute__((unused))
+int _sys_getcwd(char *buf, size_t size)
+{
+ return __nolibc_syscall2(__NR_getcwd, buf, size);
+}
+
+static __attribute__((unused))
+char *getcwd(char *buf, size_t size)
+{
+ int ret;
+
+ /* Unlike other libc's we don't handle passing NULL for buf */
+ if (!buf || !size) {
+ SET_ERRNO(EINVAL);
+ return NULL;
+ }
+
+ ret = __sysret(_sys_getcwd(buf, size));
+
+ /* On error return NULL, __sysret() above will have set errno */
+ if (ret < 0)
+ return NULL;
+
+ /* Handle no path being written or the kernel putting
+ * "(unreachable)" into the buffer instead of a path.
+ * This matches what musl is doing.
+ */
+ if (ret == 0 || buf[0] != '/') {
+ SET_ERRNO(ENOENT);
+ return NULL;
+ }
+
+ /* ret must be the number of bytes written at this point,
+ * so return the pointer to buf.
+ */
+ return buf;
+}
+
static __attribute__((unused))
int msleep(unsigned int msecs)
{
@@ -86,6 +128,22 @@ int msleep(unsigned int msecs)
return 0;
}
+/*
+ * ssize_t readlink(const char *path, char *buf, size_t bufsiz);
+ */
+
+static __attribute__((unused))
+ssize_t _sys_readlink(const char *path, char *buf, size_t bufsiz)
+{
+ return __nolibc_syscall4(__NR_readlinkat, AT_FDCWD, path, buf, bufsiz);
+}
+
+static __attribute__((unused))
+ssize_t readlink(const char *path, char *buf, size_t bufsiz)
+{
+ return __sysret(_sys_readlink(path, buf, bufsiz));
+}
+
static __attribute__((unused))
unsigned int sleep(unsigned int seconds)
{