Exemple #1
0
/**
 * Closes a file descriptor.
 *
 * @param[in] portLibrary The port library
 * @param[in] fd The file descriptor.
 *
 * @return 0 on success, -1 on failure.
 * @internal @todo return negative portable return code on failure.
 */
int32_t
omrfile_close(struct OMRPortLibrary *portLibrary, intptr_t inFD)
{
	int32_t rc = 0;
	int fd = (int)inFD;

	Trc_PRT_file_close_Entry(fd);

#if (FD_BIAS != 0)
	if (fd < FD_BIAS) {
		/* Cannot close STD streams, and no other FD's should exist <FD_BIAS */
		Trc_PRT_file_close_ExitFail(-1);
		return -1;
	}
#endif

	rc = (int32_t)close(fd - FD_BIAS);

	Trc_PRT_file_close_Exit(rc);
	return rc;
}
Exemple #2
0
int32_t
omrfile_close(struct OMRPortLibrary *portLibrary, intptr_t fd)
{
	HANDLE handle = toHandle(portLibrary, fd);

	Trc_PRT_file_close_Entry(fd);

	if ((intptr_t) INVALID_HANDLE_VALUE == fd) {
		/* RTC 100203 Windows 10 does not report an error when closing an invalid handle */
		portLibrary->error_set_last_error(portLibrary, 0, OMRPORT_ERROR_FILE_INVALID_PARAMETER);
		Trc_PRT_file_close_invalidFileHandle();
		return -1;
	} else if (TRUE == CloseHandle(handle)) {
		Trc_PRT_file_close_Exit(0);
		return 0;
	} else {
		int32_t error = GetLastError();
		error = portLibrary->error_set_last_error(portLibrary, error, findError(error));
		Trc_PRT_file_close_ExitFail(error);
		return -1;
	}
}