Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Blackmore <craig.blackmore@embecosm.com>2020-12-15 15:00:27 +0300
committerJeff Johnston <jjohnstn@redhat.com>2020-12-17 00:40:34 +0300
commit865cd30dcc2f00c81c8b3624a9f3464138cd24a5 (patch)
tree0552b0b2fa338c8915b9023fb723aaf5337d1e4c /libgloss/riscv/semihost-sys_stat_common.c
parentd634f26653d4a673fed92d882107f165503e2e60 (diff)
RISC-V: Add semihosting support
Diffstat (limited to 'libgloss/riscv/semihost-sys_stat_common.c')
-rw-r--r--libgloss/riscv/semihost-sys_stat_common.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libgloss/riscv/semihost-sys_stat_common.c b/libgloss/riscv/semihost-sys_stat_common.c
new file mode 100644
index 000000000..b38eb0863
--- /dev/null
+++ b/libgloss/riscv/semihost-sys_stat_common.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 Embecosm Limited
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include <machine/syscall.h>
+#include "semihost_syscall.h"
+#include <sys/stat.h>
+#include "semihost_fdtable.h"
+
+/* Used by _fstat and _stat to fill in some common details. */
+
+int
+__stat_common (int file, struct stat *st)
+{
+ int flen;
+ struct fdentry *fd =__get_fdentry (file);
+ long data_block[1];
+
+ if (fd == NULL)
+ return -1;
+
+ data_block[0] = fd->handle;
+
+ /* Assume character device and default block size of 4096. */
+ st->st_mode |= S_IFCHR;
+ st->st_blksize = 4096;
+
+ /* Attempt to get length of file. */
+ flen = syscall_errno (SEMIHOST_flen, data_block);
+ if (flen == -1)
+ return -1;
+
+ st->st_size = flen;
+
+ return 0;
+}