Ejemplo n.º 1
0
/**
 * Determine OS has a feature enabled.
 *
 * @param[in] portLibrary instance of port library
 * @param[in] desc The struct that will contain the OS features
 * @param[in] feature The feature to check (see omrport.h for list of OS features)
 *
 * @return TRUE if feature is present, FALSE otherwise.
 */
BOOLEAN
omrsysinfo_os_has_feature(struct OMRPortLibrary *portLibrary, struct OMROSDesc *desc, uint32_t feature)
{
	BOOLEAN rc = FALSE;
	Trc_PRT_sysinfo_os_has_feature_Entered(desc, feature);

	if ((NULL != desc) && (feature < (OMRPORT_SYSINFO_OS_FEATURES_SIZE * 32))) {
		uint32_t featureIndex = feature / 32;
		uint32_t featureShift = feature % 32;

		rc = OMR_ARE_ALL_BITS_SET(desc->features[featureIndex], 1 << featureShift);
	}

	Trc_PRT_sysinfo_os_has_feature_Exit((uintptr_t)rc);
	return rc;
}
Ejemplo n.º 2
0
intptr_t
omrfile_open(struct OMRPortLibrary *portLibrary, const char *path, int32_t flags, int32_t mode)
{
	DWORD	accessMode, shareMode, createMode, flagsAndAttributes;
	HANDLE	aHandle;
	int32_t error = 0;
	wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;
	SECURITY_ATTRIBUTES sAttrib;

	Trc_PRT_file_open_Entry(path, flags, mode);

	/* Convert the filename from UTF8 to Unicode */
	unicodePath = file_get_unicode_path(portLibrary, path, unicodeBuffer, UNICODE_BUFFER_SIZE);
	if (NULL == unicodePath) {
		return -1;
	}

	accessMode = 0;
	if (flags & EsOpenRead) {
		accessMode |= GENERIC_READ;
	}
	if (flags & EsOpenWrite) {
		accessMode |= GENERIC_WRITE;
	}

	shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;

	/* this flag allows files to be deleted/renamed while they are still open, which more in line with unix semantics */
	if (OMR_ARE_ALL_BITS_SET(flags, EsOpenShareDelete)) {
		shareMode = shareMode | FILE_SHARE_DELETE;
	}

	if ((flags & EsOpenCreate) == EsOpenCreate) {
		createMode = OPEN_ALWAYS;
	} else if ((flags & EsOpenCreateNew) == EsOpenCreateNew) {
		createMode = CREATE_NEW;
	} else if ((flags & EsOpenCreateAlways) == EsOpenCreateAlways) {
		createMode = CREATE_ALWAYS;
	} else {
		createMode = OPEN_EXISTING;
	}

	flagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
	if (flags & EsOpenSync) {
		flagsAndAttributes |= FILE_FLAG_WRITE_THROUGH;
	}

	if (flags & EsOpenAsynchronous) {
		flagsAndAttributes |= FILE_FLAG_OVERLAPPED;
	}

	if (flags & EsOpenForInherit) {
		ZeroMemory(&sAttrib, sizeof(sAttrib));
		sAttrib.bInheritHandle = 1;
		sAttrib.nLength = sizeof(sAttrib);
		aHandle = CreateFileW(unicodePath, accessMode, shareMode, &sAttrib, createMode, flagsAndAttributes, NULL);
	} else {
		aHandle = CreateFileW(unicodePath, accessMode, shareMode, NULL, createMode, flagsAndAttributes, NULL);
	}

	if (INVALID_HANDLE_VALUE == aHandle) {
		error = GetLastError();
		portLibrary->error_set_last_error(portLibrary, error, findError(error));
		if (unicodeBuffer != unicodePath) {
			portLibrary->mem_free_memory(portLibrary, unicodePath);
		}
		Trc_PRT_file_open_Exception2(path, error, findError(error));
		Trc_PRT_file_open_Exit(-1);
		portLibrary->error_set_last_error(portLibrary, error, findError(error));
		return -1;
	}

	if ((FILE_TYPE_DISK == GetFileType(aHandle)) && ((flags & EsOpenTruncate) == EsOpenTruncate)) {
		if (0 == CloseHandle(aHandle)) {
			error = GetLastError();
			portLibrary->error_set_last_error(portLibrary, error, findError(error)); /* continue */
		}

		aHandle = CreateFileW(unicodePath, accessMode, shareMode, NULL, TRUNCATE_EXISTING, flagsAndAttributes, NULL);
		if (INVALID_HANDLE_VALUE == aHandle) {
			error = GetLastError();
			portLibrary->error_set_last_error(portLibrary, error, findError(error));
			if (unicodeBuffer != unicodePath) {
				portLibrary->mem_free_memory(portLibrary, unicodePath);
			}
			Trc_PRT_file_open_Exception3(path, error, findError(error));
			Trc_PRT_file_open_Exit(-1);
			portLibrary->error_set_last_error(portLibrary, error, findError(error));
			return -1;
		}
	}

	if (flags & EsOpenAppend) {
		portLibrary->file_seek(portLibrary, (intptr_t)aHandle, 0, EsSeekEnd);
	}

	if (unicodeBuffer != unicodePath) {
		portLibrary->mem_free_memory(portLibrary, unicodePath);
	}

	Trc_PRT_file_open_Exit(aHandle);
	return ((intptr_t)aHandle);
}