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

semihost-sys_read.c « riscv « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3164eed56afb9864802cb6149f5c39af6e00d94d (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
/*
 * Copyright (C) 2020 Embecosm Limited
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include <machine/syscall.h>
#include <errno.h>
#include <sys/types.h>
#include "semihost_syscall.h"
#include "semihost_fdtable.h"

/* Read from a file.  */
ssize_t _read (int file, void *ptr, size_t len)
{
  struct fdentry *fd =__get_fdentry (file);
  long data_block[3];
  long res;

  if (fd == NULL)
    return -1;

  data_block[0] = fd->handle;
  data_block[1] = (long) ptr;
  data_block[2] = len;
  res = syscall_errno (SEMIHOST_read, data_block);
  if (res >= 0)
    {
      ssize_t bytes_read = len - res;
      fd->pos += bytes_read;
      return bytes_read;
    }
  return -1;
}