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:
Diffstat (limited to 'libgloss/riscv/semihost-sys_stat.c')
-rw-r--r--libgloss/riscv/semihost-sys_stat.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libgloss/riscv/semihost-sys_stat.c b/libgloss/riscv/semihost-sys_stat.c
new file mode 100644
index 000000000..4015801b9
--- /dev/null
+++ b/libgloss/riscv/semihost-sys_stat.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 Embecosm Limited
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include <machine/syscall.h>
+#include <string.h>
+#include <fcntl.h>
+#include "semihost_stat.h"
+
+/* Status of a file (by name). */
+
+int
+_stat (const char *name, struct stat *st)
+{
+ int file;
+ int res;
+
+ /* Initialize st as not all fields will be set. */
+ memset (st, 0, sizeof (*st));
+
+ /* Try to open file. */
+ file = _open (name, O_RDONLY);
+ if (file == -1)
+ /* _open should have already set errno. */
+ return -1;
+
+ /* File opened successfully, infer read permission for owner and assume it is
+ a regular file. */
+ st->st_mode |= S_IREAD | S_IFREG;
+
+ /* Fill in more info. */
+ res = __stat_common (file, st);
+
+ _close (file);
+ return res;
+}