libc: silence close() failure messages

Return EBADF but do not log an error for invalid descriptors.

Ref #2467
This commit is contained in:
Emery Hemingway 2017-07-26 11:52:46 -05:00 committed by Christian Helmuth
parent 2c4f0e5505
commit c2c47d2e35

View File

@ -36,6 +36,7 @@
#include "libc_file.h"
#include "libc_mem_alloc.h"
#include "libc_mmap_registry.h"
#include "libc_errno.h"
using namespace Libc;
@ -218,9 +219,16 @@ extern "C" int chdir(const char *path)
}
/**
* Close is called incorrectly enough to justify a silent failure
*/
extern "C" int _close(int libc_fd)
{
FD_FUNC_WRAPPER(close, libc_fd);
Libc::File_descriptor *fd =
Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd);
return (!fd || !fd->plugin)
? Libc::Errno(EBADF)
: fd->plugin->close(fd);
}