newlib-cygwin/libgloss/riscv/semihost-sys_close.c

29 lines
492 B
C
Raw Normal View History

2020-12-15 20:00:27 +08:00
/*
* 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;
}