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

semihost-sys_stat.c « riscv « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4015801b90709f466523c46aaef8d4980ab6d3d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
}