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

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

/* Close a file.  */
int
_close (int file)
{
  long res;
  struct fdentry *fd =__get_fdentry (file);
  long data_block[1];

  if (fd == NULL)
    return -1;

  data_block[0] = fd->handle;
  res = syscall_errno (SEMIHOST_close, data_block);

  if (res != 0)
    return res;

  __remove_fdentry (file);
  return 0;
}